ABAP Select data from SAP table J_7LKRK3 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 J_7LKRK3 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 J_7LKRK3. 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 J_7LKRK3 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_J_7LKRK3 TYPE STANDARD TABLE OF J_7LKRK3, WA_J_7LKRK3 TYPE J_7LKRK3, 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: <J_7LKRK3> TYPE J_7LKRK3. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_J_7LKRK3. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM J_7LKRK3 INTO TABLE IT_J_7LKRK3. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM J_7LKRK3 * INTO TABLE @DATA(IT_J_7LKRK32). *--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_J_7LKRK3 INDEX 1 INTO DATA(WA_J_7LKRK32). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_J_7LKRK3 ASSIGNING <J_7LKRK3>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<J_7LKRK3>-AUART = 1.
<J_7LKRK3>-FKART = 1.
<J_7LKRK3>-AUARTG = 1.
<J_7LKRK3>-AUARTL = 1.
<J_7LKRK3>-FKARTG = 1.
ENDLOOP. LOOP AT IT_J_7LKRK3 INTO WA_J_7LKRK3. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_J_7LKRK3-FKARTL, sy-vline,
WA_J_7LKRK3-KSCHL, sy-vline,
WA_J_7LKRK3-BUKRS, sy-vline,
WA_J_7LKRK3-KSCHLC, sy-vline,
WA_J_7LKRK3-LAND1, sy-vline,
WA_J_7LKRK3-MATNR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_J_7LKRK3 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_J_7LKRK3 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_J_7LKRK3 INTO WA_J_7LKRK3. *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 AUART, internal->external for field AUART CALL FUNCTION 'CONVERSION_EXIT_AUART_OUTPUT' EXPORTING input = WA_J_7LKRK3-AUART IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-AUART.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AUART, internal->external for field AUARTG CALL FUNCTION 'CONVERSION_EXIT_AUART_OUTPUT' EXPORTING input = WA_J_7LKRK3-AUARTG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-AUARTG.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AUART, internal->external for field AUARTL CALL FUNCTION 'CONVERSION_EXIT_AUART_OUTPUT' EXPORTING input = WA_J_7LKRK3-AUARTL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-AUARTL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_J_7LKRK3-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_J_7LKRK3-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-KUNNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field GJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_J_7LKRK3-GJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-GJAHR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_J_7LKRK3-MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-MEINS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_J_7LKRK3-VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-VBELN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_J_7LKRK3-FBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-FBELN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field BELNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_J_7LKRK3-BELNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-BELNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field GJAHR_BL CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_J_7LKRK3-GJAHR_BL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-GJAHR_BL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit SPDEV, internal->external for field PDEST CALL FUNCTION 'CONVERSION_EXIT_SPDEV_OUTPUT' EXPORTING input = WA_J_7LKRK3-PDEST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_J_7LKRK3-PDEST.
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_J_7LKRK3_STR,
AUART TYPE STRING,
FKART TYPE STRING,
AUARTG TYPE STRING,
AUARTL TYPE STRING,
FKARTG TYPE STRING,
FKARTL TYPE STRING,
KSCHL TYPE STRING,
BUKRS TYPE STRING,
KSCHLC TYPE STRING,
LAND1 TYPE STRING,
MATNR TYPE STRING,
VKORG TYPE STRING,
VTWEG TYPE STRING,
SPART TYPE STRING,
WERKS TYPE STRING,
KUNNR TYPE STRING,
MONAT TYPE STRING,
GJAHR TYPE STRING,
BUDAT TYPE STRING,
KAWRT_K TYPE STRING,
KWERT_K TYPE STRING,
KWERT_B TYPE STRING,
KWERT_C TYPE STRING,
WAERS TYPE STRING,
NETWR TYPE STRING,
WAERK TYPE STRING,
KLMENG TYPE STRING,
MEINS TYPE STRING,
KSCHLX TYPE STRING,
AUTOX TYPE STRING,
AUTOV TYPE STRING,
AUTOF TYPE STRING,
MODUSX TYPE STRING,
VBELN TYPE STRING,
FBELN TYPE STRING,
BELNR TYPE STRING,
GJAHR_BL TYPE STRING,
PVARIANT TYPE STRING,
PRINTX TYPE STRING,
PDEST TYPE STRING,
SORTN TYPE STRING,
DEFKEY TYPE STRING,END OF T_EKKO_STR. DATA: WA_J_7LKRK3_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_J_7LKRK3_STR-AUART sy-vline
WA_J_7LKRK3_STR-FKART sy-vline
WA_J_7LKRK3_STR-AUARTG sy-vline
WA_J_7LKRK3_STR-AUARTL sy-vline
WA_J_7LKRK3_STR-FKARTG sy-vline
WA_J_7LKRK3_STR-FKARTL sy-vline
WA_J_7LKRK3_STR-KSCHL sy-vline
WA_J_7LKRK3_STR-BUKRS sy-vline
WA_J_7LKRK3_STR-KSCHLC sy-vline
WA_J_7LKRK3_STR-LAND1 sy-vline
WA_J_7LKRK3_STR-MATNR sy-vline
WA_J_7LKRK3_STR-VKORG sy-vline
WA_J_7LKRK3_STR-VTWEG sy-vline
WA_J_7LKRK3_STR-SPART sy-vline
WA_J_7LKRK3_STR-WERKS sy-vline
WA_J_7LKRK3_STR-KUNNR sy-vline
WA_J_7LKRK3_STR-MONAT sy-vline
WA_J_7LKRK3_STR-GJAHR sy-vline
WA_J_7LKRK3_STR-BUDAT sy-vline
WA_J_7LKRK3_STR-KAWRT_K sy-vline
WA_J_7LKRK3_STR-KWERT_K sy-vline
WA_J_7LKRK3_STR-KWERT_B sy-vline
WA_J_7LKRK3_STR-KWERT_C sy-vline
WA_J_7LKRK3_STR-WAERS sy-vline
WA_J_7LKRK3_STR-NETWR sy-vline
WA_J_7LKRK3_STR-WAERK sy-vline
WA_J_7LKRK3_STR-KLMENG sy-vline
WA_J_7LKRK3_STR-MEINS sy-vline
WA_J_7LKRK3_STR-KSCHLX sy-vline
WA_J_7LKRK3_STR-AUTOX sy-vline
WA_J_7LKRK3_STR-AUTOV sy-vline
WA_J_7LKRK3_STR-AUTOF sy-vline
WA_J_7LKRK3_STR-MODUSX sy-vline
WA_J_7LKRK3_STR-VBELN sy-vline
WA_J_7LKRK3_STR-FBELN sy-vline
WA_J_7LKRK3_STR-BELNR sy-vline
WA_J_7LKRK3_STR-GJAHR_BL sy-vline
WA_J_7LKRK3_STR-PVARIANT sy-vline
WA_J_7LKRK3_STR-PRINTX sy-vline
WA_J_7LKRK3_STR-PDEST sy-vline
WA_J_7LKRK3_STR-SORTN sy-vline
WA_J_7LKRK3_STR-DEFKEY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.