ABAP Select data from SAP table FVD_BACP_I_LCIAR_CAL_RS into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP FVD_BACP_I_LCIAR_CAL_RS table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to FVD_BACP_I_LCIAR_CAL_RS. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the FVD_BACP_I_LCIAR_CAL_RS table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_FVD_BACP_I_LCIAR_CAL_RS TYPE STANDARD TABLE OF FVD_BACP_I_LCIAR_CAL_RS,
      WA_FVD_BACP_I_LCIAR_CAL_RS TYPE FVD_BACP_I_LCIAR_CAL_RS,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: <FVD_BACP_I_LCIAR_CAL_RS> TYPE FVD_BACP_I_LCIAR_CAL_RS.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_FVD_BACP_I_LCIAR_CAL_RS.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM FVD_BACP_I_LCIAR_CAL_RS
  INTO TABLE IT_FVD_BACP_I_LCIAR_CAL_RS.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FVD_BACP_I_LCIAR_CAL_RS
*  INTO TABLE @DATA(IT_FVD_BACP_I_LCIAR_CAL_RS2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_FVD_BACP_I_LCIAR_CAL_RS INDEX 1 INTO DATA(WA_FVD_BACP_I_LCIAR_CAL_RS2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FVD_BACP_I_LCIAR_CAL_RS ASSIGNING <FVD_BACP_I_LCIAR_CAL_RS>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FVD_BACP_I_LCIAR_CAL_RS>-RIOA = 1.
<FVD_BACP_I_LCIAR_CAL_RS>-MLOCKUSER = 1.
<FVD_BACP_I_LCIAR_CAL_RS>-MTEMPLNO_TXT = 1.
<FVD_BACP_I_LCIAR_CAL_RS>-TXTXBO_TEXT = 1.
<FVD_BACP_I_LCIAR_CAL_RS>-MCONF_STAT_LOAN = 1.
ENDLOOP.

LOOP AT IT_FVD_BACP_I_LCIAR_CAL_RS INTO WA_FVD_BACP_I_LCIAR_CAL_RS.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FVD_BACP_I_LCIAR_CAL_RS-MCONF_STAT_BO, sy-vline,
WA_FVD_BACP_I_LCIAR_CAL_RS-SCHEME_ID, sy-vline,
WA_FVD_BACP_I_LCIAR_CAL_RS-TEXT, sy-vline,
WA_FVD_BACP_I_LCIAR_CAL_RS-BNWHR, sy-vline,
WA_FVD_BACP_I_LCIAR_CAL_RS-BBETRAG, sy-vline,
WA_FVD_BACP_I_LCIAR_CAL_RS-SWHR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FVD_BACP_I_LCIAR_CAL_RS you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_FVD_BACP_I_LCIAR_CAL_RS TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_FVD_BACP_I_LCIAR_CAL_RS INTO WA_FVD_BACP_I_LCIAR_CAL_RS. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit ALPHA, internal->external for field RPARTNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FVD_BACP_I_LCIAR_CAL_RS-RPARTNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FVD_BACP_I_LCIAR_CAL_RS-RPARTNR.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_FVD_BACP_I_LCIAR_CAL_RS_STR,
RIOA TYPE STRING,
MLOCKUSER TYPE STRING,
MTEMPLNO_TXT TYPE STRING,
TXTXBO_TEXT TYPE STRING,
MCONF_STAT_LOAN TYPE STRING,
MCONF_STAT_BO TYPE STRING,
SCHEME_ID TYPE STRING,
TEXT TYPE STRING,
BNWHR TYPE STRING,
BBETRAG TYPE STRING,
SWHR TYPE STRING,
BBAGATELL TYPE STRING,
SWHR_BAG TYPE STRING,
SWHR_BAGGRENZE TYPE STRING,
SWHR_ERGEBNIS TYPE STRING,
VZ_DBERVON TYPE STRING,
DBERBIS TYPE STRING,
DBETRAG_VON TYPE STRING,
VZ_GEBUCHT TYPE STRING,
IINCL TYPE STRING,
SULT TYPE STRING,
DFAELL TYPE STRING,
DDISPO TYPE STRING,
VZ_BERECHNTAG TYPE STRING,
VZ_BERECHN_AB TYPE STRING,
SGTXT TYPE STRING,
RPARTNR TYPE STRING,
TPARTNR TYPE STRING,
BVTYP_IN TYPE STRING,
TBVTYP_IN TYPE STRING,
ZLSCH_IN TYPE STRING,
XZLSCH_IN TYPE STRING,
BVTYP_OUT TYPE STRING,
TBVTYP_OUT TYPE STRING,
ZLSCH_OUT TYPE STRING,
MNDID TYPE STRING,
REMIT_INFO TYPE STRING,
PREP_RECALC TYPE STRING,
RIOA_POSTED TYPE STRING,
RIOA_CALC_HISTORY TYPE STRING,
RIOA_CALC_CF TYPE STRING,
ZAHLS TYPE STRING,
TZAHLS TYPE STRING,
MABER TYPE STRING,
TMABER TYPE STRING,
MANSP TYPE STRING,
TMANSP TYPE STRING,
SBUST TYPE STRING,
MTEMPLNO TYPE STRING,
SBAGATELL TYPE STRING,
AUT_NK TYPE STRING,
MANUAL_START TYPE STRING,
VIOA_CALC TYPE STRING,END OF T_EKKO_STR. DATA: WA_FVD_BACP_I_LCIAR_CAL_RS_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-RIOA sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MLOCKUSER sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MTEMPLNO_TXT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TXTXBO_TEXT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MCONF_STAT_LOAN sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MCONF_STAT_BO sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SCHEME_ID sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TEXT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-BNWHR sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-BBETRAG sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SWHR sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-BBAGATELL sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SWHR_BAG sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SWHR_BAGGRENZE sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SWHR_ERGEBNIS sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-VZ_DBERVON sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-DBERBIS sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-DBETRAG_VON sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-VZ_GEBUCHT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-IINCL sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SULT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-DFAELL sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-DDISPO sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-VZ_BERECHNTAG sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-VZ_BERECHN_AB sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SGTXT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-RPARTNR sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TPARTNR sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-BVTYP_IN sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TBVTYP_IN sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-ZLSCH_IN sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-XZLSCH_IN sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-BVTYP_OUT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TBVTYP_OUT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-ZLSCH_OUT sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MNDID sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-REMIT_INFO sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-PREP_RECALC sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-RIOA_POSTED sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-RIOA_CALC_HISTORY sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-RIOA_CALC_CF sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-ZAHLS sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TZAHLS sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MABER sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TMABER sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MANSP sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-TMANSP sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SBUST sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MTEMPLNO sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-SBAGATELL sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-AUT_NK sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-MANUAL_START sy-vline
WA_FVD_BACP_I_LCIAR_CAL_RS_STR-VIOA_CALC sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.