ABAP Select data from SAP table VLCACTDATA_ITEM_S 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 VLCACTDATA_ITEM_S 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 VLCACTDATA_ITEM_S. 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 VLCACTDATA_ITEM_S 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_VLCACTDATA_ITEM_S TYPE STANDARD TABLE OF VLCACTDATA_ITEM_S, WA_VLCACTDATA_ITEM_S TYPE VLCACTDATA_ITEM_S, 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: <VLCACTDATA_ITEM_S> TYPE VLCACTDATA_ITEM_S. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_VLCACTDATA_ITEM_S. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM VLCACTDATA_ITEM_S INTO TABLE IT_VLCACTDATA_ITEM_S. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM VLCACTDATA_ITEM_S * INTO TABLE @DATA(IT_VLCACTDATA_ITEM_S2). *--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_VLCACTDATA_ITEM_S INDEX 1 INTO DATA(WA_VLCACTDATA_ITEM_S2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_VLCACTDATA_ITEM_S ASSIGNING <VLCACTDATA_ITEM_S>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<VLCACTDATA_ITEM_S>-VGUID = 1.
<VLCACTDATA_ITEM_S>-VHCLE = 1.
<VLCACTDATA_ITEM_S>-VBELN = 1.
<VLCACTDATA_ITEM_S>-EINDT_CHANGED = 1.
<VLCACTDATA_ITEM_S>-LPEIN = 1.
ENDLOOP. LOOP AT IT_VLCACTDATA_ITEM_S INTO WA_VLCACTDATA_ITEM_S. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_VLCACTDATA_ITEM_S-CUOBJ, sy-vline,
WA_VLCACTDATA_ITEM_S-PO_NUMBER, sy-vline,
WA_VLCACTDATA_ITEM_S-PO_ITEM, sy-vline,
WA_VLCACTDATA_ITEM_S-REF_DOC, sy-vline,
WA_VLCACTDATA_ITEM_S-REF_DOC_YEAR, sy-vline,
WA_VLCACTDATA_ITEM_S-REF_DOC_IT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_VLCACTDATA_ITEM_S 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_VLCACTDATA_ITEM_S 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_VLCACTDATA_ITEM_S INTO WA_VLCACTDATA_ITEM_S. *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 VBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-VBELN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PO_NUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-PO_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-PO_NUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REF_DOC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-REF_DOC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-REF_DOC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field REF_DOC_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-REF_DOC_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-REF_DOC_YEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-LBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-LBELN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field CSTRYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-CSTRYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-CSTRYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ENDCU CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-ENDCU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-ENDCU.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field PCOUNT_U CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-PCOUNT_U IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-PCOUNT_U.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VHORD CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-VHORD IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-VHORD.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field EQUNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-EQUNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-EQUNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MSEQUI CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-MSEQUI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-MSEQUI.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MGANR1 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-MGANR1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-MGANR1.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MGANR2 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-MGANR2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-MGANR2.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AUFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-AUFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-AUFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field QMNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-QMNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-QMNUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VBELN_SM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-VBELN_SM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-VBELN_SM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KDAUF CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VLCACTDATA_ITEM_S-KDAUF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VLCACTDATA_ITEM_S-KDAUF.
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_VLCACTDATA_ITEM_S_STR,
VGUID TYPE STRING,
VHCLE TYPE STRING,
VBELN TYPE STRING,
EINDT_CHANGED TYPE STRING,
LPEIN TYPE STRING,
CUOBJ TYPE STRING,
PO_NUMBER TYPE STRING,
PO_ITEM TYPE STRING,
REF_DOC TYPE STRING,
REF_DOC_YEAR TYPE STRING,
REF_DOC_IT TYPE STRING,
ITEM_AMOUNT TYPE STRING,
ITEM_CURRENCY TYPE STRING,
BUZEI TYPE STRING,
NETPR TYPE STRING,
MATNR TYPE STRING,
BWTAR TYPE STRING,
VALUE TYPE STRING,
VALUE_WAERS TYPE STRING,
RVALUE TYPE STRING,
RVALUE_WAERS TYPE STRING,
ANGDT TYPE STRING,
BNDDT TYPE STRING,
POSNR TYPE STRING,
RESTSTMP TYPE STRING,
RESDATTO TYPE STRING,
RESDATFROM TYPE STRING,
LBELN TYPE STRING,
NETPR_SD TYPE STRING,
NETWR TYPE STRING,
WAERK TYPE STRING,
ABGRU TYPE STRING,
WERKS TYPE STRING,
WERKS_BEZ TYPE STRING,
TRGUID TYPE STRING,
TRANSSTAT TYPE STRING,
TRANSSTATT TYPE STRING,
TRDATE TYPE STRING,
TRTIME TYPE STRING,
PDDATU TYPE STRING,
PSDATU TYPE STRING,
CDATE TYPE STRING,
CSTRYEAR TYPE STRING,
CSTRMONTH TYPE STRING,
FILENAME TYPE STRING,
ENDCU TYPE STRING,
ENDCU_NAME TYPE STRING,
LOCTNTXT TYPE STRING,
VHVIN TYPE STRING,
VHCEX TYPE STRING,
AVAIL TYPE STRING,
VBLTY TYPE STRING,
LOCTN TYPE STRING,
GPRICE TYPE STRING,
GPRICECUKY TYPE STRING,
CDTSP TYPE STRING,
PSTSP TYPE STRING,
PDTSP TYPE STRING,
ERNAM TYPE STRING,
VHUSG TYPE STRING,
CMPGN TYPE STRING,
PCOUNT TYPE STRING,
PCOUNT_U TYPE STRING,
IMMATDATE TYPE STRING,
VHSAR TYPE STRING,
VHORD TYPE STRING,
SHLVL TYPE STRING,
ARCHIVE_FLAG TYPE STRING,
USED_VEHICLE TYPE STRING,
RESPRICE TYPE STRING,
RESCUKEY TYPE STRING,
AKNCAT TYPE STRING,
EQUNR TYPE STRING,
MSEQUI TYPE STRING,
MGANR1 TYPE STRING,
GWLDT1 TYPE STRING,
MGANR2 TYPE STRING,
GWLDT2 TYPE STRING,
VAPLZ TYPE STRING,
AUFNR TYPE STRING,
QMNUM TYPE STRING,
AUFART_SM TYPE STRING,
IWERK_SM TYPE STRING,
VAWRK_SM TYPE STRING,
QMART TYPE STRING,
KTEXT TYPE STRING,
PRSDT TYPE STRING,
BUDAT TYPE STRING,
VBELN_SM TYPE STRING,
OPR_CONTAINER TYPE STRING,
KLASSE_SM TYPE STRING,
KDAUF TYPE STRING,
KDPOS TYPE STRING,
LGORT_PREV TYPE STRING,
EXBWR TYPE STRING,
PREV_VHCLE TYPE STRING,END OF T_EKKO_STR. DATA: WA_VLCACTDATA_ITEM_S_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_VLCACTDATA_ITEM_S_STR-VGUID sy-vline
WA_VLCACTDATA_ITEM_S_STR-VHCLE sy-vline
WA_VLCACTDATA_ITEM_S_STR-VBELN sy-vline
WA_VLCACTDATA_ITEM_S_STR-EINDT_CHANGED sy-vline
WA_VLCACTDATA_ITEM_S_STR-LPEIN sy-vline
WA_VLCACTDATA_ITEM_S_STR-CUOBJ sy-vline
WA_VLCACTDATA_ITEM_S_STR-PO_NUMBER sy-vline
WA_VLCACTDATA_ITEM_S_STR-PO_ITEM sy-vline
WA_VLCACTDATA_ITEM_S_STR-REF_DOC sy-vline
WA_VLCACTDATA_ITEM_S_STR-REF_DOC_YEAR sy-vline
WA_VLCACTDATA_ITEM_S_STR-REF_DOC_IT sy-vline
WA_VLCACTDATA_ITEM_S_STR-ITEM_AMOUNT sy-vline
WA_VLCACTDATA_ITEM_S_STR-ITEM_CURRENCY sy-vline
WA_VLCACTDATA_ITEM_S_STR-BUZEI sy-vline
WA_VLCACTDATA_ITEM_S_STR-NETPR sy-vline
WA_VLCACTDATA_ITEM_S_STR-MATNR sy-vline
WA_VLCACTDATA_ITEM_S_STR-BWTAR sy-vline
WA_VLCACTDATA_ITEM_S_STR-VALUE sy-vline
WA_VLCACTDATA_ITEM_S_STR-VALUE_WAERS sy-vline
WA_VLCACTDATA_ITEM_S_STR-RVALUE sy-vline
WA_VLCACTDATA_ITEM_S_STR-RVALUE_WAERS sy-vline
WA_VLCACTDATA_ITEM_S_STR-ANGDT sy-vline
WA_VLCACTDATA_ITEM_S_STR-BNDDT sy-vline
WA_VLCACTDATA_ITEM_S_STR-POSNR sy-vline
WA_VLCACTDATA_ITEM_S_STR-RESTSTMP sy-vline
WA_VLCACTDATA_ITEM_S_STR-RESDATTO sy-vline
WA_VLCACTDATA_ITEM_S_STR-RESDATFROM sy-vline
WA_VLCACTDATA_ITEM_S_STR-LBELN sy-vline
WA_VLCACTDATA_ITEM_S_STR-NETPR_SD sy-vline
WA_VLCACTDATA_ITEM_S_STR-NETWR sy-vline
WA_VLCACTDATA_ITEM_S_STR-WAERK sy-vline
WA_VLCACTDATA_ITEM_S_STR-ABGRU sy-vline
WA_VLCACTDATA_ITEM_S_STR-WERKS sy-vline
WA_VLCACTDATA_ITEM_S_STR-WERKS_BEZ sy-vline
WA_VLCACTDATA_ITEM_S_STR-TRGUID sy-vline
WA_VLCACTDATA_ITEM_S_STR-TRANSSTAT sy-vline
WA_VLCACTDATA_ITEM_S_STR-TRANSSTATT sy-vline
WA_VLCACTDATA_ITEM_S_STR-TRDATE sy-vline
WA_VLCACTDATA_ITEM_S_STR-TRTIME sy-vline
WA_VLCACTDATA_ITEM_S_STR-PDDATU sy-vline
WA_VLCACTDATA_ITEM_S_STR-PSDATU sy-vline
WA_VLCACTDATA_ITEM_S_STR-CDATE sy-vline
WA_VLCACTDATA_ITEM_S_STR-CSTRYEAR sy-vline
WA_VLCACTDATA_ITEM_S_STR-CSTRMONTH sy-vline
WA_VLCACTDATA_ITEM_S_STR-FILENAME sy-vline
WA_VLCACTDATA_ITEM_S_STR-ENDCU sy-vline
WA_VLCACTDATA_ITEM_S_STR-ENDCU_NAME sy-vline
WA_VLCACTDATA_ITEM_S_STR-LOCTNTXT sy-vline
WA_VLCACTDATA_ITEM_S_STR-VHVIN sy-vline
WA_VLCACTDATA_ITEM_S_STR-VHCEX sy-vline
WA_VLCACTDATA_ITEM_S_STR-AVAIL sy-vline
WA_VLCACTDATA_ITEM_S_STR-VBLTY sy-vline
WA_VLCACTDATA_ITEM_S_STR-LOCTN sy-vline
WA_VLCACTDATA_ITEM_S_STR-GPRICE sy-vline
WA_VLCACTDATA_ITEM_S_STR-GPRICECUKY sy-vline
WA_VLCACTDATA_ITEM_S_STR-CDTSP sy-vline
WA_VLCACTDATA_ITEM_S_STR-PSTSP sy-vline
WA_VLCACTDATA_ITEM_S_STR-PDTSP sy-vline
WA_VLCACTDATA_ITEM_S_STR-ERNAM sy-vline
WA_VLCACTDATA_ITEM_S_STR-VHUSG sy-vline
WA_VLCACTDATA_ITEM_S_STR-CMPGN sy-vline
WA_VLCACTDATA_ITEM_S_STR-PCOUNT sy-vline
WA_VLCACTDATA_ITEM_S_STR-PCOUNT_U sy-vline
WA_VLCACTDATA_ITEM_S_STR-IMMATDATE sy-vline
WA_VLCACTDATA_ITEM_S_STR-VHSAR sy-vline
WA_VLCACTDATA_ITEM_S_STR-VHORD sy-vline
WA_VLCACTDATA_ITEM_S_STR-SHLVL sy-vline
WA_VLCACTDATA_ITEM_S_STR-ARCHIVE_FLAG sy-vline
WA_VLCACTDATA_ITEM_S_STR-USED_VEHICLE sy-vline
WA_VLCACTDATA_ITEM_S_STR-RESPRICE sy-vline
WA_VLCACTDATA_ITEM_S_STR-RESCUKEY sy-vline
WA_VLCACTDATA_ITEM_S_STR-AKNCAT sy-vline
WA_VLCACTDATA_ITEM_S_STR-EQUNR sy-vline
WA_VLCACTDATA_ITEM_S_STR-MSEQUI sy-vline
WA_VLCACTDATA_ITEM_S_STR-MGANR1 sy-vline
WA_VLCACTDATA_ITEM_S_STR-GWLDT1 sy-vline
WA_VLCACTDATA_ITEM_S_STR-MGANR2 sy-vline
WA_VLCACTDATA_ITEM_S_STR-GWLDT2 sy-vline
WA_VLCACTDATA_ITEM_S_STR-VAPLZ sy-vline
WA_VLCACTDATA_ITEM_S_STR-AUFNR sy-vline
WA_VLCACTDATA_ITEM_S_STR-QMNUM sy-vline
WA_VLCACTDATA_ITEM_S_STR-AUFART_SM sy-vline
WA_VLCACTDATA_ITEM_S_STR-IWERK_SM sy-vline
WA_VLCACTDATA_ITEM_S_STR-VAWRK_SM sy-vline
WA_VLCACTDATA_ITEM_S_STR-QMART sy-vline
WA_VLCACTDATA_ITEM_S_STR-KTEXT sy-vline
WA_VLCACTDATA_ITEM_S_STR-PRSDT sy-vline
WA_VLCACTDATA_ITEM_S_STR-BUDAT sy-vline
WA_VLCACTDATA_ITEM_S_STR-VBELN_SM sy-vline
WA_VLCACTDATA_ITEM_S_STR-OPR_CONTAINER sy-vline
WA_VLCACTDATA_ITEM_S_STR-KLASSE_SM sy-vline
WA_VLCACTDATA_ITEM_S_STR-KDAUF sy-vline
WA_VLCACTDATA_ITEM_S_STR-KDPOS sy-vline
WA_VLCACTDATA_ITEM_S_STR-LGORT_PREV sy-vline
WA_VLCACTDATA_ITEM_S_STR-EXBWR sy-vline
WA_VLCACTDATA_ITEM_S_STR-PREV_VHCLE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.