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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT ASSIGNING </SCMTMS/S_TBI_BUF_UI_OVW_ROOT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMTMS/S_TBI_BUF_UI_OVW_ROOT>-KEY = 1.
</SCMTMS/S_TBI_BUF_UI_OVW_ROOT>-TOR_CAT = 1.
</SCMTMS/S_TBI_BUF_UI_OVW_ROOT>-TOR_ID = 1.
</SCMTMS/S_TBI_BUF_UI_OVW_ROOT>-TU_CAT = 1.
</SCMTMS/S_TBI_BUF_UI_OVW_ROOT>-TOR_TYPE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-TOR_TYPE_TXT, sy-vline,
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-MTR, sy-vline,
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-MTR_READONLY_REF, sy-vline,
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-MTR_ICON, sy-vline,
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-MTR_ICON_TOOLTIP, sy-vline,
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-TRMODCOD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT 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_TBI_BUF_UI_OVW_ROOT 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_TBI_BUF_UI_OVW_ROOT INTO WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT. *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 TOR_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-TOR_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-TOR_ID.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit QTYRN, internal->external for field NORMLOADCONSVAL CALL FUNCTION 'CONVERSION_EXIT_QTYRN_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-NORMLOADCONSVAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-NORMLOADCONSVAL.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit QTYRN, internal->external for field ADDNORMLOADCONSVAL CALL FUNCTION 'CONVERSION_EXIT_QTYRN_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-ADDNORMLOADCONSVAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-ADDNORMLOADCONSVAL.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field ADDNORMLOADCONSUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-ADDNORMLOADCONSUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT-ADDNORMLOADCONSUOM.
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_TBI_BUF_UI_OVW_ROOT_STR,
KEY TYPE STRING,
TOR_CAT TYPE STRING,
TOR_ID TYPE STRING,
TU_CAT TYPE STRING,
TOR_TYPE TYPE STRING,
TOR_TYPE_TXT TYPE STRING,
MTR TYPE STRING,
MTR_READONLY_REF TYPE STRING,
MTR_ICON TYPE STRING,
MTR_ICON_TOOLTIP TYPE STRING,
TRMODCOD TYPE STRING,
TRMODCOD_TXT TYPE STRING,
DGO_INDICATOR TYPE STRING,
DGO_ICON TYPE STRING,
DGO_ICON_TOOLTIP TYPE STRING,
DGO_CHECK_ERROR TYPE STRING,
DGO_CHECK_ERROR_TXT TYPE STRING,
TSP TYPE STRING,
TSPID TYPE STRING,
TSPID_READONLY_REF TYPE STRING,
TSP_DESCRIPTION TYPE STRING,
TSP_SCAC TYPE STRING,
TSP_AIRLC TYPE STRING,
TSP_AIRLC_READONLY_REF TYPE STRING,
TSP_AIRLCAWB TYPE STRING,
BLK_PLAN TYPE STRING,
BLK_EXEC TYPE STRING,
BRC_PLAN TYPE STRING,
BRC_PLAN_TXT TYPE STRING,
BRC_EXEC TYPE STRING,
BRC_EXEC_TXT TYPE STRING,
PARTNER_MBL_ID TYPE STRING,
PARTNER_REF_ID TYPE STRING,
PARTNER_REF_ID_READONLY_REF TYPE STRING,
LIFECYCLE TYPE STRING,
LIFECYCLE_TXT TYPE STRING,
EXECUTION TYPE STRING,
EXECUTION_TXT TYPE STRING,
FIXATION TYPE STRING,
FIXATION_ICON TYPE STRING,
FIXATION_TXT TYPE STRING,
MULTI_EXE_PTY TYPE STRING,
PYMT_IND TYPE STRING,
PYMT_IND_TXT TYPE STRING,
DENSITY_FACTOR_TXT TYPE STRING,
GEN_SECURITY_STATUS TYPE STRING,
GEN_SECURITY_STATUS_TXT TYPE STRING,
ERP_SHP_REL TYPE STRING,
BL_NUMBER TYPE STRING,
BL_NUMBER_STATUS TYPE STRING,
BASE_BTD_TCO TYPE STRING,
BASE_BTD_ID TYPE STRING,
BASE_BTD_TCO_TXT TYPE STRING,
REQ_DRV_CNT TYPE STRING,
DRV_RELEVANCE TYPE STRING,
DRV_ASSGN_TYPE TYPE STRING,
DRV_SETTINGS_CHGEABLE TYPE STRING,
NORMLOADCONSVAL TYPE STRING,
NORMLOADCONSUOM TYPE STRING,
ADDNORMLOADCONSVAL TYPE STRING,
ADDNORMLOADCONSUOM TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_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_TBI_BUF_UI_OVW_ROOT_STR-KEY sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TOR_CAT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TOR_ID sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TU_CAT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TOR_TYPE sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TOR_TYPE_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-MTR sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-MTR_READONLY_REF sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-MTR_ICON sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-MTR_ICON_TOOLTIP sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TRMODCOD sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TRMODCOD_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DGO_INDICATOR sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DGO_ICON sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DGO_ICON_TOOLTIP sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DGO_CHECK_ERROR sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DGO_CHECK_ERROR_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSP sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSPID sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSPID_READONLY_REF sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSP_DESCRIPTION sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSP_SCAC sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSP_AIRLC sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSP_AIRLC_READONLY_REF sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-TSP_AIRLCAWB sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BLK_PLAN sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BLK_EXEC sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BRC_PLAN sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BRC_PLAN_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BRC_EXEC sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BRC_EXEC_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-PARTNER_MBL_ID sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-PARTNER_REF_ID sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-PARTNER_REF_ID_READONLY_REF sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-LIFECYCLE sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-LIFECYCLE_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-EXECUTION sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-EXECUTION_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-FIXATION sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-FIXATION_ICON sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-FIXATION_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-MULTI_EXE_PTY sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-PYMT_IND sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-PYMT_IND_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DENSITY_FACTOR_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-GEN_SECURITY_STATUS sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-GEN_SECURITY_STATUS_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-ERP_SHP_REL sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BL_NUMBER sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BL_NUMBER_STATUS sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BASE_BTD_TCO sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BASE_BTD_ID sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-BASE_BTD_TCO_TXT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-REQ_DRV_CNT sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DRV_RELEVANCE sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DRV_ASSGN_TYPE sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-DRV_SETTINGS_CHGEABLE sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-NORMLOADCONSVAL sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-NORMLOADCONSUOM sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-ADDNORMLOADCONSVAL sy-vline
WA_/SCMTMS/S_TBI_BUF_UI_OVW_ROOT_STR-ADDNORMLOADCONSUOM sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.