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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCWM/S_WAVEITM_CL_DET_MON_OUT ASSIGNING </SCWM/S_WAVEITM_CL_DET_MON_OUT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_WAVEITM_CL_DET_MON_OUT>-LGNUM = 1.
</SCWM/S_WAVEITM_CL_DET_MON_OUT>-WAVE = 1.
</SCWM/S_WAVEITM_CL_DET_MON_OUT>-WAVE_ITM = 1.
</SCWM/S_WAVEITM_CL_DET_MON_OUT>-PRODUCTNO = 1.
</SCWM/S_WAVEITM_CL_DET_MON_OUT>-BATCHNO = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-QTY, sy-vline,
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-UOM, sy-vline,
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-OWNER, sy-vline,
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-ENTITLED, sy-vline,
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-DOCNO, sy-vline,
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-ITEMNO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT 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_WAVEITM_CL_DET_MON_OUT 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_WAVEITM_CL_DET_MON_OUT INTO WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT. *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 WAVE CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-WAVE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-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_WAVEITM_CL_DET_MON_OUT-WAVE_ITM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-WAVE_ITM.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit BPMAP, internal->external for field OWNER CALL FUNCTION 'CONVERSION_EXIT_BPMAP_OUTPUT' EXPORTING input = WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-OWNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-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_WAVEITM_CL_DET_MON_OUT-ENTITLED IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-ENTITLED.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

*Conversion exit TSPWM, internal->external for field TSP CALL FUNCTION 'CONVERSION_EXIT_TSPWM_OUTPUT' EXPORTING input = WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-TSP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-TSP.
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_WAVEITM_CL_DET_MON_OUT-UNIT_W IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-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_WAVEITM_CL_DET_MON_OUT-UNIT_V IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-UNIT_V.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field WR_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-WR_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT-WR_UOM.
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_WAVEITM_CL_DET_MON_OUT_STR,
LGNUM TYPE STRING,
WAVE TYPE STRING,
WAVE_ITM TYPE STRING,
PRODUCTNO TYPE STRING,
BATCHNO TYPE STRING,
QTY TYPE STRING,
UOM TYPE STRING,
OWNER TYPE STRING,
ENTITLED TYPE STRING,
DOCNO TYPE STRING,
ITEMNO TYPE STRING,
SPLIT_ID TYPE STRING,
AAREA TYPE STRING,
ROUTE_ID TYPE STRING,
REFDOCNO_SO TYPE STRING,
CARRIER TYPE STRING,
SHIPTO TYPE STRING,
TU_NUM_EXT TYPE STRING,
TSP TYPE STRING,
GI_DATE TYPE STRING,
GI_TIME TYPE STRING,
TYPE_2ST TYPE STRING,
STAT_CR TYPE STRING,
WEIGHT TYPE STRING,
UNIT_W TYPE STRING,
VOLUM TYPE STRING,
UNIT_V TYPE STRING,
CAPA TYPE STRING,
WV_ERROR TYPE STRING,
RDOCCAT TYPE STRING,
PROCTY TYPE STRING,
SIM_ICON TYPE STRING,
WR_QTY TYPE STRING,
WR_UOM TYPE STRING,
OPEN_QTY TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_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_WAVEITM_CL_DET_MON_OUT_STR-LGNUM sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-WAVE sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-WAVE_ITM sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-PRODUCTNO sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-BATCHNO sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-QTY sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-UOM sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-OWNER sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-ENTITLED sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-DOCNO sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-ITEMNO sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-SPLIT_ID sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-AAREA sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-ROUTE_ID sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-REFDOCNO_SO sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-CARRIER sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-SHIPTO sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-TU_NUM_EXT sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-TSP sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-GI_DATE sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-GI_TIME sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-TYPE_2ST sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-STAT_CR sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-WEIGHT sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-UNIT_W sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-VOLUM sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-UNIT_V sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-CAPA sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-WV_ERROR sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-RDOCCAT sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-PROCTY sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-SIM_ICON sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-WR_QTY sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-WR_UOM sy-vline
WA_/SCWM/S_WAVEITM_CL_DET_MON_OUT_STR-OPEN_QTY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.