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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCMTMS/S_TOR_STOP_K ASSIGNING </SCMTMS/S_TOR_STOP_K>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMTMS/S_TOR_STOP_K>-KEY = 1.
</SCMTMS/S_TOR_STOP_K>-PARENT_KEY = 1.
</SCMTMS/S_TOR_STOP_K>-ROOT_KEY = 1.
</SCMTMS/S_TOR_STOP_K>-STOP_ID = 1.
</SCMTMS/S_TOR_STOP_K>-STOP_CAT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCMTMS/S_TOR_STOP_K-LOG_LOC_UUID, sy-vline,
WA_/SCMTMS/S_TOR_STOP_K-LOG_LOCID, sy-vline,
WA_/SCMTMS/S_TOR_STOP_K-LOG_LOCUN, sy-vline,
WA_/SCMTMS/S_TOR_STOP_K-LOG_LOCIATA, sy-vline,
WA_/SCMTMS/S_TOR_STOP_K-ADR_LOC_UUID, sy-vline,
WA_/SCMTMS/S_TOR_STOP_K-STOP_PARENT_KEY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMTMS/S_TOR_STOP_K 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_/SCMTMS/S_TOR_STOP_K 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_/SCMTMS/S_TOR_STOP_K INTO WA_/SCMTMS/S_TOR_STOP_K. *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 STOP_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TOR_STOP_K-STOP_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TOR_STOP_K-STOP_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ID004, internal->external for field LOG_LOC_UUID CALL FUNCTION 'CONVERSION_EXIT_ID004_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TOR_STOP_K-LOG_LOC_UUID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TOR_STOP_K-LOG_LOC_UUID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ID004, internal->external for field ADR_LOC_UUID CALL FUNCTION 'CONVERSION_EXIT_ID004_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TOR_STOP_K-ADR_LOC_UUID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TOR_STOP_K-ADR_LOC_UUID.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ID014, internal->external for field ASSGN_HRES CALL FUNCTION 'CONVERSION_EXIT_ID014_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TOR_STOP_K-ASSGN_HRES IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TOR_STOP_K-ASSGN_HRES.
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_/SCMTMS/S_TOR_STOP_K_STR,
KEY TYPE STRING,
PARENT_KEY TYPE STRING,
ROOT_KEY TYPE STRING,
STOP_ID TYPE STRING,
STOP_CAT TYPE STRING,
LOG_LOC_UUID TYPE STRING,
LOG_LOCID TYPE STRING,
LOG_LOCUN TYPE STRING,
LOG_LOCIATA TYPE STRING,
ADR_LOC_UUID TYPE STRING,
STOP_PARENT_KEY TYPE STRING,
STOP_WITH_SUBSTOPS TYPE STRING,
SUBSTOPS_KIND TYPE STRING,
NODE_HAS_ERROR TYPE STRING,
ACC_START TYPE STRING,
REQ_START TYPE STRING,
REQ_END TYPE STRING,
ACC_END TYPE STRING,
DATES_SETBY TYPE STRING,
PLAN_TRANS_TIME TYPE STRING,
STOP_ROLE TYPE STRING,
STOP_ORIGIN TYPE STRING,
STOP_SEQ_POS TYPE STRING,
STOP_CURRENT TYPE STRING,
AUTO_PLAN TYPE STRING,
SEL_TIME TYPE STRING,
APPOINTMENT_START TYPE STRING,
APPOINTMENT_END TYPE STRING,
CARR_CONF_START TYPE STRING,
CARR_CONF_END TYPE STRING,
PREPARE_START TYPE STRING,
PREPARE_END TYPE STRING,
FINALIZE_START TYPE STRING,
FINALIZE_END TYPE STRING,
PUDLV_CALC_BASE TYPE STRING,
STOP_FIX TYPE STRING,
HANDLING_EXEC TYPE STRING,
AGGR_ASSGN_START_L TYPE STRING,
AGGR_ASSGN_END_L TYPE STRING,
AGGR_ASSGN_START_C TYPE STRING,
AGGR_ASSGN_END_C TYPE STRING,
CUTOFF_CARGO TYPE STRING,
CUTOFF_DOC TYPE STRING,
CUTOFF_CUST_DOC TYPE STRING,
CUTOFF_DG_DOC TYPE STRING,
CUTOFF_DOC_SET_BY_SRVC TYPE STRING,
CUTOFF_CARR_VGM TYPE STRING,
ENTRY_PORT TYPE STRING,
EXIT_PORT TYPE STRING,
EWM_INT_REL TYPE STRING,
WH_TRANSM_STATUS TYPE STRING,
LOAD_PLAN_STATUS TYPE STRING,
WH_NEXT_REL TYPE STRING,
LOAD_POINT_ID TYPE STRING,
LOAD_POINT_UUID TYPE STRING,
ASR_INDICATOR TYPE STRING,
ASR_SOURCE TYPE STRING,
WH_CAT TYPE STRING,
WH_NUMBER TYPE STRING,
WH_DOOR TYPE STRING,
WH_DOOR_STATUS TYPE STRING,
BLK_EXEC TYPE STRING,
PREDEC_BLK_EXEC TYPE STRING,
ASSGN_STOP_KEY TYPE STRING,
ASSGN_ITEM_KEY TYPE STRING,
ASSGN_START TYPE STRING,
ASSGN_END TYPE STRING,
ASSGN_NET_DUR TYPE STRING,
ASSGN_SEQ TYPE STRING,
ASSGN_HRES TYPE STRING,
ASSGN_HRES_CONS TYPE STRING,
ASSG_CAT TYPE STRING,
ASSGN_MULTI TYPE STRING,
SCHED_STOP_KEY TYPE STRING,
SCHED_REF_INFO TYPE STRING,
SCHED_REF_DATA_STATUS TYPE STRING,
SCHED_DEP_KEY TYPE STRING,
ROUTE_STOP_KEY TYPE STRING,
ROUTE_REF_DATA_STATUS TYPE STRING,
ROUTE_ROOT_KEY TYPE STRING,
TRQ_BASED_STOP TYPE STRING,
TRQ_ACC_START TYPE STRING,
TRQ_REQ_START TYPE STRING,
TRQ_REQ_END TYPE STRING,
TRQ_ACC_END TYPE STRING,
TOR_STOP_PUDL_RULE TYPE STRING,
EEW_TOR_STOP TYPE STRING,
EARLIEST_ACT_START TYPE STRING,
EARLIEST_ACT_END TYPE STRING,
LATEST_ACT_START TYPE STRING,
LATEST_ACT_END TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMTMS/S_TOR_STOP_K_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_/SCMTMS/S_TOR_STOP_K_STR-KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-PARENT_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ROOT_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_ID sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_CAT sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LOG_LOC_UUID sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LOG_LOCID sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LOG_LOCUN sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LOG_LOCIATA sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ADR_LOC_UUID sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_PARENT_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_WITH_SUBSTOPS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-SUBSTOPS_KIND sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-NODE_HAS_ERROR sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ACC_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-REQ_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-REQ_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ACC_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-DATES_SETBY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-PLAN_TRANS_TIME sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_ROLE sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_ORIGIN sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_SEQ_POS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_CURRENT sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-AUTO_PLAN sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-SEL_TIME sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-APPOINTMENT_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-APPOINTMENT_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CARR_CONF_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CARR_CONF_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-PREPARE_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-PREPARE_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-FINALIZE_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-FINALIZE_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-PUDLV_CALC_BASE sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-STOP_FIX sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-HANDLING_EXEC sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-AGGR_ASSGN_START_L sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-AGGR_ASSGN_END_L sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-AGGR_ASSGN_START_C sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-AGGR_ASSGN_END_C sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CUTOFF_CARGO sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CUTOFF_DOC sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CUTOFF_CUST_DOC sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CUTOFF_DG_DOC sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CUTOFF_DOC_SET_BY_SRVC sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-CUTOFF_CARR_VGM sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ENTRY_PORT sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-EXIT_PORT sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-EWM_INT_REL sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-WH_TRANSM_STATUS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LOAD_PLAN_STATUS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-WH_NEXT_REL sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LOAD_POINT_ID sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LOAD_POINT_UUID sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASR_INDICATOR sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASR_SOURCE sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-WH_CAT sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-WH_NUMBER sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-WH_DOOR sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-WH_DOOR_STATUS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-BLK_EXEC sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-PREDEC_BLK_EXEC sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_STOP_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_ITEM_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_NET_DUR sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_SEQ sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_HRES sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_HRES_CONS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSG_CAT sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ASSGN_MULTI sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-SCHED_STOP_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-SCHED_REF_INFO sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-SCHED_REF_DATA_STATUS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-SCHED_DEP_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ROUTE_STOP_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ROUTE_REF_DATA_STATUS sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-ROUTE_ROOT_KEY sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-TRQ_BASED_STOP sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-TRQ_ACC_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-TRQ_REQ_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-TRQ_REQ_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-TRQ_ACC_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-TOR_STOP_PUDL_RULE sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-EEW_TOR_STOP sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-EARLIEST_ACT_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-EARLIEST_ACT_END sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LATEST_ACT_START sy-vline
WA_/SCMTMS/S_TOR_STOP_K_STR-LATEST_ACT_END sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.