ABAP Select data from SAP table /SCWM/S_QLOT_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_QLOT_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_QLOT_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_QLOT_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_QLOT_MON TYPE STANDARD TABLE OF /SCWM/S_QLOT_MON,
      WA_/SCWM/S_QLOT_MON TYPE /SCWM/S_QLOT_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_QLOT_MON> TYPE /SCWM/S_QLOT_MON.

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCWM/S_QLOT_MON ASSIGNING </SCWM/S_QLOT_MON>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_QLOT_MON>-PRUEFLOS = 1.
</SCWM/S_QLOT_MON>-ART = 1.
</SCWM/S_QLOT_MON>-STAT02 = 1.
</SCWM/S_QLOT_MON>-MATNR = 1.
</SCWM/S_QLOT_MON>-MAKTX = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCWM/S_QLOT_MON-CHARG, sy-vline,
WA_/SCWM/S_QLOT_MON-LICHN, sy-vline,
WA_/SCWM/S_QLOT_MON-VFDAT, sy-vline,
WA_/SCWM/S_QLOT_MON-LOSMENGE, sy-vline,
WA_/SCWM/S_QLOT_MON-MENGENEINH, sy-vline,
WA_/SCWM/S_QLOT_MON-LMENGEIST, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_QLOT_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_QLOT_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_QLOT_MON INTO WA_/SCWM/S_QLOT_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 ALPHA, internal->external for field PRUEFLOS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_QLOT_MON-PRUEFLOS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_QLOT_MON-PRUEFLOS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/SCWM/S_QLOT_MON-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_QLOT_MON-MATNR.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

*Conversion exit ALPHA, internal->external for field LS_VBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_QLOT_MON-LS_VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_QLOT_MON-LS_VBELN.
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_QLOT_MON_STR,
PRUEFLOS TYPE STRING,
ART TYPE STRING,
STAT02 TYPE STRING,
MATNR TYPE STRING,
MAKTX TYPE STRING,
CHARG TYPE STRING,
LICHN TYPE STRING,
VFDAT TYPE STRING,
LOSMENGE TYPE STRING,
MENGENEINH TYPE STRING,
LMENGEIST TYPE STRING,
GESSTICHPR TYPE STRING,
EINHPROBE TYPE STRING,
KZSKIPLOT TYPE STRING,
PASTRTERM TYPE STRING,
PAENDTERM TYPE STRING,
VCODE TYPE STRING,
VNAME TYPE STRING,
VDATUM TYPE STRING,
VEZEITERF TYPE STRING,
VFOLGEAKTI TYPE STRING,
LIFNR TYPE STRING,
LIF_DESCRIP TYPE STRING,
EBELN TYPE STRING,
AUFNR TYPE STRING,
LS_VBELN TYPE STRING,
ENSTEHDAT TYPE STRING,
ENTSTEZEIT TYPE STRING,
IOT TYPE STRING,
IOTDSCR TYPE STRING,
LOT_GUID TYPE STRING,
INBOUND_PROC TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_QLOT_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_QLOT_MON_STR-PRUEFLOS sy-vline
WA_/SCWM/S_QLOT_MON_STR-ART sy-vline
WA_/SCWM/S_QLOT_MON_STR-STAT02 sy-vline
WA_/SCWM/S_QLOT_MON_STR-MATNR sy-vline
WA_/SCWM/S_QLOT_MON_STR-MAKTX sy-vline
WA_/SCWM/S_QLOT_MON_STR-CHARG sy-vline
WA_/SCWM/S_QLOT_MON_STR-LICHN sy-vline
WA_/SCWM/S_QLOT_MON_STR-VFDAT sy-vline
WA_/SCWM/S_QLOT_MON_STR-LOSMENGE sy-vline
WA_/SCWM/S_QLOT_MON_STR-MENGENEINH sy-vline
WA_/SCWM/S_QLOT_MON_STR-LMENGEIST sy-vline
WA_/SCWM/S_QLOT_MON_STR-GESSTICHPR sy-vline
WA_/SCWM/S_QLOT_MON_STR-EINHPROBE sy-vline
WA_/SCWM/S_QLOT_MON_STR-KZSKIPLOT sy-vline
WA_/SCWM/S_QLOT_MON_STR-PASTRTERM sy-vline
WA_/SCWM/S_QLOT_MON_STR-PAENDTERM sy-vline
WA_/SCWM/S_QLOT_MON_STR-VCODE sy-vline
WA_/SCWM/S_QLOT_MON_STR-VNAME sy-vline
WA_/SCWM/S_QLOT_MON_STR-VDATUM sy-vline
WA_/SCWM/S_QLOT_MON_STR-VEZEITERF sy-vline
WA_/SCWM/S_QLOT_MON_STR-VFOLGEAKTI sy-vline
WA_/SCWM/S_QLOT_MON_STR-LIFNR sy-vline
WA_/SCWM/S_QLOT_MON_STR-LIF_DESCRIP sy-vline
WA_/SCWM/S_QLOT_MON_STR-EBELN sy-vline
WA_/SCWM/S_QLOT_MON_STR-AUFNR sy-vline
WA_/SCWM/S_QLOT_MON_STR-LS_VBELN sy-vline
WA_/SCWM/S_QLOT_MON_STR-ENSTEHDAT sy-vline
WA_/SCWM/S_QLOT_MON_STR-ENTSTEZEIT sy-vline
WA_/SCWM/S_QLOT_MON_STR-IOT sy-vline
WA_/SCWM/S_QLOT_MON_STR-IOTDSCR sy-vline
WA_/SCWM/S_QLOT_MON_STR-LOT_GUID sy-vline
WA_/SCWM/S_QLOT_MON_STR-INBOUND_PROC sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.