ABAP Select data from SAP table /SCMB/DM_DELVRY_OV_STR 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 /SCMB/DM_DELVRY_OV_STR 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 /SCMB/DM_DELVRY_OV_STR. 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 /SCMB/DM_DELVRY_OV_STR 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_/SCMB/DM_DELVRY_OV_STR TYPE STANDARD TABLE OF /SCMB/DM_DELVRY_OV_STR,
      WA_/SCMB/DM_DELVRY_OV_STR TYPE /SCMB/DM_DELVRY_OV_STR,
      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: </SCMB/DM_DELVRY_OV_STR> TYPE /SCMB/DM_DELVRY_OV_STR.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /SCMB/DM_DELVRY_OV_STR
  INTO TABLE IT_/SCMB/DM_DELVRY_OV_STR.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /SCMB/DM_DELVRY_OV_STR
*  INTO TABLE @DATA(IT_/SCMB/DM_DELVRY_OV_STR2).
*--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_/SCMB/DM_DELVRY_OV_STR INDEX 1 INTO DATA(WA_/SCMB/DM_DELVRY_OV_STR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCMB/DM_DELVRY_OV_STR ASSIGNING </SCMB/DM_DELVRY_OV_STR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMB/DM_DELVRY_OV_STR>-GUID = 1.
</SCMB/DM_DELVRY_OV_STR>-VERSION = 1.
</SCMB/DM_DELVRY_OV_STR>-ID = 1.
</SCMB/DM_DELVRY_OV_STR>-CUSTOMER_ID = 1.
</SCMB/DM_DELVRY_OV_STR>-CREATION_DATETIME = 1.
ENDLOOP.

LOOP AT IT_/SCMB/DM_DELVRY_OV_STR INTO WA_/SCMB/DM_DELVRY_OV_STR.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCMB/DM_DELVRY_OV_STR-VALIDATION_LOG_EXCLIST, sy-vline,
WA_/SCMB/DM_DELVRY_OV_STR-INTERNAL_ID, sy-vline,
WA_/SCMB/DM_DELVRY_OV_STR-MSG_CLASS, sy-vline,
WA_/SCMB/DM_DELVRY_OV_STR-MSG_ID, sy-vline,
WA_/SCMB/DM_DELVRY_OV_STR-MSG_SEVERITY, sy-vline,
WA_/SCMB/DM_DELVRY_OV_STR-MSG_V1, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMB/DM_DELVRY_OV_STR 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_/SCMB/DM_DELVRY_OV_STR 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_/SCMB/DM_DELVRY_OV_STR INTO WA_/SCMB/DM_DELVRY_OV_STR. *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 DLVCV, internal->external for field ID CALL FUNCTION 'CONVERSION_EXIT_DLVCV_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit DLVCV, internal->external for field CUSTOMER_ID CALL FUNCTION 'CONVERSION_EXIT_DLVCV_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-CUSTOMER_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-CUSTOMER_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field CREATION_DATETIME CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-CREATION_DATETIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-CREATION_DATETIME.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SUPPLIERPARTY_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-SUPPLIERPARTY_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-SUPPLIERPARTY_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CUSTOMERPARTY_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-CUSTOMERPARTY_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-CUSTOMERPARTY_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CARRIERPARTY_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-CARRIERPARTY_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-CARRIERPARTY_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field CREATION_DATETIME CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-CREATION_DATETIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-CREATION_DATETIME.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field MODIFICATION_DATETIME CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_/SCMB/DM_DELVRY_OV_STR-MODIFICATION_DATETIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/DM_DELVRY_OV_STR-MODIFICATION_DATETIME.
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_/SCMB/DM_DELVRY_OV_STR_STR,
GUID TYPE STRING,
VERSION TYPE STRING,
ID TYPE STRING,
CUSTOMER_ID TYPE STRING,
CREATION_DATETIME TYPE STRING,
VALIDATION_LOG_EXCLIST TYPE STRING,
INTERNAL_ID TYPE STRING,
MSG_CLASS TYPE STRING,
MSG_ID TYPE STRING,
MSG_SEVERITY TYPE STRING,
MSG_V1 TYPE STRING,
MSG_V2 TYPE STRING,
MSG_V3 TYPE STRING,
MSG_V4 TYPE STRING,
ALERT_TYPE TYPE STRING,
ALERT_PRIORITY TYPE STRING,
ALERT_CREA_PRIO TYPE STRING,
NOTE TYPE STRING,
VALIDATION_IND TYPE STRING,
SHIPFROM_LOCATION_GUID TYPE STRING,
SHIPFROM_LOCATION_ID TYPE STRING,
SHIPTO_LOCATION_GUID TYPE STRING,
SHIPTO_LOCATION_ID TYPE STRING,
GOODSRECIPIENT_LOCATION_GUID TYPE STRING,
GOODSRECIPIENT_LOCATION_ID TYPE STRING,
SUPPLIERPARTY_GUID TYPE STRING,
SUPPLIERPARTY_ID TYPE STRING,
CUSTOMERPARTY_GUID TYPE STRING,
CUSTOMERPARTY_ID TYPE STRING,
GOODSRECIPIENTPARTY_GUID TYPE STRING,
CARRIERPARTY_ID TYPE STRING,
ISSUE_DATETIME TYPE STRING,
ARRIVAL_DATETIME TYPE STRING,
DATEFR TYPE STRING,
TIMEFR TYPE STRING,
TZONEFR TYPE STRING,
DATETO TYPE STRING,
TIMETO TYPE STRING,
TZONETO TYPE STRING,
NOTE_FLAG TYPE STRING,
CONTROL TYPE STRING,
CHG_MODE TYPE STRING,
CHG_MODE_TRSF TYPE STRING,
CUSTOMER_ID_AS_KEY TYPE STRING,
WAYBILL_ID_FIX TYPE STRING,
ITEM_PUBLISH TYPE STRING,
ITEM_CHANGED TYPE STRING,
OPENQTY_CALC TYPE STRING,
NO_PO_ASSIGN TYPE STRING,
ADMIN TYPE STRING,
CREATING_USER TYPE STRING,
CREATION_DATETIME TYPE STRING,
MODIFYING_USER TYPE STRING,
MODIFICATION_DATETIME TYPE STRING,
TZONE TYPE STRING,
ITEM_STATUS_VALIDATION TYPE STRING,
STATUS_TYPE TYPE STRING,
STATUS_VALUE TYPE STRING,
BOOKTST TYPE STRING,
STATUS_GLOBAL_PROCESS TYPE STRING,
STATUS_VALIDATION TYPE STRING,
STATUS_TYPE TYPE STRING,
STATUS_VALUE TYPE STRING,
BOOKTST TYPE STRING,
THIRDPARTY_IND TYPE STRING,
DISPLAY_ONLY TYPE STRING,
ACTION_CODE TYPE STRING,
PURPOSE_CODE TYPE STRING,
SHIPMENT_IND TYPE STRING,
QN_CREATE_IND TYPE STRING,
NOTE_COUNT TYPE STRING,
HU_OUT_COUNT TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMB/DM_DELVRY_OV_STR_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_/SCMB/DM_DELVRY_OV_STR_STR-GUID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-VERSION sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CUSTOMER_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CREATION_DATETIME sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-VALIDATION_LOG_EXCLIST sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-INTERNAL_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MSG_CLASS sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MSG_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MSG_SEVERITY sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MSG_V1 sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MSG_V2 sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MSG_V3 sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MSG_V4 sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ALERT_TYPE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ALERT_PRIORITY sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ALERT_CREA_PRIO sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-NOTE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-VALIDATION_IND sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-SHIPFROM_LOCATION_GUID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-SHIPFROM_LOCATION_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-SHIPTO_LOCATION_GUID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-SHIPTO_LOCATION_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-GOODSRECIPIENT_LOCATION_GUID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-GOODSRECIPIENT_LOCATION_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-SUPPLIERPARTY_GUID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-SUPPLIERPARTY_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CUSTOMERPARTY_GUID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CUSTOMERPARTY_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-GOODSRECIPIENTPARTY_GUID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CARRIERPARTY_ID sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ISSUE_DATETIME sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ARRIVAL_DATETIME sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-DATEFR sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-TIMEFR sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-TZONEFR sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-DATETO sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-TIMETO sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-TZONETO sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-NOTE_FLAG sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CONTROL sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CHG_MODE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CHG_MODE_TRSF sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CUSTOMER_ID_AS_KEY sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-WAYBILL_ID_FIX sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ITEM_PUBLISH sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ITEM_CHANGED sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-OPENQTY_CALC sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-NO_PO_ASSIGN sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ADMIN sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CREATING_USER sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-CREATION_DATETIME sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MODIFYING_USER sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-MODIFICATION_DATETIME sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-TZONE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ITEM_STATUS_VALIDATION sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-STATUS_TYPE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-STATUS_VALUE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-BOOKTST sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-STATUS_GLOBAL_PROCESS sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-STATUS_VALIDATION sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-STATUS_TYPE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-STATUS_VALUE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-BOOKTST sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-THIRDPARTY_IND sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-DISPLAY_ONLY sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-ACTION_CODE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-PURPOSE_CODE sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-SHIPMENT_IND sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-QN_CREATE_IND sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-NOTE_COUNT sy-vline
WA_/SCMB/DM_DELVRY_OV_STR_STR-HU_OUT_COUNT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.