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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCMB/TMS_RES_HEAD_PLANT ASSIGNING </SCMB/TMS_RES_HEAD_PLANT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMB/TMS_RES_HEAD_PLANT>-MANDT = 1.
</SCMB/TMS_RES_HEAD_PLANT>-RESUID = 1.
</SCMB/TMS_RES_HEAD_PLANT>-SIMVERSID = 1.
</SCMB/TMS_RES_HEAD_PLANT>-SIMSESSID = 1.
</SCMB/TMS_RES_HEAD_PLANT>-LCRESID = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCMB/TMS_RES_HEAD_PLANT-TSTREAMID, sy-vline,
WA_/SCMB/TMS_RES_HEAD_PLANT-UNIT, sy-vline,
WA_/SCMB/TMS_RES_HEAD_PLANT-NAME, sy-vline,
WA_/SCMB/TMS_RES_HEAD_PLANT-RESTYPE, sy-vline,
WA_/SCMB/TMS_RES_HEAD_PLANT-RESOURCE_GROUP, sy-vline,
WA_/SCMB/TMS_RES_HEAD_PLANT-LOCID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMB/TMS_RES_HEAD_PLANT 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/TMS_RES_HEAD_PLANT 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/TMS_RES_HEAD_PLANT INTO WA_/SCMB/TMS_RES_HEAD_PLANT. *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 UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCMB/TMS_RES_HEAD_PLANT-UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/TMS_RES_HEAD_PLANT-UNIT.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

