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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCMB/STOP ASSIGNING </SCMB/STOP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMB/STOP>-MANDT = 1.
</SCMB/STOP>-GUID_LEG = 1.
</SCMB/STOP>-SEQ_NUM = 1.
</SCMB/STOP>-GUID_SPOT = 1.
</SCMB/STOP>-TYPE_SPOT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCMB/STOP-GUID_ROUTE, sy-vline,
WA_/SCMB/STOP-PICK_DROP, sy-vline,
WA_/SCMB/STOP-WGT_MIN_SINGLE, sy-vline,
WA_/SCMB/STOP-WGT_MAX_SINGLE, sy-vline,
WA_/SCMB/STOP-WGT_MIN_TOTAL, sy-vline,
WA_/SCMB/STOP-WGT_MAX_TOTAL, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMB/STOP 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/STOP 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/STOP INTO WA_/SCMB/STOP. *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 CUNIT, internal->external for field WGTUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCMB/STOP-WGTUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-WGTUOM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field VOLUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCMB/STOP-VOLUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-VOLUOM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTRN, internal->external for field TRANSP_TIME CALL FUNCTION 'CONVERSION_EXIT_TSTRN_OUTPUT' EXPORTING input = WA_/SCMB/STOP-TRANSP_TIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-TRANSP_TIME.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTRN, internal->external for field LENGTH_STAY CALL FUNCTION 'CONVERSION_EXIT_TSTRN_OUTPUT' EXPORTING input = WA_/SCMB/STOP-LENGTH_STAY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-LENGTH_STAY.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTRN, internal->external for field MIN_WAIT_DEPT CALL FUNCTION 'CONVERSION_EXIT_TSTRN_OUTPUT' EXPORTING input = WA_/SCMB/STOP-MIN_WAIT_DEPT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-MIN_WAIT_DEPT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTRN, internal->external for field MAX_WAIT_DEPT CALL FUNCTION 'CONVERSION_EXIT_TSTRN_OUTPUT' EXPORTING input = WA_/SCMB/STOP-MAX_WAIT_DEPT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-MAX_WAIT_DEPT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTRN, internal->external for field MIN_WAIT_ARRV CALL FUNCTION 'CONVERSION_EXIT_TSTRN_OUTPUT' EXPORTING input = WA_/SCMB/STOP-MIN_WAIT_ARRV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-MIN_WAIT_ARRV.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTRN, internal->external for field MAX_WAIT_ARRV CALL FUNCTION 'CONVERSION_EXIT_TSTRN_OUTPUT' EXPORTING input = WA_/SCMB/STOP-MAX_WAIT_ARRV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/STOP-MAX_WAIT_ARRV.
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/STOP_STR,
MANDT TYPE STRING,
GUID_LEG TYPE STRING,
SEQ_NUM TYPE STRING,
GUID_SPOT TYPE STRING,
TYPE_SPOT TYPE STRING,
GUID_ROUTE TYPE STRING,
PICK_DROP TYPE STRING,
WGT_MIN_SINGLE TYPE STRING,
WGT_MAX_SINGLE TYPE STRING,
WGT_MIN_TOTAL TYPE STRING,
WGT_MAX_TOTAL TYPE STRING,
WGTUOM TYPE STRING,
VOL_MIN_SINGLE TYPE STRING,
VOL_MAX_SINGLE TYPE STRING,
VOL_MIN_TOTAL TYPE STRING,
VOL_MAX_TOTAL TYPE STRING,
VOLUOM TYPE STRING,
GTS_MOT_OUT TYPE STRING,
GTS_EXPORT TYPE STRING,
VISIT_RULE TYPE STRING,
TRANSP_TIME TYPE STRING,
LENGTH_STAY TYPE STRING,
MIN_WAIT_DEPT TYPE STRING,
MAX_WAIT_DEPT TYPE STRING,
X_WAIT_DEPT TYPE STRING,
MIN_WAIT_ARRV TYPE STRING,
MAX_WAIT_ARRV TYPE STRING,
X_WAIT_ARRV TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMB/STOP_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/STOP_STR-MANDT sy-vline
WA_/SCMB/STOP_STR-GUID_LEG sy-vline
WA_/SCMB/STOP_STR-SEQ_NUM sy-vline
WA_/SCMB/STOP_STR-GUID_SPOT sy-vline
WA_/SCMB/STOP_STR-TYPE_SPOT sy-vline
WA_/SCMB/STOP_STR-GUID_ROUTE sy-vline
WA_/SCMB/STOP_STR-PICK_DROP sy-vline
WA_/SCMB/STOP_STR-WGT_MIN_SINGLE sy-vline
WA_/SCMB/STOP_STR-WGT_MAX_SINGLE sy-vline
WA_/SCMB/STOP_STR-WGT_MIN_TOTAL sy-vline
WA_/SCMB/STOP_STR-WGT_MAX_TOTAL sy-vline
WA_/SCMB/STOP_STR-WGTUOM sy-vline
WA_/SCMB/STOP_STR-VOL_MIN_SINGLE sy-vline
WA_/SCMB/STOP_STR-VOL_MAX_SINGLE sy-vline
WA_/SCMB/STOP_STR-VOL_MIN_TOTAL sy-vline
WA_/SCMB/STOP_STR-VOL_MAX_TOTAL sy-vline
WA_/SCMB/STOP_STR-VOLUOM sy-vline
WA_/SCMB/STOP_STR-GTS_MOT_OUT sy-vline
WA_/SCMB/STOP_STR-GTS_EXPORT sy-vline
WA_/SCMB/STOP_STR-VISIT_RULE sy-vline
WA_/SCMB/STOP_STR-TRANSP_TIME sy-vline
WA_/SCMB/STOP_STR-LENGTH_STAY sy-vline
WA_/SCMB/STOP_STR-MIN_WAIT_DEPT sy-vline
WA_/SCMB/STOP_STR-MAX_WAIT_DEPT sy-vline
WA_/SCMB/STOP_STR-X_WAIT_DEPT sy-vline
WA_/SCMB/STOP_STR-MIN_WAIT_ARRV sy-vline
WA_/SCMB/STOP_STR-MAX_WAIT_ARRV sy-vline
WA_/SCMB/STOP_STR-X_WAIT_ARRV sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.