ABAP Select data from SAP table ISTMNTOFCHANGES 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 ISTMNTOFCHANGES 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 ISTMNTOFCHANGES. 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 ISTMNTOFCHANGES 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_ISTMNTOFCHANGES TYPE STANDARD TABLE OF ISTMNTOFCHANGES,
      WA_ISTMNTOFCHANGES TYPE ISTMNTOFCHANGES,
      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: <ISTMNTOFCHANGES> TYPE ISTMNTOFCHANGES.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ISTMNTOFCHANGES
*  INTO TABLE @DATA(IT_ISTMNTOFCHANGES2).
*--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_ISTMNTOFCHANGES INDEX 1 INTO DATA(WA_ISTMNTOFCHANGES2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ISTMNTOFCHANGES ASSIGNING <ISTMNTOFCHANGES>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ISTMNTOFCHANGES>-MANDT = 1.
<ISTMNTOFCHANGES>-LEDGER = 1.
<ISTMNTOFCHANGES>-COMPANYCODE = 1.
<ISTMNTOFCHANGES>-FISCALYEAR = 1.
<ISTMNTOFCHANGES>-STATEMENTOFCHANGESSORTORDER = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ISTMNTOFCHANGES-FINANCIALTRANSACTIONTYPE, sy-vline,
WA_ISTMNTOFCHANGES-LEDGERFISCALYEAR, sy-vline,
WA_ISTMNTOFCHANGES-GLACCOUNT, sy-vline,
WA_ISTMNTOFCHANGES-PROFITCENTER, sy-vline,
WA_ISTMNTOFCHANGES-FUNCTIONALAREA, sy-vline,
WA_ISTMNTOFCHANGES-BUSINESSAREA, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ISTMNTOFCHANGES 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_ISTMNTOFCHANGES 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_ISTMNTOFCHANGES INTO WA_ISTMNTOFCHANGES. *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 LEDGER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-LEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-LEDGER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field FISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-FISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-FISCALYEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field LEDGERFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-LEDGERFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-LEDGERFISCALYEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field GLACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-GLACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-GLACCOUNT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PROFITCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-PROFITCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-PROFITCENTER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SEGMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-SEGMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-SEGMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ORDERID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-ORDERID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-ORDERID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SUPPLIER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-SUPPLIER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-SUPPLIER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field COSTCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-COSTCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-COSTCENTER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ASSETCLASS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-ASSETCLASS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-ASSETCLASS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SALESDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-SALESDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-SALESDOCUMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SERVICEDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-SERVICEDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-SERVICEDOCUMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CUSTOMER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-CUSTOMER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-CUSTOMER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PARTNERCOMPANY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTMNTOFCHANGES-PARTNERCOMPANY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTMNTOFCHANGES-PARTNERCOMPANY.
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_ISTMNTOFCHANGES_STR,
MANDT TYPE STRING,
LEDGER TYPE STRING,
COMPANYCODE TYPE STRING,
FISCALYEAR TYPE STRING,
STATEMENTOFCHANGESSORTORDER TYPE STRING,
FINANCIALTRANSACTIONTYPE TYPE STRING,
LEDGERFISCALYEAR TYPE STRING,
GLACCOUNT TYPE STRING,
PROFITCENTER TYPE STRING,
FUNCTIONALAREA TYPE STRING,
BUSINESSAREA TYPE STRING,
CONTROLLINGAREA TYPE STRING,
SEGMENT TYPE STRING,
DEBITCREDITCODE TYPE STRING,
FISCALYEARVARIANT TYPE STRING,
FISCALYEARPERIOD TYPE STRING,
POSTINGDATE TYPE STRING,
CHARTOFACCOUNTS TYPE STRING,
TRANSACTIONCURRENCY TYPE STRING,
AMOUNTINTRANSACTIONCURRENCY TYPE STRING,
COMPANYCODECURRENCY TYPE STRING,
AMOUNTINCOMPANYCODECURRENCY TYPE STRING,
GLOBALCURRENCY TYPE STRING,
AMOUNTINGLOBALCURRENCY TYPE STRING,
FREEDEFINEDCURRENCY1 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY1 TYPE STRING,
FREEDEFINEDCURRENCY2 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY2 TYPE STRING,
FREEDEFINEDCURRENCY3 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY3 TYPE STRING,
FREEDEFINEDCURRENCY4 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY4 TYPE STRING,
FREEDEFINEDCURRENCY5 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY5 TYPE STRING,
FREEDEFINEDCURRENCY6 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY6 TYPE STRING,
FREEDEFINEDCURRENCY7 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY7 TYPE STRING,
FREEDEFINEDCURRENCY8 TYPE STRING,
AMOUNTINFREEDEFINEDCURRENCY8 TYPE STRING,
FISCALPERIOD TYPE STRING,
ORDERID TYPE STRING,
SUPPLIER TYPE STRING,
COSTCENTER TYPE STRING,
ORGANIZATIONDIVISION TYPE STRING,
SERVICEDOCUMENTTYPE TYPE STRING,
ASSETCLASS TYPE STRING,
PLANT TYPE STRING,
VALUATIONAREA TYPE STRING,
FINANCIALACCOUNTTYPE TYPE STRING,
SALESDOCUMENT TYPE STRING,
SALESORGANIZATION TYPE STRING,
DISTRIBUTIONCHANNEL TYPE STRING,
SERVICEDOCUMENT TYPE STRING,
CUSTOMER TYPE STRING,
ACCOUNTINGDOCUMENTTYPE TYPE STRING,
SERVICEDOCUMENTITEM TYPE STRING,
PARTNERCOMPANY TYPE STRING,
FISCALQUARTER TYPE STRING,
FISCALWEEK TYPE STRING,
FISCALYEARQUARTER TYPE STRING,
FISCALYEARWEEK TYPE STRING,
FISCALPERIODSTARTDATE TYPE STRING,
FISCALPERIODENDDATE TYPE STRING,
DISPLAYCURRENCY TYPE STRING,
AMOUNTINDISPLAYCURRENCY TYPE STRING,END OF T_EKKO_STR. DATA: WA_ISTMNTOFCHANGES_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_ISTMNTOFCHANGES_STR-MANDT sy-vline
WA_ISTMNTOFCHANGES_STR-LEDGER sy-vline
WA_ISTMNTOFCHANGES_STR-COMPANYCODE sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALYEAR sy-vline
WA_ISTMNTOFCHANGES_STR-STATEMENTOFCHANGESSORTORDER sy-vline
WA_ISTMNTOFCHANGES_STR-FINANCIALTRANSACTIONTYPE sy-vline
WA_ISTMNTOFCHANGES_STR-LEDGERFISCALYEAR sy-vline
WA_ISTMNTOFCHANGES_STR-GLACCOUNT sy-vline
WA_ISTMNTOFCHANGES_STR-PROFITCENTER sy-vline
WA_ISTMNTOFCHANGES_STR-FUNCTIONALAREA sy-vline
WA_ISTMNTOFCHANGES_STR-BUSINESSAREA sy-vline
WA_ISTMNTOFCHANGES_STR-CONTROLLINGAREA sy-vline
WA_ISTMNTOFCHANGES_STR-SEGMENT sy-vline
WA_ISTMNTOFCHANGES_STR-DEBITCREDITCODE sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALYEARVARIANT sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALYEARPERIOD sy-vline
WA_ISTMNTOFCHANGES_STR-POSTINGDATE sy-vline
WA_ISTMNTOFCHANGES_STR-CHARTOFACCOUNTS sy-vline
WA_ISTMNTOFCHANGES_STR-TRANSACTIONCURRENCY sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINTRANSACTIONCURRENCY sy-vline
WA_ISTMNTOFCHANGES_STR-COMPANYCODECURRENCY sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINCOMPANYCODECURRENCY sy-vline
WA_ISTMNTOFCHANGES_STR-GLOBALCURRENCY sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINGLOBALCURRENCY sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY1 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY1 sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY2 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY2 sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY3 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY3 sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY4 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY4 sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY5 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY5 sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY6 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY6 sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY7 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY7 sy-vline
WA_ISTMNTOFCHANGES_STR-FREEDEFINEDCURRENCY8 sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINFREEDEFINEDCURRENCY8 sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALPERIOD sy-vline
WA_ISTMNTOFCHANGES_STR-ORDERID sy-vline
WA_ISTMNTOFCHANGES_STR-SUPPLIER sy-vline
WA_ISTMNTOFCHANGES_STR-COSTCENTER sy-vline
WA_ISTMNTOFCHANGES_STR-ORGANIZATIONDIVISION sy-vline
WA_ISTMNTOFCHANGES_STR-SERVICEDOCUMENTTYPE sy-vline
WA_ISTMNTOFCHANGES_STR-ASSETCLASS sy-vline
WA_ISTMNTOFCHANGES_STR-PLANT sy-vline
WA_ISTMNTOFCHANGES_STR-VALUATIONAREA sy-vline
WA_ISTMNTOFCHANGES_STR-FINANCIALACCOUNTTYPE sy-vline
WA_ISTMNTOFCHANGES_STR-SALESDOCUMENT sy-vline
WA_ISTMNTOFCHANGES_STR-SALESORGANIZATION sy-vline
WA_ISTMNTOFCHANGES_STR-DISTRIBUTIONCHANNEL sy-vline
WA_ISTMNTOFCHANGES_STR-SERVICEDOCUMENT sy-vline
WA_ISTMNTOFCHANGES_STR-CUSTOMER sy-vline
WA_ISTMNTOFCHANGES_STR-ACCOUNTINGDOCUMENTTYPE sy-vline
WA_ISTMNTOFCHANGES_STR-SERVICEDOCUMENTITEM sy-vline
WA_ISTMNTOFCHANGES_STR-PARTNERCOMPANY sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALQUARTER sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALWEEK sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALYEARQUARTER sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALYEARWEEK sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALPERIODSTARTDATE sy-vline
WA_ISTMNTOFCHANGES_STR-FISCALPERIODENDDATE sy-vline
WA_ISTMNTOFCHANGES_STR-DISPLAYCURRENCY sy-vline
WA_ISTMNTOFCHANGES_STR-AMOUNTINDISPLAYCURRENCY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.