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

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

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

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


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

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCWM/S_TO_DYNSEL_MON-TRART, sy-vline,
WA_/SCWM/S_TO_DYNSEL_MON-PRCES, sy-vline,
WA_/SCWM/S_TO_DYNSEL_MON-PROCS, sy-vline,
WA_/SCWM/S_TO_DYNSEL_MON-TOSTAT, sy-vline,
WA_/SCWM/S_TO_DYNSEL_MON-CREATED_BY, sy-vline,
WA_/SCWM/S_TO_DYNSEL_MON-CREATED_AT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_TO_DYNSEL_MON 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_TO_DYNSEL_MON 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_TO_DYNSEL_MON INTO WA_/SCWM/S_TO_DYNSEL_MON. *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 ALPH0, internal->external for field TANUM CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-TANUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-TANUM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTWH, internal->external for field CREATED_AT CALL FUNCTION 'CONVERSION_EXIT_TSTWH_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-CREATED_AT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-CREATED_AT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTWH, internal->external for field STARTED_AT CALL FUNCTION 'CONVERSION_EXIT_TSTWH_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-STARTED_AT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-STARTED_AT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit BPMAP, internal->external for field OWNER CALL FUNCTION 'CONVERSION_EXIT_BPMAP_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-OWNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-OWNER.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

*Conversion exit TSTWH, internal->external for field WDATU CALL FUNCTION 'CONVERSION_EXIT_TSTWH_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-WDATU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-WDATU.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit HUID, internal->external for field VLENR CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-VLENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-VLENR.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit HUID, internal->external for field NLENR CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-NLENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-NLENR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPH0, internal->external for field WAVE CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-WAVE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-WAVE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPH0, internal->external for field WAVE_ITM CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-WAVE_ITM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-WAVE_ITM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPH0, internal->external for field WHO CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-WHO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-WHO.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit GJAHR, internal->external for field MMIM_MJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-MMIM_MJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-MMIM_MJAHR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field MMIM_MBLNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_DYNSEL_MON-MMIM_MBLNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_DYNSEL_MON-MMIM_MBLNR.
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_/SCWM/S_TO_DYNSEL_MON_STR,
MANDT TYPE STRING,
LGNUM TYPE STRING,
TANUM TYPE STRING,
FLGHUTO TYPE STRING,
PROCTY TYPE STRING,
TRART TYPE STRING,
PRCES TYPE STRING,
PROCS TYPE STRING,
TOSTAT TYPE STRING,
CREATED_BY TYPE STRING,
CREATED_AT TYPE STRING,
PRSRC TYPE STRING,
REASON TYPE STRING,
STARTED_AT TYPE STRING,
CAT TYPE STRING,
STOCK_DOCCAT TYPE STRING,
STOCK_DOCNO TYPE STRING,
STOCK_ITMNO TYPE STRING,
DOCCAT TYPE STRING,
STOCK_USAGE TYPE STRING,
OWNER TYPE STRING,
ENTITLED TYPE STRING,
VSOLM TYPE STRING,
NISTM TYPE STRING,
MEINS TYPE STRING,
VSOLA TYPE STRING,
NISTA TYPE STRING,
ALTME TYPE STRING,
LETYP TYPE STRING,
WEIGHT TYPE STRING,
UNIT_W TYPE STRING,
VOLUM TYPE STRING,
UNIT_V TYPE STRING,
CAPA TYPE STRING,
SOLPO TYPE STRING,
ZEIEI TYPE STRING,
PLACE_INV TYPE STRING,
LOWCHK_INV TYPE STRING,
VFDAT TYPE STRING,
WDATU TYPE STRING,
COO TYPE STRING,
IDPLATE TYPE STRING,
VLTYP TYPE STRING,
VLPLA TYPE STRING,
SRSRC TYPE STRING,
STU_NUM TYPE STRING,
VLENR TYPE STRING,
NLTYP TYPE STRING,
NLPLA TYPE STRING,
DRSRC TYPE STRING,
DTU_NUM TYPE STRING,
NLENR TYPE STRING,
KZSUB TYPE STRING,
RDOCCAT TYPE STRING,
WAVE TYPE STRING,
WAVE_ITM TYPE STRING,
L2SKA TYPE STRING,
L2SKR TYPE STRING,
AAREA TYPE STRING,
WHO TYPE STRING,
QUEUE TYPE STRING,
PSA TYPE STRING,
ORD_CANCEL TYPE STRING,
MMIM_MJAHR TYPE STRING,
MMIM_MBLNR TYPE STRING,
MMIM_ZEILE TYPE STRING,
JIT_RELEVANCE TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_TO_DYNSEL_MON_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_TO_DYNSEL_MON_STR-MANDT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-LGNUM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-TANUM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-FLGHUTO sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-PROCTY sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-TRART sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-PRCES sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-PROCS sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-TOSTAT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-CREATED_BY sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-CREATED_AT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-PRSRC sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-REASON sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-STARTED_AT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-CAT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-STOCK_DOCCAT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-STOCK_DOCNO sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-STOCK_ITMNO sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-DOCCAT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-STOCK_USAGE sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-OWNER sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-ENTITLED sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-VSOLM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-NISTM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-MEINS sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-VSOLA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-NISTA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-ALTME sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-LETYP sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-WEIGHT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-UNIT_W sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-VOLUM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-UNIT_V sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-CAPA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-SOLPO sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-ZEIEI sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-PLACE_INV sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-LOWCHK_INV sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-VFDAT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-WDATU sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-COO sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-IDPLATE sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-VLTYP sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-VLPLA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-SRSRC sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-STU_NUM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-VLENR sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-NLTYP sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-NLPLA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-DRSRC sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-DTU_NUM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-NLENR sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-KZSUB sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-RDOCCAT sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-WAVE sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-WAVE_ITM sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-L2SKA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-L2SKR sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-AAREA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-WHO sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-QUEUE sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-PSA sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-ORD_CANCEL sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-MMIM_MJAHR sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-MMIM_MBLNR sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-MMIM_ZEILE sy-vline
WA_/SCWM/S_TO_DYNSEL_MON_STR-JIT_RELEVANCE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.