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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCWM/S_DOWNLOAD_STOCK_POP ASSIGNING </SCWM/S_DOWNLOAD_STOCK_POP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_DOWNLOAD_STOCK_POP>-LGNUM = 1.
</SCWM/S_DOWNLOAD_STOCK_POP>-LGTYP = 1.
</SCWM/S_DOWNLOAD_STOCK_POP>-LGPLA = 1.
</SCWM/S_DOWNLOAD_STOCK_POP>-PI_AREA_UI = 1.
</SCWM/S_DOWNLOAD_STOCK_POP>-MATNR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCWM/S_DOWNLOAD_STOCK_POP-CHARG, sy-vline,
WA_/SCWM/S_DOWNLOAD_STOCK_POP-CAT, sy-vline,
WA_/SCWM/S_DOWNLOAD_STOCK_POP-ENTITLED, sy-vline,
WA_/SCWM/S_DOWNLOAD_STOCK_POP-OWNER, sy-vline,
WA_/SCWM/S_DOWNLOAD_STOCK_POP-STOCK_USAGE, sy-vline,
WA_/SCWM/S_DOWNLOAD_STOCK_POP-STOCK_DOCCAT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_DOWNLOAD_STOCK_POP 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_DOWNLOAD_STOCK_POP 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_DOWNLOAD_STOCK_POP INTO WA_/SCWM/S_DOWNLOAD_STOCK_POP. *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 MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/SCWM/S_DOWNLOAD_STOCK_POP-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_DOWNLOAD_STOCK_POP-MATNR.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

*Conversion exit CUNIT, internal->external for field COUNT_AUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_DOWNLOAD_STOCK_POP-COUNT_AUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_DOWNLOAD_STOCK_POP-COUNT_AUNIT.
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_DOWNLOAD_STOCK_POP_STR,
LGNUM TYPE STRING,
LGTYP TYPE STRING,
LGPLA TYPE STRING,
PI_AREA_UI TYPE STRING,
MATNR TYPE STRING,
CHARG TYPE STRING,
CAT TYPE STRING,
ENTITLED TYPE STRING,
OWNER TYPE STRING,
STOCK_USAGE TYPE STRING,
STOCK_DOCCAT TYPE STRING,
STOCK_DOCNO TYPE STRING,
STOCK_ITMNO TYPE STRING,
STREF_DOCCAT TYPE STRING,
IDPLATE TYPE STRING,
QDOCCAT TYPE STRING,
QDOCNO TYPE STRING,
QITEMNO TYPE STRING,
INSPTYP TYPE STRING,
INSPDOCNO TYPE STRING,
IND_BIN_EMPTY TYPE STRING,
BEHAV TYPE STRING,
FLGSBIN TYPE STRING,
LGPLA_MAIN TYPE STRING,
COUNT_QUAN TYPE STRING,
QUAN TYPE STRING,
UNIT TYPE STRING,
VPRSV TYPE STRING,
VERPR TYPE STRING,
PEINH TYPE STRING,
WAERS TYPE STRING,
VALUE TYPE STRING,
MOVED_DATE TYPE STRING,
MOVED_TIME TYPE STRING,
QUANA TYPE STRING,
AUNIT TYPE STRING,
COUNT_QUANA TYPE STRING,
COUNT_AUNIT TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_DOWNLOAD_STOCK_POP_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_DOWNLOAD_STOCK_POP_STR-LGNUM sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-LGTYP sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-LGPLA sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-PI_AREA_UI sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-MATNR sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-CHARG sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-CAT sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-ENTITLED sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-OWNER sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-STOCK_USAGE sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-STOCK_DOCCAT sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-STOCK_DOCNO sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-STOCK_ITMNO sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-STREF_DOCCAT sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-IDPLATE sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-QDOCCAT sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-QDOCNO sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-QITEMNO sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-INSPTYP sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-INSPDOCNO sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-IND_BIN_EMPTY sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-BEHAV sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-FLGSBIN sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-LGPLA_MAIN sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-COUNT_QUAN sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-QUAN sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-UNIT sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-VPRSV sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-VERPR sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-PEINH sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-WAERS sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-VALUE sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-MOVED_DATE sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-MOVED_TIME sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-QUANA sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-AUNIT sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-COUNT_QUANA sy-vline
WA_/SCWM/S_DOWNLOAD_STOCK_POP_STR-COUNT_AUNIT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.