ABAP Select data from SAP table LXHME_LDVDT 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 LXHME_LDVDT 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 LXHME_LDVDT. 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 LXHME_LDVDT 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_LXHME_LDVDT TYPE STANDARD TABLE OF LXHME_LDVDT, WA_LXHME_LDVDT TYPE LXHME_LDVDT, 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: <LXHME_LDVDT> TYPE LXHME_LDVDT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_LXHME_LDVDT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM LXHME_LDVDT INTO TABLE IT_LXHME_LDVDT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM LXHME_LDVDT * INTO TABLE @DATA(IT_LXHME_LDVDT2). *--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_LXHME_LDVDT INDEX 1 INTO DATA(WA_LXHME_LDVDT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_LXHME_LDVDT ASSIGNING <LXHME_LDVDT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<LXHME_LDVDT>-LGNUM = 1.
<LXHME_LDVDT>-DOCTY = 1.
<LXHME_LDVDT>-DOCNR = 1.
<LXHME_LDVDT>-DOCPR = 1.
<LXHME_LDVDT>-TKNUM = 1.
ENDLOOP. LOOP AT IT_LXHME_LDVDT INTO WA_LXHME_LDVDT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_LXHME_LDVDT-ROUTE, sy-vline,
WA_LXHME_LDVDT-LGTOR, sy-vline,
WA_LXHME_LDVDT-LGBZO, sy-vline,
WA_LXHME_LDVDT-SPDNR, sy-vline,
WA_LXHME_LDVDT-NAME_SP, sy-vline,
WA_LXHME_LDVDT-XPLDT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_LXHME_LDVDT 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_LXHME_LDVDT 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_LXHME_LDVDT INTO WA_LXHME_LDVDT. *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 DOCNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-DOCNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-DOCNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field TKNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-TKNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-TKNUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SPDNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-SPDNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-SPDNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field XPLDT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-XPLDT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-XPLDT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field SHPDT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-SHPDT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-SHPDT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field RLSDT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-RLSDT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-RLSDT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field MTCDT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-MTCDT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-MTCDT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field KODAT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-KODAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-KODAT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field LDDAT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-LDDAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-LDDAT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field TDDAT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-TDDAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-TDDAT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field WADAT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-WADAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-WADAT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSHME, internal->external for field LFDAT CALL FUNCTION 'CONVERSION_EXIT_TSHME_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-LFDAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-LFDAT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field TERNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-TERNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-TERNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNAG CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-KUNAG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-KUNAG.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-KUNNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LIFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-LIFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-LIFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field BENUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-BENUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-BENUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field GRPNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-GRPNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-GRPNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PWLIF CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-PWLIF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-PWLIF.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-MEINS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field VRKME CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-VRKME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-VRKME.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SONUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-SONUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-SONUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AKTNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-AKTNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-AKTNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field GEWEI CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-GEWEI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-GEWEI.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field VOLEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-VOLEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-VOLEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field LDUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-LDUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-LDUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field RMATP CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_LXHME_LDVDT-RMATP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_LXHME_LDVDT-RMATP.
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_LXHME_LDVDT_STR,
LGNUM TYPE STRING,
DOCTY TYPE STRING,
DOCNR TYPE STRING,
DOCPR TYPE STRING,
TKNUM TYPE STRING,
ROUTE TYPE STRING,
LGTOR TYPE STRING,
LGBZO TYPE STRING,
SPDNR TYPE STRING,
NAME_SP TYPE STRING,
XPLDT TYPE STRING,
SHPDT TYPE STRING,
RLSDT TYPE STRING,
MTCDT TYPE STRING,
KODAT TYPE STRING,
LDDAT TYPE STRING,
TDDAT TYPE STRING,
WADAT TYPE STRING,
LFDAT TYPE STRING,
VKORG TYPE STRING,
VTWIV TYPE STRING,
VSTEL TYPE STRING,
PRVBE TYPE STRING,
TERNR TYPE STRING,
KUNAG TYPE STRING,
KUNNR TYPE STRING,
KDGRP TYPE STRING,
AULWE TYPE STRING,
LSTEL TYPE STRING,
ABLAD TYPE STRING,
VSART TYPE STRING,
GMSTS TYPE STRING,
VSBED TYPE STRING,
LIFNR TYPE STRING,
LIFEX TYPE STRING,
BETYP TYPE STRING,
BENUM TYPE STRING,
LZNUM TYPE STRING,
TRAID TYPE STRING,
ITEMS TYPE STRING,
GRPNR TYPE STRING,
IMWRK TYPE STRING,
TRAGR TYPE STRING,
PWLIF TYPE STRING,
RESWK TYPE STRING,
OBJIN TYPE STRING,
LDVIN TYPE STRING,
LDVPR TYPE STRING,
BPRTN TYPE STRING,
DOCIT TYPE STRING,
MATNR TYPE STRING,
MTART TYPE STRING,
XCHAR TYPE STRING,
CHARG TYPE STRING,
WERKS TYPE STRING,
LGORT TYPE STRING,
MEINS TYPE STRING,
VRKME TYPE STRING,
LFIMG TYPE STRING,
LGMNG TYPE STRING,
PIKMG TYPE STRING,
QTYPL TYPE STRING,
BESTQ TYPE STRING,
SOBKZ TYPE STRING,
SONUM TYPE STRING,
LETY1 TYPE STRING,
VFDAT TYPE STRING,
LGTYP TYPE STRING,
LGPLA TYPE STRING,
BWLVS TYPE STRING,
BWART TYPE STRING,
AKTNR TYPE STRING,
NTGEW TYPE STRING,
GEWEI TYPE STRING,
VOLUM TYPE STRING,
VOLEH TYPE STRING,
INPRS TYPE STRING,
TUNIT TYPE STRING,
LDQTY TYPE STRING,
LDUOM TYPE STRING,
LADGR TYPE STRING,
RMATP TYPE STRING,
BERID TYPE STRING,
ABRVW TYPE STRING,
DCKEY TYPE STRING,END OF T_EKKO_STR. DATA: WA_LXHME_LDVDT_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_LXHME_LDVDT_STR-LGNUM sy-vline
WA_LXHME_LDVDT_STR-DOCTY sy-vline
WA_LXHME_LDVDT_STR-DOCNR sy-vline
WA_LXHME_LDVDT_STR-DOCPR sy-vline
WA_LXHME_LDVDT_STR-TKNUM sy-vline
WA_LXHME_LDVDT_STR-ROUTE sy-vline
WA_LXHME_LDVDT_STR-LGTOR sy-vline
WA_LXHME_LDVDT_STR-LGBZO sy-vline
WA_LXHME_LDVDT_STR-SPDNR sy-vline
WA_LXHME_LDVDT_STR-NAME_SP sy-vline
WA_LXHME_LDVDT_STR-XPLDT sy-vline
WA_LXHME_LDVDT_STR-SHPDT sy-vline
WA_LXHME_LDVDT_STR-RLSDT sy-vline
WA_LXHME_LDVDT_STR-MTCDT sy-vline
WA_LXHME_LDVDT_STR-KODAT sy-vline
WA_LXHME_LDVDT_STR-LDDAT sy-vline
WA_LXHME_LDVDT_STR-TDDAT sy-vline
WA_LXHME_LDVDT_STR-WADAT sy-vline
WA_LXHME_LDVDT_STR-LFDAT sy-vline
WA_LXHME_LDVDT_STR-VKORG sy-vline
WA_LXHME_LDVDT_STR-VTWIV sy-vline
WA_LXHME_LDVDT_STR-VSTEL sy-vline
WA_LXHME_LDVDT_STR-PRVBE sy-vline
WA_LXHME_LDVDT_STR-TERNR sy-vline
WA_LXHME_LDVDT_STR-KUNAG sy-vline
WA_LXHME_LDVDT_STR-KUNNR sy-vline
WA_LXHME_LDVDT_STR-KDGRP sy-vline
WA_LXHME_LDVDT_STR-AULWE sy-vline
WA_LXHME_LDVDT_STR-LSTEL sy-vline
WA_LXHME_LDVDT_STR-ABLAD sy-vline
WA_LXHME_LDVDT_STR-VSART sy-vline
WA_LXHME_LDVDT_STR-GMSTS sy-vline
WA_LXHME_LDVDT_STR-VSBED sy-vline
WA_LXHME_LDVDT_STR-LIFNR sy-vline
WA_LXHME_LDVDT_STR-LIFEX sy-vline
WA_LXHME_LDVDT_STR-BETYP sy-vline
WA_LXHME_LDVDT_STR-BENUM sy-vline
WA_LXHME_LDVDT_STR-LZNUM sy-vline
WA_LXHME_LDVDT_STR-TRAID sy-vline
WA_LXHME_LDVDT_STR-ITEMS sy-vline
WA_LXHME_LDVDT_STR-GRPNR sy-vline
WA_LXHME_LDVDT_STR-IMWRK sy-vline
WA_LXHME_LDVDT_STR-TRAGR sy-vline
WA_LXHME_LDVDT_STR-PWLIF sy-vline
WA_LXHME_LDVDT_STR-RESWK sy-vline
WA_LXHME_LDVDT_STR-OBJIN sy-vline
WA_LXHME_LDVDT_STR-LDVIN sy-vline
WA_LXHME_LDVDT_STR-LDVPR sy-vline
WA_LXHME_LDVDT_STR-BPRTN sy-vline
WA_LXHME_LDVDT_STR-DOCIT sy-vline
WA_LXHME_LDVDT_STR-MATNR sy-vline
WA_LXHME_LDVDT_STR-MTART sy-vline
WA_LXHME_LDVDT_STR-XCHAR sy-vline
WA_LXHME_LDVDT_STR-CHARG sy-vline
WA_LXHME_LDVDT_STR-WERKS sy-vline
WA_LXHME_LDVDT_STR-LGORT sy-vline
WA_LXHME_LDVDT_STR-MEINS sy-vline
WA_LXHME_LDVDT_STR-VRKME sy-vline
WA_LXHME_LDVDT_STR-LFIMG sy-vline
WA_LXHME_LDVDT_STR-LGMNG sy-vline
WA_LXHME_LDVDT_STR-PIKMG sy-vline
WA_LXHME_LDVDT_STR-QTYPL sy-vline
WA_LXHME_LDVDT_STR-BESTQ sy-vline
WA_LXHME_LDVDT_STR-SOBKZ sy-vline
WA_LXHME_LDVDT_STR-SONUM sy-vline
WA_LXHME_LDVDT_STR-LETY1 sy-vline
WA_LXHME_LDVDT_STR-VFDAT sy-vline
WA_LXHME_LDVDT_STR-LGTYP sy-vline
WA_LXHME_LDVDT_STR-LGPLA sy-vline
WA_LXHME_LDVDT_STR-BWLVS sy-vline
WA_LXHME_LDVDT_STR-BWART sy-vline
WA_LXHME_LDVDT_STR-AKTNR sy-vline
WA_LXHME_LDVDT_STR-NTGEW sy-vline
WA_LXHME_LDVDT_STR-GEWEI sy-vline
WA_LXHME_LDVDT_STR-VOLUM sy-vline
WA_LXHME_LDVDT_STR-VOLEH sy-vline
WA_LXHME_LDVDT_STR-INPRS sy-vline
WA_LXHME_LDVDT_STR-TUNIT sy-vline
WA_LXHME_LDVDT_STR-LDQTY sy-vline
WA_LXHME_LDVDT_STR-LDUOM sy-vline
WA_LXHME_LDVDT_STR-LADGR sy-vline
WA_LXHME_LDVDT_STR-RMATP sy-vline
WA_LXHME_LDVDT_STR-BERID sy-vline
WA_LXHME_LDVDT_STR-ABRVW sy-vline
WA_LXHME_LDVDT_STR-DCKEY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.