ABAP Select data from SAP table TKKAU 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 TKKAU 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 TKKAU. 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 TKKAU 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_TKKAU TYPE STANDARD TABLE OF TKKAU, WA_TKKAU TYPE TKKAU, 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: <TKKAU> TYPE TKKAU. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_TKKAU. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM TKKAU INTO TABLE IT_TKKAU. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM TKKAU * INTO TABLE @DATA(IT_TKKAU2). *--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_TKKAU INDEX 1 INTO DATA(WA_TKKAU2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_TKKAU ASSIGNING <TKKAU>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<TKKAU>-METHO = 1.
<TKKAU>-STATART = 1.
<TKKAU>-PRIST = 1.
<TKKAU>-NABGR = 1.
<TKKAU>-ABART = 1.
ENDLOOP. LOOP AT IT_TKKAU INTO WA_TKKAU. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_TKKAU-BASIS, sy-vline,
WA_TKKAU-GEWBS, sy-vline,
WA_TKKAU-EBMAX, sy-vline,
WA_TKKAU-EBBVA, sy-vline,
WA_TKKAU-OBLIA, sy-vline,
WA_TKKAU-OBLIB, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TKKAU 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_TKKAU 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_TKKAU INTO WA_TKKAU. *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 VERSP CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TKKAU-VERSP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-VERSP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VERSI CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TKKAU-VERSI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-VERSI.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VERSS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TKKAU-VERSS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-VERSS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field MIBST CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-MIBST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-MIBST.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field MIRUE CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-MIRUE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-MIRUE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field MIPRO CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-MIPRO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-MIPRO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field MIRDV CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-MIRDV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-MIRDV.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWBST CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-SWBST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-SWBST.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWRUE CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-SWRUE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-SWRUE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWPRO CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-SWPRO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-SWPRO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC152, internal->external for field SWRDV CALL FUNCTION 'CONVERSION_EXIT_AC152_OUTPUT' EXPORTING input = WA_TKKAU-SWRDV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TKKAU-SWRDV.
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_TKKAU_STR,
METHO TYPE STRING,
STATART TYPE STRING,
PRIST TYPE STRING,
NABGR TYPE STRING,
ABART TYPE STRING,
BASIS TYPE STRING,
GEWBS TYPE STRING,
EBMAX TYPE STRING,
EBBVA TYPE STRING,
OBLIA TYPE STRING,
OBLIB TYPE STRING,
OBLIR TYPE STRING,
VERSP TYPE STRING,
VERSI TYPE STRING,
VERSS TYPE STRING,
AFTLB TYPE STRING,
AFTLR TYPE STRING,
AFTLP TYPE STRING,
GEWKZ TYPE STRING,
VREAL TYPE STRING,
AFTLV TYPE STRING,
ALBST TYPE STRING,
ALRUE TYPE STRING,
ALPRO TYPE STRING,
ALRDV TYPE STRING,
DABSP TYPE STRING,
BWBST TYPE STRING,
EBBEW TYPE STRING,
KDUFR TYPE STRING,
ENDKZ TYPE STRING,
UMVTL TYPE STRING,
EINZL TYPE STRING,
MIBST TYPE STRING,
MIRUE TYPE STRING,
MIPRO TYPE STRING,
MIRDV TYPE STRING,
AFTLK TYPE STRING,
SOLBS TYPE STRING,
RFLG1 TYPE STRING,
RFLG2 TYPE STRING,
RFLG3 TYPE STRING,
RFLG4 TYPE STRING,
RFLG5 TYPE STRING,
RFLG6 TYPE STRING,
GWPRZ TYPE STRING,
ZLNID TYPE STRING,
STRPL TYPE STRING,
MAXPI TYPE STRING,
MXZID TYPE STRING,
RFLG7 TYPE STRING,
RFLG8 TYPE STRING,
RFLG9 TYPE STRING,
ELZID TYPE STRING,
SWBST TYPE STRING,
SWRUE TYPE STRING,
SWPRO TYPE STRING,
SWRDV TYPE STRING,
EMPRZ TYPE STRING,
EMPKZ TYPE STRING,
BWVAR TYPE STRING,
RFLG10 TYPE STRING,
RFLG11 TYPE STRING,
RFLG12 TYPE STRING,
RFLG13 TYPE STRING,
RFLG14 TYPE STRING,
RFLG15 TYPE STRING,
PROFNR TYPE STRING,
MENGE TYPE STRING,END OF T_EKKO_STR. DATA: WA_TKKAU_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_TKKAU_STR-METHO sy-vline
WA_TKKAU_STR-STATART sy-vline
WA_TKKAU_STR-PRIST sy-vline
WA_TKKAU_STR-NABGR sy-vline
WA_TKKAU_STR-ABART sy-vline
WA_TKKAU_STR-BASIS sy-vline
WA_TKKAU_STR-GEWBS sy-vline
WA_TKKAU_STR-EBMAX sy-vline
WA_TKKAU_STR-EBBVA sy-vline
WA_TKKAU_STR-OBLIA sy-vline
WA_TKKAU_STR-OBLIB sy-vline
WA_TKKAU_STR-OBLIR sy-vline
WA_TKKAU_STR-VERSP sy-vline
WA_TKKAU_STR-VERSI sy-vline
WA_TKKAU_STR-VERSS sy-vline
WA_TKKAU_STR-AFTLB sy-vline
WA_TKKAU_STR-AFTLR sy-vline
WA_TKKAU_STR-AFTLP sy-vline
WA_TKKAU_STR-GEWKZ sy-vline
WA_TKKAU_STR-VREAL sy-vline
WA_TKKAU_STR-AFTLV sy-vline
WA_TKKAU_STR-ALBST sy-vline
WA_TKKAU_STR-ALRUE sy-vline
WA_TKKAU_STR-ALPRO sy-vline
WA_TKKAU_STR-ALRDV sy-vline
WA_TKKAU_STR-DABSP sy-vline
WA_TKKAU_STR-BWBST sy-vline
WA_TKKAU_STR-EBBEW sy-vline
WA_TKKAU_STR-KDUFR sy-vline
WA_TKKAU_STR-ENDKZ sy-vline
WA_TKKAU_STR-UMVTL sy-vline
WA_TKKAU_STR-EINZL sy-vline
WA_TKKAU_STR-MIBST sy-vline
WA_TKKAU_STR-MIRUE sy-vline
WA_TKKAU_STR-MIPRO sy-vline
WA_TKKAU_STR-MIRDV sy-vline
WA_TKKAU_STR-AFTLK sy-vline
WA_TKKAU_STR-SOLBS sy-vline
WA_TKKAU_STR-RFLG1 sy-vline
WA_TKKAU_STR-RFLG2 sy-vline
WA_TKKAU_STR-RFLG3 sy-vline
WA_TKKAU_STR-RFLG4 sy-vline
WA_TKKAU_STR-RFLG5 sy-vline
WA_TKKAU_STR-RFLG6 sy-vline
WA_TKKAU_STR-GWPRZ sy-vline
WA_TKKAU_STR-ZLNID sy-vline
WA_TKKAU_STR-STRPL sy-vline
WA_TKKAU_STR-MAXPI sy-vline
WA_TKKAU_STR-MXZID sy-vline
WA_TKKAU_STR-RFLG7 sy-vline
WA_TKKAU_STR-RFLG8 sy-vline
WA_TKKAU_STR-RFLG9 sy-vline
WA_TKKAU_STR-ELZID sy-vline
WA_TKKAU_STR-SWBST sy-vline
WA_TKKAU_STR-SWRUE sy-vline
WA_TKKAU_STR-SWPRO sy-vline
WA_TKKAU_STR-SWRDV sy-vline
WA_TKKAU_STR-EMPRZ sy-vline
WA_TKKAU_STR-EMPKZ sy-vline
WA_TKKAU_STR-BWVAR sy-vline
WA_TKKAU_STR-RFLG10 sy-vline
WA_TKKAU_STR-RFLG11 sy-vline
WA_TKKAU_STR-RFLG12 sy-vline
WA_TKKAU_STR-RFLG13 sy-vline
WA_TKKAU_STR-RFLG14 sy-vline
WA_TKKAU_STR-RFLG15 sy-vline
WA_TKKAU_STR-PROFNR sy-vline
WA_TKKAU_STR-MENGE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.