*Conversion exit CUNIT, internal->external for field STORAGE_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCMB/TMS_RES_HEAD_PLANT-STORAGE_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/TMS_RES_HEAD_PLANT-STORAGE_UNIT.
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/TMS_RES_HEAD_PLANT_STR,
MANDT TYPE STRING,
RESUID TYPE STRING,
SIMVERSID TYPE STRING,
SIMSESSID TYPE STRING,
LCRESID TYPE STRING,
TSTREAMID TYPE STRING,
UNIT TYPE STRING,
NAME TYPE STRING,
RESTYPE TYPE STRING,
RESOURCE_GROUP TYPE STRING,
LOCID TYPE STRING,
CALENDAR TYPE STRING,
TYPE TYPE STRING,
DIMENSION TYPE STRING,
BEGTI TYPE STRING,
ENDTI TYPE STRING,
BREAKTIME TYPE STRING,
BUFFERTIME TYPE STRING,
BUFFERTIME_UNIT TYPE STRING,
NOINDIVRES TYPE STRING,
NOINDIVRES_UNIT TYPE STRING,
INDIVRES_CAP TYPE STRING,
UTILIZATION TYPE STRING,
STRFACT TYPE STRING,
SHRFACT TYPE STRING,
CAPACITY_A TYPE STRING,
CAPACITY_A_UNIT TYPE STRING,
NUM_OF_PERIODS TYPE STRING,
PERIOD TYPE STRING,
PLANNER TYPE STRING,
PLANNER_SNP TYPE STRING,
OUTPUT_RATE TYPE STRING,
VERSION_ACTIVE TYPE STRING,
FINITE_PLANNING TYPE STRING,
IS_BOTTLENECK TYPE STRING,
MIN_GAPS TYPE STRING,
OVERLOAD TYPE STRING,
UNDERLOAD TYPE STRING,
OVERLAP_BUCKETS TYPE STRING,
START_ON_GRID TYPE STRING,
MIN_OVERLAP TYPE STRING,
MIN_OVERLAP_UNIT TYPE STRING,
MATRIX_ID TYPE STRING,
REFUID TYPE STRING,
CHANGEUSER TYPE STRING,
CHANGEDATE TYPE STRING,
LOSS_FACTOR TYPE STRING,
REF_PROCTIME TYPE STRING,
REF_PTIME_UNIT TYPE STRING,
TZONE TYPE STRING,
TAKTS TYPE STRING,
BR_QUANT TYPE STRING,
BR_QUNIT TYPE STRING,
BR_TIME TYPE STRING,
BR_TUNIT TYPE STRING,
RITT_FLG TYPE STRING,
MDRMODEL TYPE STRING,
SORT TYPE STRING,
SYNC_START TYPE STRING,
SYNC_COMPATIBLE TYPE STRING,
DEFINE_BUCKETS TYPE STRING,
SINGLE_RES_LC TYPE STRING,
SINGLE_RES_TID TYPE STRING,
LC_DAYS_MINUS TYPE STRING,
LC_DAYS_PLUS TYPE STRING,
TRATY TYPE STRING,
STORAGE_CAPABLE TYPE STRING,
STORAGE_TO_ZERO TYPE STRING,
SNPLC TYPE STRING,
UTIL_BUCKET TYPE STRING,
MIX_PLAN_TYPE TYPE STRING,
CAMPAIGN_PPDS TYPE STRING,
CAMPAIGN_SNP TYPE STRING,
TSTREAM_EXTERNAL TYPE STRING,
FINITY_LEVEL TYPE STRING,
MULTIPLE_PRODUCT TYPE STRING,
DIM_STORAGE TYPE STRING,
MIN_STORAGE TYPE STRING,
MAX_STORAGE TYPE STRING,
MIN_REPLENISHMNT TYPE STRING,
STORAGE_UNIT TYPE STRING,
DIMENSION_BUCKET TYPE STRING,
LOCNO TYPE STRING,
TEXT TYPE STRING,
TRATY_PASSIVE TYPE STRING,
EXT_TTYPE_FLG TYPE STRING,
EXT_TTYPE_NUM TYPE STRING,
LOCK_MULTIRES TYPE STRING,
NO_DIRECT_LOAD TYPE STRING,
CREATEUSER TYPE STRING,
CREATEDATE TYPE STRING,
UPD TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMB/TMS_RES_HEAD_PLANT_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/TMS_RES_HEAD_PLANT_STR-MANDT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-RESUID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SIMVERSID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SIMSESSID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-LCRESID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TSTREAMID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-UNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-NAME sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-RESTYPE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-RESOURCE_GROUP sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-LOCID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CALENDAR sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TYPE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-DIMENSION sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BEGTI sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-ENDTI sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BREAKTIME sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BUFFERTIME sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BUFFERTIME_UNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-NOINDIVRES sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-NOINDIVRES_UNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-INDIVRES_CAP sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-UTILIZATION sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-STRFACT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SHRFACT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CAPACITY_A sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CAPACITY_A_UNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-NUM_OF_PERIODS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-PERIOD sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-PLANNER sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-PLANNER_SNP sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-OUTPUT_RATE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-VERSION_ACTIVE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-FINITE_PLANNING sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-IS_BOTTLENECK sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MIN_GAPS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-OVERLOAD sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-UNDERLOAD sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-OVERLAP_BUCKETS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-START_ON_GRID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MIN_OVERLAP sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MIN_OVERLAP_UNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MATRIX_ID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-REFUID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CHANGEUSER sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CHANGEDATE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-LOSS_FACTOR sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-REF_PROCTIME sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-REF_PTIME_UNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TZONE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TAKTS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BR_QUANT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BR_QUNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BR_TIME sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-BR_TUNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-RITT_FLG sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MDRMODEL sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SORT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SYNC_START sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SYNC_COMPATIBLE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-DEFINE_BUCKETS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SINGLE_RES_LC sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SINGLE_RES_TID sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-LC_DAYS_MINUS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-LC_DAYS_PLUS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TRATY sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-STORAGE_CAPABLE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-STORAGE_TO_ZERO sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-SNPLC sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-UTIL_BUCKET sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MIX_PLAN_TYPE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CAMPAIGN_PPDS sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CAMPAIGN_SNP sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TSTREAM_EXTERNAL sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-FINITY_LEVEL sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MULTIPLE_PRODUCT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-DIM_STORAGE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MIN_STORAGE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MAX_STORAGE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-MIN_REPLENISHMNT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-STORAGE_UNIT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-DIMENSION_BUCKET sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-LOCNO sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TEXT sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-TRATY_PASSIVE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-EXT_TTYPE_FLG sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-EXT_TTYPE_NUM sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-LOCK_MULTIRES sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-NO_DIRECT_LOAD sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CREATEUSER sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-CREATEDATE sy-vline
WA_/SCMB/TMS_RES_HEAD_PLANT_STR-UPD sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.