ABAP Select data from SAP table DRE_DELIVERY_HEADER_STS 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 DRE_DELIVERY_HEADER_STS 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 DRE_DELIVERY_HEADER_STS. 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 DRE_DELIVERY_HEADER_STS 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_DRE_DELIVERY_HEADER_STS TYPE STANDARD TABLE OF DRE_DELIVERY_HEADER_STS,
      WA_DRE_DELIVERY_HEADER_STS TYPE DRE_DELIVERY_HEADER_STS,
      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: <DRE_DELIVERY_HEADER_STS> TYPE DRE_DELIVERY_HEADER_STS.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_DRE_DELIVERY_HEADER_STS.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM DRE_DELIVERY_HEADER_STS
  INTO TABLE IT_DRE_DELIVERY_HEADER_STS.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM DRE_DELIVERY_HEADER_STS
*  INTO TABLE @DATA(IT_DRE_DELIVERY_HEADER_STS2).
*--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_DRE_DELIVERY_HEADER_STS INDEX 1 INTO DATA(WA_DRE_DELIVERY_HEADER_STS2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_DRE_DELIVERY_HEADER_STS ASSIGNING <DRE_DELIVERY_HEADER_STS>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<DRE_DELIVERY_HEADER_STS>-MANDT = 1.
<DRE_DELIVERY_HEADER_STS>-VBELN = 1.
<DRE_DELIVERY_HEADER_STS>-RFSTK = 1.
<DRE_DELIVERY_HEADER_STS>-RFGSK = 1.
<DRE_DELIVERY_HEADER_STS>-BESTK = 1.
ENDLOOP.

LOOP AT IT_DRE_DELIVERY_HEADER_STS INTO WA_DRE_DELIVERY_HEADER_STS.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_DRE_DELIVERY_HEADER_STS-LFSTK, sy-vline,
WA_DRE_DELIVERY_HEADER_STS-LFGSK, sy-vline,
WA_DRE_DELIVERY_HEADER_STS-WBSTK, sy-vline,
WA_DRE_DELIVERY_HEADER_STS-FKSTK, sy-vline,
WA_DRE_DELIVERY_HEADER_STS-FKSAK, sy-vline,
WA_DRE_DELIVERY_HEADER_STS-BUCHK, sy-vline.
ENDLOOP. *Add any further fields from structure WA_DRE_DELIVERY_HEADER_STS 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_DRE_DELIVERY_HEADER_STS 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_DRE_DELIVERY_HEADER_STS INTO WA_DRE_DELIVERY_HEADER_STS. *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_DRE_DELIVERY_HEADER_STS-VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DRE_DELIVERY_HEADER_STS-VBELN.
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_DRE_DELIVERY_HEADER_STS_STR,
MANDT TYPE STRING,
VBELN TYPE STRING,
RFSTK TYPE STRING,
RFGSK TYPE STRING,
BESTK TYPE STRING,
LFSTK TYPE STRING,
LFGSK TYPE STRING,
WBSTK TYPE STRING,
FKSTK TYPE STRING,
FKSAK TYPE STRING,
BUCHK TYPE STRING,
ABSTK TYPE STRING,
GBSTK TYPE STRING,
KOSTK TYPE STRING,
LVSTK TYPE STRING,
UVALS TYPE STRING,
UVVLS TYPE STRING,
UVFAS TYPE STRING,
UVALL TYPE STRING,
UVVLK TYPE STRING,
UVFAK TYPE STRING,
UVPRS TYPE STRING,
VBTYP TYPE STRING,
VBOBJ TYPE STRING,
AEDAT TYPE STRING,
FKIVK TYPE STRING,
RELIK TYPE STRING,
UVK01 TYPE STRING,
UVK02 TYPE STRING,
UVK03 TYPE STRING,
UVK04 TYPE STRING,
UVK05 TYPE STRING,
UVS01 TYPE STRING,
UVS02 TYPE STRING,
UVS03 TYPE STRING,
UVS04 TYPE STRING,
UVS05 TYPE STRING,
PKSTK TYPE STRING,
CMPSA TYPE STRING,
CMPSB TYPE STRING,
CMPSC TYPE STRING,
CMPSD TYPE STRING,
CMPSE TYPE STRING,
CMPSF TYPE STRING,
CMPSG TYPE STRING,
CMPSH TYPE STRING,
CMPSI TYPE STRING,
CMPSJ TYPE STRING,
CMPSK TYPE STRING,
CMPSL TYPE STRING,
CMPS0 TYPE STRING,
CMPS1 TYPE STRING,
CMPS2 TYPE STRING,
CMGST TYPE STRING,
TRSTA TYPE STRING,
KOQUK TYPE STRING,
COSTA TYPE STRING,
SAPRL TYPE STRING,
UVPAS TYPE STRING,
UVPIS TYPE STRING,
UVWAS TYPE STRING,
UVPAK TYPE STRING,
UVPIK TYPE STRING,
UVWAK TYPE STRING,
UVGEK TYPE STRING,
CMPSM TYPE STRING,
DCSTK TYPE STRING,
VESTK TYPE STRING,
VLSTK TYPE STRING,
RRSTA TYPE STRING,
BLOCK TYPE STRING,
FSSTK TYPE STRING,
LSSTK TYPE STRING,
SPSTG TYPE STRING,
PDSTK TYPE STRING,
FMSTK TYPE STRING,
MANEK TYPE STRING,
SPE_TMPID TYPE STRING,
HDALL TYPE STRING,
HDALS TYPE STRING,
VBTYP_LONG TYPE STRING,END OF T_EKKO_STR. DATA: WA_DRE_DELIVERY_HEADER_STS_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_DRE_DELIVERY_HEADER_STS_STR-MANDT sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-VBELN sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-RFSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-RFGSK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-BESTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-LFSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-LFGSK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-WBSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-FKSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-FKSAK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-BUCHK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-ABSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-GBSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-KOSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-LVSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVALS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVVLS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVFAS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVALL sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVVLK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVFAK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVPRS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-VBTYP sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-VBOBJ sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-AEDAT sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-FKIVK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-RELIK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVK01 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVK02 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVK03 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVK04 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVK05 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVS01 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVS02 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVS03 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVS04 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVS05 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-PKSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSA sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSB sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSC sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSD sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSE sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSF sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSG sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSH sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSI sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSJ sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSL sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPS0 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPS1 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPS2 sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMGST sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-TRSTA sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-KOQUK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-COSTA sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-SAPRL sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVPAS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVPIS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVWAS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVPAK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVPIK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVWAK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-UVGEK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-CMPSM sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-DCSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-VESTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-VLSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-RRSTA sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-BLOCK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-FSSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-LSSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-SPSTG sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-PDSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-FMSTK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-MANEK sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-SPE_TMPID sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-HDALL sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-HDALS sy-vline
WA_DRE_DELIVERY_HEADER_STS_STR-VBTYP_LONG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.