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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCWM/S_TFORMFLD ASSIGNING </SCWM/S_TFORMFLD>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_TFORMFLD>-MANDT = 1.
</SCWM/S_TFORMFLD>-LGNUM = 1.
</SCWM/S_TFORMFLD>-PI_AREA = 1.
</SCWM/S_TFORMFLD>-PI_ITM_NUMBER = 1.
</SCWM/S_TFORMFLD>-BIN = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCWM/S_TFORMFLD-BIN_EMPTY, sy-vline,
WA_/SCWM/S_TFORMFLD-HU, sy-vline,
WA_/SCWM/S_TFORMFLD-HU_COMPLETE, sy-vline,
WA_/SCWM/S_TFORMFLD-HU_EMPTY, sy-vline,
WA_/SCWM/S_TFORMFLD-HU_MISSING, sy-vline,
WA_/SCWM/S_TFORMFLD-SUB_HU, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_TFORMFLD 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_/SCWM/S_TFORMFLD 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_/SCWM/S_TFORMFLD INTO WA_/SCWM/S_TFORMFLD. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/SCWM/S_TFORMFLD_STR,
MANDT TYPE STRING,
LGNUM TYPE STRING,
PI_AREA TYPE STRING,
PI_ITM_NUMBER TYPE STRING,
BIN TYPE STRING,
BIN_EMPTY TYPE STRING,
HU TYPE STRING,
HU_COMPLETE TYPE STRING,
HU_EMPTY TYPE STRING,
HU_MISSING TYPE STRING,
SUB_HU TYPE STRING,
SUB_HU_COMPLETE TYPE STRING,
SUB_HU_EMPTY TYPE STRING,
SUB_HU_MISSING TYPE STRING,
PRODUCTID TYPE STRING,
PRODUCT_DESC TYPE STRING,
BATCH TYPE STRING,
OWNER TYPE STRING,
OWNER_DESC TYPE STRING,
ENTITLED TYPE STRING,
ENTITLED_DESC TYPE STRING,
STOCK_TYPE TYPE STRING,
STOCK_TYPE_DESC TYPE STRING,
STOCK_USAGE TYPE STRING,
STOCK_USAGE_DESC TYPE STRING,
SPECIAL_STOCK_TYPE TYPE STRING,
SPECIAL_STOCK_TYPE_DESC TYPE STRING,
SPECIAL_STOCK_EXT_NO TYPE STRING,
SPECIAL_STOCK_EXT_ITM_NO TYPE STRING,
COUNTRY_OF_ORIGIN TYPE STRING,
COO_DESC TYPE STRING,
SLED TYPE STRING,
GR_DATE TYPE STRING,
QUANTITY TYPE STRING,
UOM TYPE STRING,
BOOKQTYFLG TYPE STRING,
BOOKUOMFLG TYPE STRING,
SERIAL_NUMBER_FLG TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_TFORMFLD_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_/SCWM/S_TFORMFLD_STR-MANDT sy-vline
WA_/SCWM/S_TFORMFLD_STR-LGNUM sy-vline
WA_/SCWM/S_TFORMFLD_STR-PI_AREA sy-vline
WA_/SCWM/S_TFORMFLD_STR-PI_ITM_NUMBER sy-vline
WA_/SCWM/S_TFORMFLD_STR-BIN sy-vline
WA_/SCWM/S_TFORMFLD_STR-BIN_EMPTY sy-vline
WA_/SCWM/S_TFORMFLD_STR-HU sy-vline
WA_/SCWM/S_TFORMFLD_STR-HU_COMPLETE sy-vline
WA_/SCWM/S_TFORMFLD_STR-HU_EMPTY sy-vline
WA_/SCWM/S_TFORMFLD_STR-HU_MISSING sy-vline
WA_/SCWM/S_TFORMFLD_STR-SUB_HU sy-vline
WA_/SCWM/S_TFORMFLD_STR-SUB_HU_COMPLETE sy-vline
WA_/SCWM/S_TFORMFLD_STR-SUB_HU_EMPTY sy-vline
WA_/SCWM/S_TFORMFLD_STR-SUB_HU_MISSING sy-vline
WA_/SCWM/S_TFORMFLD_STR-PRODUCTID sy-vline
WA_/SCWM/S_TFORMFLD_STR-PRODUCT_DESC sy-vline
WA_/SCWM/S_TFORMFLD_STR-BATCH sy-vline
WA_/SCWM/S_TFORMFLD_STR-OWNER sy-vline
WA_/SCWM/S_TFORMFLD_STR-OWNER_DESC sy-vline
WA_/SCWM/S_TFORMFLD_STR-ENTITLED sy-vline
WA_/SCWM/S_TFORMFLD_STR-ENTITLED_DESC sy-vline
WA_/SCWM/S_TFORMFLD_STR-STOCK_TYPE sy-vline
WA_/SCWM/S_TFORMFLD_STR-STOCK_TYPE_DESC sy-vline
WA_/SCWM/S_TFORMFLD_STR-STOCK_USAGE sy-vline
WA_/SCWM/S_TFORMFLD_STR-STOCK_USAGE_DESC sy-vline
WA_/SCWM/S_TFORMFLD_STR-SPECIAL_STOCK_TYPE sy-vline
WA_/SCWM/S_TFORMFLD_STR-SPECIAL_STOCK_TYPE_DESC sy-vline
WA_/SCWM/S_TFORMFLD_STR-SPECIAL_STOCK_EXT_NO sy-vline
WA_/SCWM/S_TFORMFLD_STR-SPECIAL_STOCK_EXT_ITM_NO sy-vline
WA_/SCWM/S_TFORMFLD_STR-COUNTRY_OF_ORIGIN sy-vline
WA_/SCWM/S_TFORMFLD_STR-COO_DESC sy-vline
WA_/SCWM/S_TFORMFLD_STR-SLED sy-vline
WA_/SCWM/S_TFORMFLD_STR-GR_DATE sy-vline
WA_/SCWM/S_TFORMFLD_STR-QUANTITY sy-vline
WA_/SCWM/S_TFORMFLD_STR-UOM sy-vline
WA_/SCWM/S_TFORMFLD_STR-BOOKQTYFLG sy-vline
WA_/SCWM/S_TFORMFLD_STR-BOOKUOMFLG sy-vline
WA_/SCWM/S_TFORMFLD_STR-SERIAL_NUMBER_FLG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.