ABAP Select data from SAP table TCM_S_CFIR_ITM_CHRG_ELE_PRINT 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 TCM_S_CFIR_ITM_CHRG_ELE_PRINT 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 TCM_S_CFIR_ITM_CHRG_ELE_PRINT. 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 TCM_S_CFIR_ITM_CHRG_ELE_PRINT 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_TCM_S_CFIR_ITM_CHRG_ELE_PRINT TYPE STANDARD TABLE OF TCM_S_CFIR_ITM_CHRG_ELE_PRINT, WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT TYPE TCM_S_CFIR_ITM_CHRG_ELE_PRINT, 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: <TCM_S_CFIR_ITM_CHRG_ELE_PRINT> TYPE TCM_S_CFIR_ITM_CHRG_ELE_PRINT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_TCM_S_CFIR_ITM_CHRG_ELE_PRINT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM TCM_S_CFIR_ITM_CHRG_ELE_PRINT INTO TABLE IT_TCM_S_CFIR_ITM_CHRG_ELE_PRINT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM TCM_S_CFIR_ITM_CHRG_ELE_PRINT * INTO TABLE @DATA(IT_TCM_S_CFIR_ITM_CHRG_ELE_PRINT2). *--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_TCM_S_CFIR_ITM_CHRG_ELE_PRINT INDEX 1 INTO DATA(WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_TCM_S_CFIR_ITM_CHRG_ELE_PRINT ASSIGNING <TCM_S_CFIR_ITM_CHRG_ELE_PRINT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<TCM_S_CFIR_ITM_CHRG_ELE_PRINT>-ITM_CHRG_ELE_KEY = 1.
<TCM_S_CFIR_ITM_CHRG_ELE_PRINT>-TYPE_CODE = 1.
<TCM_S_CFIR_ITM_CHRG_ELE_PRINT>-CATEGORY_CODE = 1.
<TCM_S_CFIR_ITM_CHRG_ELE_PRINT>-SUB_CATEGORY_CODE = 1.
<TCM_S_CFIR_ITM_CHRG_ELE_PRINT>-CONDITION_TYPE = 1.
ENDLOOP. LOOP AT IT_TCM_S_CFIR_ITM_CHRG_ELE_PRINT INTO WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KPOSN, sy-vline,
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-STUNR, sy-vline,
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-ZAEHK, sy-vline,
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KAPPL, sy-vline,
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KSCHL, sy-vline,
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KRECH, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT 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_TCM_S_CFIR_ITM_CHRG_ELE_PRINT 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_TCM_S_CFIR_ITM_CHRG_ELE_PRINT INTO WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT. *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 EXCRT, internal->external for field KKURS CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KKURS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KKURS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field KMEIN CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KMEIN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT-KMEIN.
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_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR,
ITM_CHRG_ELE_KEY TYPE STRING,
TYPE_CODE TYPE STRING,
CATEGORY_CODE TYPE STRING,
SUB_CATEGORY_CODE TYPE STRING,
CONDITION_TYPE TYPE STRING,
KPOSN TYPE STRING,
STUNR TYPE STRING,
ZAEHK TYPE STRING,
KAPPL TYPE STRING,
KSCHL TYPE STRING,
KRECH TYPE STRING,
KAWRT TYPE STRING,
AWEIN TYPE STRING,
AWEI1 TYPE STRING,
KBETR TYPE STRING,
KOEIN TYPE STRING,
KOEI1 TYPE STRING,
KKURS TYPE STRING,
KPEIN TYPE STRING,
KMEIN TYPE STRING,
KUMZA TYPE STRING,
KUMNE TYPE STRING,
KNTYP TYPE STRING,
KSTAT TYPE STRING,
KHERK TYPE STRING,
KWERT TYPE STRING,
KSTEU TYPE STRING,
KINAK TYPE STRING,
KOAID TYPE STRING,
KNUMT TYPE STRING,
DRUKZ TYPE STRING,
VTEXT TYPE STRING,
MWSKZ TYPE STRING,
STUFE TYPE STRING,
WEGXX TYPE STRING,
KFAKTOR TYPE STRING,
NRMNG TYPE STRING,
MDFLG TYPE STRING,
KWERT_EURO TYPE STRING,
KAQTY TYPE STRING,
KWERT_HWAER TYPE STRING,
KAWRT_HWAER TYPE STRING,
TAX_COUNTRY TYPE STRING,
RATE_AMOUNT TYPE STRING,
RATE_CURRENCY TYPE STRING,
CONTAINER_ID TYPE STRING,
PRODUCT_ID TYPE STRING,
RESOURCE_ID TYPE STRING,
RESOURCE_KEY TYPE STRING,
STAGE_KEY TYPE STRING,
STAGE_SRC_LOC TYPE STRING,
STAGE_DEST_LOC TYPE STRING,END OF T_EKKO_STR. DATA: WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_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_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-ITM_CHRG_ELE_KEY sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-TYPE_CODE sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-CATEGORY_CODE sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-SUB_CATEGORY_CODE sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-CONDITION_TYPE sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KPOSN sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-STUNR sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-ZAEHK sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KAPPL sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KSCHL sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KRECH sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KAWRT sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-AWEIN sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-AWEI1 sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KBETR sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KOEIN sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KOEI1 sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KKURS sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KPEIN sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KMEIN sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KUMZA sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KUMNE sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KNTYP sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KSTAT sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KHERK sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KWERT sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KSTEU sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KINAK sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KOAID sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KNUMT sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-DRUKZ sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-VTEXT sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-MWSKZ sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-STUFE sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-WEGXX sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KFAKTOR sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-NRMNG sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-MDFLG sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KWERT_EURO sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KAQTY sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KWERT_HWAER sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-KAWRT_HWAER sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-TAX_COUNTRY sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-RATE_AMOUNT sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-RATE_CURRENCY sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-CONTAINER_ID sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-PRODUCT_ID sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-RESOURCE_ID sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-RESOURCE_KEY sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-STAGE_KEY sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-STAGE_SRC_LOC sy-vline
WA_TCM_S_CFIR_ITM_CHRG_ELE_PRINT_STR-STAGE_DEST_LOC sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.