ABAP Select data from SAP table /SCMTMS/S_TCC_DO_CHARGES_COM 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 /SCMTMS/S_TCC_DO_CHARGES_COM 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 /SCMTMS/S_TCC_DO_CHARGES_COM. 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 /SCMTMS/S_TCC_DO_CHARGES_COM 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_/SCMTMS/S_TCC_DO_CHARGES_COM TYPE STANDARD TABLE OF /SCMTMS/S_TCC_DO_CHARGES_COM, WA_/SCMTMS/S_TCC_DO_CHARGES_COM TYPE /SCMTMS/S_TCC_DO_CHARGES_COM, 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: </SCMTMS/S_TCC_DO_CHARGES_COM> TYPE /SCMTMS/S_TCC_DO_CHARGES_COM. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SCMTMS/S_TCC_DO_CHARGES_COM. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SCMTMS/S_TCC_DO_CHARGES_COM INTO TABLE IT_/SCMTMS/S_TCC_DO_CHARGES_COM. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SCMTMS/S_TCC_DO_CHARGES_COM * INTO TABLE @DATA(IT_/SCMTMS/S_TCC_DO_CHARGES_COM2). *--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_/SCMTMS/S_TCC_DO_CHARGES_COM INDEX 1 INTO DATA(WA_/SCMTMS/S_TCC_DO_CHARGES_COM2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SCMTMS/S_TCC_DO_CHARGES_COM ASSIGNING </SCMTMS/S_TCC_DO_CHARGES_COM>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMTMS/S_TCC_DO_CHARGES_COM>-NODE_ID = 1.
</SCMTMS/S_TCC_DO_CHARGES_COM>-PARENT_NODE_ID = 1.
</SCMTMS/S_TCC_DO_CHARGES_COM>-BO_KEY = 1.
</SCMTMS/S_TCC_DO_CHARGES_COM>-NODE_KEY = 1.
</SCMTMS/S_TCC_DO_CHARGES_COM>-HOST_BO_KEY = 1.
ENDLOOP. LOOP AT IT_/SCMTMS/S_TCC_DO_CHARGES_COM INTO WA_/SCMTMS/S_TCC_DO_CHARGES_COM. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SCMTMS/S_TCC_DO_CHARGES_COM-HOST_NODE_KEY, sy-vline,
WA_/SCMTMS/S_TCC_DO_CHARGES_COM-HOST_KEY, sy-vline,
WA_/SCMTMS/S_TCC_DO_CHARGES_COM-HOST_ROOT_KEY, sy-vline,
WA_/SCMTMS/S_TCC_DO_CHARGES_COM-PARTY_UUID, sy-vline,
WA_/SCMTMS/S_TCC_DO_CHARGES_COM-ORG_UNIT_ID, sy-vline,
WA_/SCMTMS/S_TCC_DO_CHARGES_COM-ORG_OFF_ID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMTMS/S_TCC_DO_CHARGES_COM 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_/SCMTMS/S_TCC_DO_CHARGES_COM 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_/SCMTMS/S_TCC_DO_CHARGES_COM INTO WA_/SCMTMS/S_TCC_DO_CHARGES_COM. *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 ID001, internal->external for field PARTY_UUID CALL FUNCTION 'CONVERSION_EXIT_ID001_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TCC_DO_CHARGES_COM-PARTY_UUID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TCC_DO_CHARGES_COM-PARTY_UUID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FAGRMNTID044 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TCC_DO_CHARGES_COM-FAGRMNTID044 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TCC_DO_CHARGES_COM-FAGRMNTID044.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FAGRMNT_ITEM_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TCC_DO_CHARGES_COM-FAGRMNT_ITEM_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TCC_DO_CHARGES_COM-FAGRMNT_ITEM_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field TCCS_ID047 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TCC_DO_CHARGES_COM-TCCS_ID047 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TCC_DO_CHARGES_COM-TCCS_ID047.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ID004, internal->external for field SOURCELOC_UUID CALL FUNCTION 'CONVERSION_EXIT_ID004_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TCC_DO_CHARGES_COM-SOURCELOC_UUID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TCC_DO_CHARGES_COM-SOURCELOC_UUID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ID004, internal->external for field DESTLOC_UUID CALL FUNCTION 'CONVERSION_EXIT_ID004_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TCC_DO_CHARGES_COM-DESTLOC_UUID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TCC_DO_CHARGES_COM-DESTLOC_UUID.
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_/SCMTMS/S_TCC_DO_CHARGES_COM_STR,
NODE_ID TYPE STRING,
PARENT_NODE_ID TYPE STRING,
BO_KEY TYPE STRING,
NODE_KEY TYPE STRING,
HOST_BO_KEY TYPE STRING,
HOST_NODE_KEY TYPE STRING,
HOST_KEY TYPE STRING,
HOST_ROOT_KEY TYPE STRING,
PARTY_UUID TYPE STRING,
ORG_UNIT_ID TYPE STRING,
ORG_OFF_ID TYPE STRING,
ORG_GRP_ID TYPE STRING,
TCUSAGECD085 TYPE STRING,
TCHARGESID086 TYPE STRING,
UUID TYPE STRING,
FAGRMNTID044 TYPE STRING,
FAGRMNT_ITEM_NO TYPE STRING,
FAGRMNTVSID045 TYPE STRING,
TCCS_ID047 TYPE STRING,
UUID020 TYPE STRING,
UUID057 TYPE STRING,
EXCH_RATE_TYPE TYPE STRING,
CALCULATION_DATE TYPE STRING,
EXCH_RATE_DATE TYPE STRING,
EXCH_RATE_DATE_LCL TYPE STRING,
FAG_FIXATION173 TYPE STRING,
TXC_KEY TYPE STRING,
TEXT_SCHEMA_ID TYPE STRING,
MERGE_INDICATOR TYPE STRING,
FAG_IT_KEY TYPE STRING,
EEW_TCH_ROOT TYPE STRING,
CALC_DATE_TSTMP TYPE STRING,
CALC_DATE_TZONE TYPE STRING,
AMOUNTINV TYPE STRING,
CURRCODE016INV TYPE STRING,
AMOUNTTIN TYPE STRING,
CURRCODE016TIN TYPE STRING,
AMOUNT TYPE STRING,
CURRCODE016 TYPE STRING,
AMOUNTLCL TYPE STRING,
CURRCODE016LCL TYPE STRING,
CASHDISCOUNT TYPE STRING,
CURRENCIES TYPE STRING,
EXCHANGERATES TYPE STRING,
PAYMENTINSTRUCTIONS TYPE STRING,
PERCENTAGEDETAILS TYPE STRING,
TAXDETAILS TYPE STRING,
CHARGEELEMENTS TYPE STRING,
CHAROTMANCHNG TYPE STRING,
PAYMENTTERMS TYPE STRING,
ROOT_LEVEL TYPE STRING,
DIM_WT_PROFILE TYPE STRING,
TYPE_CODE TYPE STRING,
CARRIER_PRODUCT_ID TYPE STRING,
SOURCELOC_UUID TYPE STRING,
DESTLOC_UUID TYPE STRING,
INV_READY TYPE STRING,
CALC_LEVEL_ID TYPE STRING,
IS_HEADER_CHARGE TYPE STRING,
TACT_REL_ITEM TYPE STRING,
EXECUTING_DOC_KEY TYPE STRING,
IS_TECHNICAL TYPE STRING,
BILLING_SCHEME TYPE STRING,
GROUP_ID TYPE STRING,
CURRCODE_LINE TYPE STRING,
CURRUSGCD017_LINE TYPE STRING,
EXCHGRATETCO05_I_LINE TYPE STRING,
CURRCODE_LCL TYPE STRING,
CURRUSGCD017_LCL TYPE STRING,
EXCHGRATETCO05_I_LCL TYPE STRING,
ZTERM TYPE STRING,
BASELINE_DATE TYPE STRING,
MANUAL_ENTRY TYPE STRING,
EEW_PAY_TERMS TYPE STRING,
FIX_MANUAL_QTY_RELV TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMTMS/S_TCC_DO_CHARGES_COM_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_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-NODE_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-PARENT_NODE_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-BO_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-NODE_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-HOST_BO_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-HOST_NODE_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-HOST_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-HOST_ROOT_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-PARTY_UUID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-ORG_UNIT_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-ORG_OFF_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-ORG_GRP_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TCUSAGECD085 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TCHARGESID086 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-UUID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-FAGRMNTID044 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-FAGRMNT_ITEM_NO sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-FAGRMNTVSID045 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TCCS_ID047 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-UUID020 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-UUID057 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EXCH_RATE_TYPE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CALCULATION_DATE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EXCH_RATE_DATE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EXCH_RATE_DATE_LCL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-FAG_FIXATION173 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TXC_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TEXT_SCHEMA_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-MERGE_INDICATOR sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-FAG_IT_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EEW_TCH_ROOT sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CALC_DATE_TSTMP sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CALC_DATE_TZONE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-AMOUNTINV sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRCODE016INV sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-AMOUNTTIN sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRCODE016TIN sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-AMOUNT sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRCODE016 sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-AMOUNTLCL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRCODE016LCL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CASHDISCOUNT sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRENCIES sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EXCHANGERATES sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-PAYMENTINSTRUCTIONS sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-PERCENTAGEDETAILS sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TAXDETAILS sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CHARGEELEMENTS sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CHAROTMANCHNG sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-PAYMENTTERMS sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-ROOT_LEVEL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-DIM_WT_PROFILE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TYPE_CODE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CARRIER_PRODUCT_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-SOURCELOC_UUID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-DESTLOC_UUID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-INV_READY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CALC_LEVEL_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-IS_HEADER_CHARGE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-TACT_REL_ITEM sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EXECUTING_DOC_KEY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-IS_TECHNICAL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-BILLING_SCHEME sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-GROUP_ID sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRCODE_LINE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRUSGCD017_LINE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EXCHGRATETCO05_I_LINE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRCODE_LCL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-CURRUSGCD017_LCL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EXCHGRATETCO05_I_LCL sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-ZTERM sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-BASELINE_DATE sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-MANUAL_ENTRY sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-EEW_PAY_TERMS sy-vline
WA_/SCMTMS/S_TCC_DO_CHARGES_COM_STR-FIX_MANUAL_QTY_RELV sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.