ABAP Select data from SAP table /SCWM/S_T331 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_T331 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_T331. 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_T331 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_T331 TYPE STANDARD TABLE OF /SCWM/S_T331, WA_/SCWM/S_T331 TYPE /SCWM/S_T331, 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_T331> TYPE /SCWM/S_T331. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SCWM/S_T331. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SCWM/S_T331 INTO TABLE IT_/SCWM/S_T331. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SCWM/S_T331 * INTO TABLE @DATA(IT_/SCWM/S_T3312). *--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_T331 INDEX 1 INTO DATA(WA_/SCWM/S_T3312). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SCWM/S_T331 ASSIGNING </SCWM/S_T331>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_T331>-LGNUM = 1.
</SCWM/S_T331>-LGTYP = 1.
</SCWM/S_T331>-KAPAP = 1.
</SCWM/S_T331>-QUEIN = 1.
</SCWM/S_T331>-QUAUS = 1.
ENDLOOP. LOOP AT IT_/SCWM/S_T331 INTO WA_/SCWM/S_T331. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SCWM/S_T331-ZULAG, sy-vline,
WA_/SCWM/S_T331-ADD_LEVEL, sy-vline,
WA_/SCWM/S_T331-NEGAT, sy-vline,
WA_/SCWM/S_T331-REM_RULE, sy-vline,
WA_/SCWM/S_T331-PRLET, sy-vline,
WA_/SCWM/S_T331-PRBER, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_T331 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_T331 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_T331 INTO WA_/SCWM/S_T331. *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_T331_STR,
LGNUM TYPE STRING,
LGTYP TYPE STRING,
KAPAP TYPE STRING,
QUEIN TYPE STRING,
QUAUS TYPE STRING,
ZULAG TYPE STRING,
ADD_LEVEL TYPE STRING,
NEGAT TYPE STRING,
REM_RULE TYPE STRING,
PRLET TYPE STRING,
PRBER TYPE STRING,
GEFAL TYPE STRING,
ROUND TYPE STRING,
PIKTA TYPE STRING,
NOGIS TYPE STRING,
NOTRP TYPE STRING,
AVQLVL TYPE STRING,
AVQBTC TYPE STRING,
HUOBL TYPE STRING,
REPL_LVL TYPE STRING,
REPL_TOL TYPE STRING,
PPNTA TYPE STRING,
IPNTA TYPE STRING,
BINGN TYPE STRING,
FINPS TYPE STRING,
PROCS TYPE STRING,
HUPUT TYPE STRING,
TPFACTOR TYPE STRING,
RNDMODE TYPE STRING,
FLGDETFXB TYPE STRING,
FLGDETSMAQ TYPE STRING,
PUT_RULE TYPE STRING,
ST_ROLE TYPE STRING,
QUANCLA TYPE STRING,
QUANCLAP TYPE STRING,
AVLGRP TYPE STRING,
AVLGRP_MAND TYPE STRING,
CATLOCN TYPE STRING,
CAT_ROLE TYPE STRING,
SCBIN TYPE STRING,
BEHAV TYPE STRING,
FIXBIN TYPE STRING,
EBSRCHR TYPE STRING,
MIXBIN TYPE STRING,
MIXHU TYPE STRING,
MIXCAT TYPE STRING,
MIXOWN TYPE STRING,
MIXENT TYPE STRING,
MIXSS TYPE STRING,
MIXINSP TYPE STRING,
MIXBBD TYPE STRING,
MIXGR TYPE STRING,
MIXCT TYPE STRING,
CHKSMAQ TYPE STRING,
BTRULE TYPE STRING,
BTDETTEC TYPE STRING,
PERMXQTY TYPE STRING,
BINNOLIM TYPE STRING,
MAXFIXBIN TYPE STRING,
HUMOVE_PROD TYPE STRING,
SPLITTH TYPE STRING,
SPLITPUT TYPE STRING,
STOCK_RSRC TYPE STRING,
RBD_USE TYPE STRING,
STOCKID_DEL TYPE STRING,
MAXBINCHK TYPE STRING,
AAREA_PLAN TYPE STRING,
DISTANCE_DEF TYPE STRING,
RNDSPLIT TYPE STRING,
FLD_CTRL_HU_DEST TYPE STRING,
FIXMOD TYPE STRING,
CAPCHKBT TYPE STRING,
STGTYP_LVL TYPE STRING,
PTWY_STR_CTRL TYPE STRING,
FBAUTONO TYPE STRING,
NOCAPAUPD TYPE STRING,
REPL_TOL_WT TYPE STRING,
MIXAUOM TYPE STRING,
MIXAUOMSTLVL TYPE STRING,
MULTIDEEP TYPE STRING,
AIR_CRG_SECU TYPE STRING,
TEMPLATE TYPE STRING,
PTWY_AUTO_WT TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_T331_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_T331_STR-LGNUM sy-vline
WA_/SCWM/S_T331_STR-LGTYP sy-vline
WA_/SCWM/S_T331_STR-KAPAP sy-vline
WA_/SCWM/S_T331_STR-QUEIN sy-vline
WA_/SCWM/S_T331_STR-QUAUS sy-vline
WA_/SCWM/S_T331_STR-ZULAG sy-vline
WA_/SCWM/S_T331_STR-ADD_LEVEL sy-vline
WA_/SCWM/S_T331_STR-NEGAT sy-vline
WA_/SCWM/S_T331_STR-REM_RULE sy-vline
WA_/SCWM/S_T331_STR-PRLET sy-vline
WA_/SCWM/S_T331_STR-PRBER sy-vline
WA_/SCWM/S_T331_STR-GEFAL sy-vline
WA_/SCWM/S_T331_STR-ROUND sy-vline
WA_/SCWM/S_T331_STR-PIKTA sy-vline
WA_/SCWM/S_T331_STR-NOGIS sy-vline
WA_/SCWM/S_T331_STR-NOTRP sy-vline
WA_/SCWM/S_T331_STR-AVQLVL sy-vline
WA_/SCWM/S_T331_STR-AVQBTC sy-vline
WA_/SCWM/S_T331_STR-HUOBL sy-vline
WA_/SCWM/S_T331_STR-REPL_LVL sy-vline
WA_/SCWM/S_T331_STR-REPL_TOL sy-vline
WA_/SCWM/S_T331_STR-PPNTA sy-vline
WA_/SCWM/S_T331_STR-IPNTA sy-vline
WA_/SCWM/S_T331_STR-BINGN sy-vline
WA_/SCWM/S_T331_STR-FINPS sy-vline
WA_/SCWM/S_T331_STR-PROCS sy-vline
WA_/SCWM/S_T331_STR-HUPUT sy-vline
WA_/SCWM/S_T331_STR-TPFACTOR sy-vline
WA_/SCWM/S_T331_STR-RNDMODE sy-vline
WA_/SCWM/S_T331_STR-FLGDETFXB sy-vline
WA_/SCWM/S_T331_STR-FLGDETSMAQ sy-vline
WA_/SCWM/S_T331_STR-PUT_RULE sy-vline
WA_/SCWM/S_T331_STR-ST_ROLE sy-vline
WA_/SCWM/S_T331_STR-QUANCLA sy-vline
WA_/SCWM/S_T331_STR-QUANCLAP sy-vline
WA_/SCWM/S_T331_STR-AVLGRP sy-vline
WA_/SCWM/S_T331_STR-AVLGRP_MAND sy-vline
WA_/SCWM/S_T331_STR-CATLOCN sy-vline
WA_/SCWM/S_T331_STR-CAT_ROLE sy-vline
WA_/SCWM/S_T331_STR-SCBIN sy-vline
WA_/SCWM/S_T331_STR-BEHAV sy-vline
WA_/SCWM/S_T331_STR-FIXBIN sy-vline
WA_/SCWM/S_T331_STR-EBSRCHR sy-vline
WA_/SCWM/S_T331_STR-MIXBIN sy-vline
WA_/SCWM/S_T331_STR-MIXHU sy-vline
WA_/SCWM/S_T331_STR-MIXCAT sy-vline
WA_/SCWM/S_T331_STR-MIXOWN sy-vline
WA_/SCWM/S_T331_STR-MIXENT sy-vline
WA_/SCWM/S_T331_STR-MIXSS sy-vline
WA_/SCWM/S_T331_STR-MIXINSP sy-vline
WA_/SCWM/S_T331_STR-MIXBBD sy-vline
WA_/SCWM/S_T331_STR-MIXGR sy-vline
WA_/SCWM/S_T331_STR-MIXCT sy-vline
WA_/SCWM/S_T331_STR-CHKSMAQ sy-vline
WA_/SCWM/S_T331_STR-BTRULE sy-vline
WA_/SCWM/S_T331_STR-BTDETTEC sy-vline
WA_/SCWM/S_T331_STR-PERMXQTY sy-vline
WA_/SCWM/S_T331_STR-BINNOLIM sy-vline
WA_/SCWM/S_T331_STR-MAXFIXBIN sy-vline
WA_/SCWM/S_T331_STR-HUMOVE_PROD sy-vline
WA_/SCWM/S_T331_STR-SPLITTH sy-vline
WA_/SCWM/S_T331_STR-SPLITPUT sy-vline
WA_/SCWM/S_T331_STR-STOCK_RSRC sy-vline
WA_/SCWM/S_T331_STR-RBD_USE sy-vline
WA_/SCWM/S_T331_STR-STOCKID_DEL sy-vline
WA_/SCWM/S_T331_STR-MAXBINCHK sy-vline
WA_/SCWM/S_T331_STR-AAREA_PLAN sy-vline
WA_/SCWM/S_T331_STR-DISTANCE_DEF sy-vline
WA_/SCWM/S_T331_STR-RNDSPLIT sy-vline
WA_/SCWM/S_T331_STR-FLD_CTRL_HU_DEST sy-vline
WA_/SCWM/S_T331_STR-FIXMOD sy-vline
WA_/SCWM/S_T331_STR-CAPCHKBT sy-vline
WA_/SCWM/S_T331_STR-STGTYP_LVL sy-vline
WA_/SCWM/S_T331_STR-PTWY_STR_CTRL sy-vline
WA_/SCWM/S_T331_STR-FBAUTONO sy-vline
WA_/SCWM/S_T331_STR-NOCAPAUPD sy-vline
WA_/SCWM/S_T331_STR-REPL_TOL_WT sy-vline
WA_/SCWM/S_T331_STR-MIXAUOM sy-vline
WA_/SCWM/S_T331_STR-MIXAUOMSTLVL sy-vline
WA_/SCWM/S_T331_STR-MULTIDEEP sy-vline
WA_/SCWM/S_T331_STR-AIR_CRG_SECU sy-vline
WA_/SCWM/S_T331_STR-TEMPLATE sy-vline
WA_/SCWM/S_T331_STR-PTWY_AUTO_WT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.