ABAP Select data from SAP table IACEDFRLPERDCAMT 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 IACEDFRLPERDCAMT 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 IACEDFRLPERDCAMT. 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 IACEDFRLPERDCAMT 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_IACEDFRLPERDCAMT TYPE STANDARD TABLE OF IACEDFRLPERDCAMT, WA_IACEDFRLPERDCAMT TYPE IACEDFRLPERDCAMT, 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: <IACEDFRLPERDCAMT> TYPE IACEDFRLPERDCAMT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_IACEDFRLPERDCAMT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM IACEDFRLPERDCAMT INTO TABLE IT_IACEDFRLPERDCAMT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM IACEDFRLPERDCAMT * INTO TABLE @DATA(IT_IACEDFRLPERDCAMT2). *--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_IACEDFRLPERDCAMT INDEX 1 INTO DATA(WA_IACEDFRLPERDCAMT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_IACEDFRLPERDCAMT ASSIGNING <IACEDFRLPERDCAMT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<IACEDFRLPERDCAMT>-MANDT = 1.
<IACEDFRLPERDCAMT>-ACCRUALENGINEACCRUALOBJECTTYPE = 1.
<IACEDFRLPERDCAMT>-ACCRUALOBJECTLOGICALSYSTEM = 1.
<IACEDFRLPERDCAMT>-COMPANYCODE = 1.
<IACEDFRLPERDCAMT>-ACCRUALOBJECT = 1.
ENDLOOP. LOOP AT IT_IACEDFRLPERDCAMT INTO WA_IACEDFRLPERDCAMT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_IACEDFRLPERDCAMT-ACCRUALSUBOBJECT, sy-vline,
WA_IACEDFRLPERDCAMT-ACCRUALITEMTYPE, sy-vline,
WA_IACEDFRLPERDCAMT-LEDGER, sy-vline,
WA_IACEDFRLPERDCAMT-ACCRUALPERIODENDDATE, sy-vline,
WA_IACEDFRLPERDCAMT-ACCRUALPERIODSTARTDATE, sy-vline,
WA_IACEDFRLPERDCAMT-ACCRPERIODAMTCALCULATIONMETHOD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IACEDFRLPERDCAMT 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_IACEDFRLPERDCAMT 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_IACEDFRLPERDCAMT INTO WA_IACEDFRLPERDCAMT. *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 ACCRUALOBJECTLOGICALSYSTEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-ACCRUALOBJECTLOGICALSYSTEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-ACCRUALOBJECTLOGICALSYSTEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ACCRUALITEMTYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-ACCRUALITEMTYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-ACCRUALITEMTYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LEDGER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-LEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-LEDGER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINTRANSCRCY CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINTRANSCRCY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINTRANSCRCY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINCOCODECRCY CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINCOCODECRCY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINCOCODECRCY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINGLOBALCRCY CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINGLOBALCRCY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINGLOBALCRCY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY1 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY1.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY2 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY2.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY3 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY3 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY3.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY4 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY4 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY4.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY5 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY5 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY5.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY6 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY6 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY6.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY7 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY7 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY7.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field DEFERREDCOSTINFREEDFNDCRCY8 CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY8 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-DEFERREDCOSTINFREEDFNDCRCY8.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field TOTALACCRUALQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IACEDFRLPERDCAMT-TOTALACCRUALQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IACEDFRLPERDCAMT-TOTALACCRUALQUANTITYUNIT.
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_IACEDFRLPERDCAMT_STR,
MANDT TYPE STRING,
ACCRUALENGINEACCRUALOBJECTTYPE TYPE STRING,
ACCRUALOBJECTLOGICALSYSTEM TYPE STRING,
COMPANYCODE TYPE STRING,
ACCRUALOBJECT TYPE STRING,
ACCRUALSUBOBJECT TYPE STRING,
ACCRUALITEMTYPE TYPE STRING,
LEDGER TYPE STRING,
ACCRUALPERIODENDDATE TYPE STRING,
ACCRUALPERIODSTARTDATE TYPE STRING,
ACCRPERIODAMTCALCULATIONMETHOD TYPE STRING,
ACCRUALAMOUNTPROPOSEDBYUSER TYPE STRING,
ACCRUALAMOUNTPROPOSALDATE TYPE STRING,
ACCRUALAMOUNTPROPOSALTIME TYPE STRING,
TRANSACTIONCURRENCY TYPE STRING,
COMPANYCODECURRENCY TYPE STRING,
GLOBALCURRENCY TYPE STRING,
FREEDEFINEDCURRENCY1 TYPE STRING,
FREEDEFINEDCURRENCY2 TYPE STRING,
FREEDEFINEDCURRENCY3 TYPE STRING,
FREEDEFINEDCURRENCY4 TYPE STRING,
FREEDEFINEDCURRENCY5 TYPE STRING,
FREEDEFINEDCURRENCY6 TYPE STRING,
FREEDEFINEDCURRENCY7 TYPE STRING,
FREEDEFINEDCURRENCY8 TYPE STRING,
DEFERREDCOSTINTRANSCRCY TYPE STRING,
DEFERREDCOSTINCOCODECRCY TYPE STRING,
DEFERREDCOSTINGLOBALCRCY TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY1 TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY2 TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY3 TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY4 TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY5 TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY6 TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY7 TYPE STRING,
DEFERREDCOSTINFREEDFNDCRCY8 TYPE STRING,
TOTALACCRUALQUANTITYUNIT TYPE STRING,
DEFERREDQUANTITYINBASEUNIT TYPE STRING,END OF T_EKKO_STR. DATA: WA_IACEDFRLPERDCAMT_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_IACEDFRLPERDCAMT_STR-MANDT sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALENGINEACCRUALOBJECTTYPE sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALOBJECTLOGICALSYSTEM sy-vline
WA_IACEDFRLPERDCAMT_STR-COMPANYCODE sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALOBJECT sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALSUBOBJECT sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALITEMTYPE sy-vline
WA_IACEDFRLPERDCAMT_STR-LEDGER sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALPERIODENDDATE sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALPERIODSTARTDATE sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRPERIODAMTCALCULATIONMETHOD sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALAMOUNTPROPOSEDBYUSER sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALAMOUNTPROPOSALDATE sy-vline
WA_IACEDFRLPERDCAMT_STR-ACCRUALAMOUNTPROPOSALTIME sy-vline
WA_IACEDFRLPERDCAMT_STR-TRANSACTIONCURRENCY sy-vline
WA_IACEDFRLPERDCAMT_STR-COMPANYCODECURRENCY sy-vline
WA_IACEDFRLPERDCAMT_STR-GLOBALCURRENCY sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY1 sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY2 sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY3 sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY4 sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY5 sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY6 sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY7 sy-vline
WA_IACEDFRLPERDCAMT_STR-FREEDEFINEDCURRENCY8 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINTRANSCRCY sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINCOCODECRCY sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINGLOBALCRCY sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY1 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY2 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY3 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY4 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY5 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY6 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY7 sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDCOSTINFREEDFNDCRCY8 sy-vline
WA_IACEDFRLPERDCAMT_STR-TOTALACCRUALQUANTITYUNIT sy-vline
WA_IACEDFRLPERDCAMT_STR-DEFERREDQUANTITYINBASEUNIT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.