ABAP Select data from SAP table VIXCAJRECCH01_TAB 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 VIXCAJRECCH01_TAB 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 VIXCAJRECCH01_TAB. 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 VIXCAJRECCH01_TAB 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_VIXCAJRECCH01_TAB TYPE STANDARD TABLE OF VIXCAJRECCH01_TAB, WA_VIXCAJRECCH01_TAB TYPE VIXCAJRECCH01_TAB, 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: <VIXCAJRECCH01_TAB> TYPE VIXCAJRECCH01_TAB. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_VIXCAJRECCH01_TAB. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM VIXCAJRECCH01_TAB INTO TABLE IT_VIXCAJRECCH01_TAB. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM VIXCAJRECCH01_TAB * INTO TABLE @DATA(IT_VIXCAJRECCH01_TAB2). *--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_VIXCAJRECCH01_TAB INDEX 1 INTO DATA(WA_VIXCAJRECCH01_TAB2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_VIXCAJRECCH01_TAB ASSIGNING <VIXCAJRECCH01_TAB>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<VIXCAJRECCH01_TAB>-PROCESSGUID = 1.
<VIXCAJRECCH01_TAB>-INTRENO = 1.
<VIXCAJRECCH01_TAB>-CONDCURR = 1.
<VIXCAJRECCH01_TAB>-MGRBASEREF = 1.
<VIXCAJRECCH01_TAB>-MGRBASEDATE = 1.
ENDLOOP. LOOP AT IT_VIXCAJRECCH01_TAB INTO WA_VIXCAJRECCH01_TAB. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_VIXCAJRECCH01_TAB-MGRBASERATE, sy-vline,
WA_VIXCAJRECCH01_TAB-MGRADJMDATE, sy-vline,
WA_VIXCAJRECCH01_TAB-MGRADJMRATE, sy-vline,
WA_VIXCAJRECCH01_TAB-MGRADJMPERCENT, sy-vline,
WA_VIXCAJRECCH01_TAB-MGRADJMAMOUNT, sy-vline,
WA_VIXCAJRECCH01_TAB-MOCPERCENTTYPE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_VIXCAJRECCH01_TAB 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_VIXCAJRECCH01_TAB 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_VIXCAJRECCH01_TAB INTO WA_VIXCAJRECCH01_TAB. *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 DEC03, internal->external for field MGRBASERATE CALL FUNCTION 'CONVERSION_EXIT_DEC03_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-MGRBASERATE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-MGRBASERATE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit DEC03, internal->external for field MGRADJMRATE CALL FUNCTION 'CONVERSION_EXIT_DEC03_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-MGRADJMRATE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-MGRADJMRATE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit DEC03, internal->external for field MOCBASEINDX CALL FUNCTION 'CONVERSION_EXIT_DEC03_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-MOCBASEINDX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-MOCBASEINDX.
WRITE:/ 'New Value:', ld_input.
*Conversion exit DEC03, internal->external for field MOCBASEPPCINDX CALL FUNCTION 'CONVERSION_EXIT_DEC03_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-MOCBASEPPCINDX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-MOCBASEPPCINDX.
WRITE:/ 'New Value:', ld_input.
*Conversion exit DEC03, internal->external for field MOCADJMPPCINDX CALL FUNCTION 'CONVERSION_EXIT_DEC03_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-MOCADJMPPCINDX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-MOCADJMPPCINDX.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field PPCBASEYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-PPCBASEYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-PPCBASEYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit DEC03, internal->external for field PPCBASEINDX CALL FUNCTION 'CONVERSION_EXIT_DEC03_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-PPCBASEINDX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-PPCBASEINDX.
WRITE:/ 'New Value:', ld_input.
*Conversion exit DEC03, internal->external for field PPCADJMINDX CALL FUNCTION 'CONVERSION_EXIT_DEC03_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-PPCADJMINDX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-PPCADJMINDX.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ACCOMCONDTYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-ACCOMCONDTYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-ACCOMCONDTYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field YIELDCONDTYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-YIELDCONDTYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-YIELDCONDTYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field WOIINCONDTYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VIXCAJRECCH01_TAB-WOIINCONDTYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VIXCAJRECCH01_TAB-WOIINCONDTYPE.
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_VIXCAJRECCH01_TAB_STR,
PROCESSGUID TYPE STRING,
INTRENO TYPE STRING,
CONDCURR TYPE STRING,
MGRBASEREF TYPE STRING,
MGRBASEDATE TYPE STRING,
MGRBASERATE TYPE STRING,
MGRADJMDATE TYPE STRING,
MGRADJMRATE TYPE STRING,
MGRADJMPERCENT TYPE STRING,
MGRADJMAMOUNT TYPE STRING,
MOCPERCENTTYPE TYPE STRING,
MOCBASEINDX TYPE STRING,
MOCBASEDATE TYPE STRING,
MOCBASEPPCINDX TYPE STRING,
MOCADJMDATE TYPE STRING,
MOCADJNBMONTH TYPE STRING,
MOCADJMPERCENT TYPE STRING,
MOCADJMPPCINDX TYPE STRING,
MOCADJMAMOUNT TYPE STRING,
PPCBASESERIES TYPE STRING,
PPCBASEYEAR TYPE STRING,
PPCBASEDATE TYPE STRING,
PPCBASEINDX TYPE STRING,
PPCPRCTPASS TYPE STRING,
PPCADJMDATE TYPE STRING,
PPCADJMINDX TYPE STRING,
PPCADJMPERCENT TYPE STRING,
PPCADJMAMOUNT TYPE STRING,
RELADJMPERCENT TYPE STRING,
RELADJMAMOUNT TYPE STRING,
ACCOMCONDTYPE TYPE STRING,
ACCOMBASEUPRICE TYPE STRING,
ACCOMVALIDFROM TYPE STRING,
YIELDCONDTYPE TYPE STRING,
YIELDBASEUPRICE TYPE STRING,
YIELDVALIDFROM TYPE STRING,
WOIINCONDTYPE TYPE STRING,
WOIINBASEUPRICE TYPE STRING,
WOIINVALIDFROM TYPE STRING,
ABSREASCOND TYPE STRING,
ABSREASAMOUNT TYPE STRING,
ABSREASPERCENT TYPE STRING,
ABSADJOPTION TYPE STRING,
ABSADJMPERCENT TYPE STRING,
ABSADJMAMOUNT TYPE STRING,
WOIREASCOND TYPE STRING,
WOIREASAMOUNT TYPE STRING,
WOIREASPERCENT TYPE STRING,
WOIADJMPERCENT TYPE STRING,
WOIADJMAMOUNT TYPE STRING,
ABSCONTRIBUTION TYPE STRING,
ADJCONDABS TYPE STRING,
ACCOMADJMUPRICE TYPE STRING,
YIELDADJMUPRICE TYPE STRING,
WOIINADJMUPRICE TYPE STRING,
PARMRELLOW TYPE STRING,
PARMRELLOWPRIO1 TYPE STRING,
PARMRELLOWPRIO2 TYPE STRING,
RESVAMOUNTPRIO1 TYPE STRING,
BASEADJMPRIO1 TYPE STRING,
ADJMPRIO1 TYPE STRING,
RESVAMOUNTPRIO2 TYPE STRING,
BASEADJMPRIO2 TYPE STRING,
ADJMPRIO2 TYPE STRING,
FREEVALUEABSINC TYPE STRING,
FREEVALUEPERCENT TYPE STRING,
FREEADJMPERCENT TYPE STRING,
FREEADJMAMOUNT TYPE STRING,
FREEADJMTXT TYPE STRING,
ADJMTXTDESCRIPT TYPE STRING,
ADJMTXTMOMENT TYPE STRING,
ADJMTXTREASON TYPE STRING,
ADJMTXTGUID TYPE STRING,END OF T_EKKO_STR. DATA: WA_VIXCAJRECCH01_TAB_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_VIXCAJRECCH01_TAB_STR-PROCESSGUID sy-vline
WA_VIXCAJRECCH01_TAB_STR-INTRENO sy-vline
WA_VIXCAJRECCH01_TAB_STR-CONDCURR sy-vline
WA_VIXCAJRECCH01_TAB_STR-MGRBASEREF sy-vline
WA_VIXCAJRECCH01_TAB_STR-MGRBASEDATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-MGRBASERATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-MGRADJMDATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-MGRADJMRATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-MGRADJMPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-MGRADJMAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCPERCENTTYPE sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCBASEINDX sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCBASEDATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCBASEPPCINDX sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCADJMDATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCADJNBMONTH sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCADJMPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCADJMPPCINDX sy-vline
WA_VIXCAJRECCH01_TAB_STR-MOCADJMAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCBASESERIES sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCBASEYEAR sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCBASEDATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCBASEINDX sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCPRCTPASS sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCADJMDATE sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCADJMINDX sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCADJMPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-PPCADJMAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-RELADJMPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-RELADJMAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ACCOMCONDTYPE sy-vline
WA_VIXCAJRECCH01_TAB_STR-ACCOMBASEUPRICE sy-vline
WA_VIXCAJRECCH01_TAB_STR-ACCOMVALIDFROM sy-vline
WA_VIXCAJRECCH01_TAB_STR-YIELDCONDTYPE sy-vline
WA_VIXCAJRECCH01_TAB_STR-YIELDBASEUPRICE sy-vline
WA_VIXCAJRECCH01_TAB_STR-YIELDVALIDFROM sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIINCONDTYPE sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIINBASEUPRICE sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIINVALIDFROM sy-vline
WA_VIXCAJRECCH01_TAB_STR-ABSREASCOND sy-vline
WA_VIXCAJRECCH01_TAB_STR-ABSREASAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ABSREASPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ABSADJOPTION sy-vline
WA_VIXCAJRECCH01_TAB_STR-ABSADJMPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ABSADJMAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIREASCOND sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIREASAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIREASPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIADJMPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIADJMAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ABSCONTRIBUTION sy-vline
WA_VIXCAJRECCH01_TAB_STR-ADJCONDABS sy-vline
WA_VIXCAJRECCH01_TAB_STR-ACCOMADJMUPRICE sy-vline
WA_VIXCAJRECCH01_TAB_STR-YIELDADJMUPRICE sy-vline
WA_VIXCAJRECCH01_TAB_STR-WOIINADJMUPRICE sy-vline
WA_VIXCAJRECCH01_TAB_STR-PARMRELLOW sy-vline
WA_VIXCAJRECCH01_TAB_STR-PARMRELLOWPRIO1 sy-vline
WA_VIXCAJRECCH01_TAB_STR-PARMRELLOWPRIO2 sy-vline
WA_VIXCAJRECCH01_TAB_STR-RESVAMOUNTPRIO1 sy-vline
WA_VIXCAJRECCH01_TAB_STR-BASEADJMPRIO1 sy-vline
WA_VIXCAJRECCH01_TAB_STR-ADJMPRIO1 sy-vline
WA_VIXCAJRECCH01_TAB_STR-RESVAMOUNTPRIO2 sy-vline
WA_VIXCAJRECCH01_TAB_STR-BASEADJMPRIO2 sy-vline
WA_VIXCAJRECCH01_TAB_STR-ADJMPRIO2 sy-vline
WA_VIXCAJRECCH01_TAB_STR-FREEVALUEABSINC sy-vline
WA_VIXCAJRECCH01_TAB_STR-FREEVALUEPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-FREEADJMPERCENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-FREEADJMAMOUNT sy-vline
WA_VIXCAJRECCH01_TAB_STR-FREEADJMTXT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ADJMTXTDESCRIPT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ADJMTXTMOMENT sy-vline
WA_VIXCAJRECCH01_TAB_STR-ADJMTXTREASON sy-vline
WA_VIXCAJRECCH01_TAB_STR-ADJMTXTGUID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.