ABAP Select data from SAP table FSH_S_PCW_ORD_LIST 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 FSH_S_PCW_ORD_LIST 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 FSH_S_PCW_ORD_LIST. 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 FSH_S_PCW_ORD_LIST 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_FSH_S_PCW_ORD_LIST TYPE STANDARD TABLE OF FSH_S_PCW_ORD_LIST,
      WA_FSH_S_PCW_ORD_LIST TYPE FSH_S_PCW_ORD_LIST,
      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: <FSH_S_PCW_ORD_LIST> TYPE FSH_S_PCW_ORD_LIST.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM FSH_S_PCW_ORD_LIST
  INTO TABLE IT_FSH_S_PCW_ORD_LIST.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FSH_S_PCW_ORD_LIST
*  INTO TABLE @DATA(IT_FSH_S_PCW_ORD_LIST2).
*--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_FSH_S_PCW_ORD_LIST INDEX 1 INTO DATA(WA_FSH_S_PCW_ORD_LIST2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FSH_S_PCW_ORD_LIST ASSIGNING <FSH_S_PCW_ORD_LIST>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FSH_S_PCW_ORD_LIST>-MARK = 1.
<FSH_S_PCW_ORD_LIST>-ORDER_NUM = 1.
<FSH_S_PCW_ORD_LIST>-ITEM_NUM = 1.
<FSH_S_PCW_ORD_LIST>-MATNR = 1.
<FSH_S_PCW_ORD_LIST>-MAKTX = 1.
ENDLOOP.

LOOP AT IT_FSH_S_PCW_ORD_LIST INTO WA_FSH_S_PCW_ORD_LIST.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FSH_S_PCW_ORD_LIST-GAMNG, sy-vline,
WA_FSH_S_PCW_ORD_LIST-GMEIN, sy-vline,
WA_FSH_S_PCW_ORD_LIST-GASMG, sy-vline,
WA_FSH_S_PCW_ORD_LIST-PSTTR, sy-vline,
WA_FSH_S_PCW_ORD_LIST-PEDTR, sy-vline,
WA_FSH_S_PCW_ORD_LIST-PERTR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FSH_S_PCW_ORD_LIST 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_FSH_S_PCW_ORD_LIST 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_FSH_S_PCW_ORD_LIST INTO WA_FSH_S_PCW_ORD_LIST. *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 ORDER_NUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FSH_S_PCW_ORD_LIST-ORDER_NUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FSH_S_PCW_ORD_LIST-ORDER_NUM.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ATINN, internal->external for field COLOR_ATINN CALL FUNCTION 'CONVERSION_EXIT_ATINN_OUTPUT' EXPORTING input = WA_FSH_S_PCW_ORD_LIST-COLOR_ATINN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FSH_S_PCW_ORD_LIST-COLOR_ATINN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ATINN, internal->external for field SIZE1_ATINN CALL FUNCTION 'CONVERSION_EXIT_ATINN_OUTPUT' EXPORTING input = WA_FSH_S_PCW_ORD_LIST-SIZE1_ATINN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FSH_S_PCW_ORD_LIST-SIZE1_ATINN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ATINN, internal->external for field SIZE2_ATINN CALL FUNCTION 'CONVERSION_EXIT_ATINN_OUTPUT' EXPORTING input = WA_FSH_S_PCW_ORD_LIST-SIZE2_ATINN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FSH_S_PCW_ORD_LIST-SIZE2_ATINN.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ABPSP, internal->external for field PROJN CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_FSH_S_PCW_ORD_LIST-PROJN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FSH_S_PCW_ORD_LIST-PROJN.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

*Conversion exit ALPHA, internal->external for field INFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FSH_S_PCW_ORD_LIST-INFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FSH_S_PCW_ORD_LIST-INFNR.
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_FSH_S_PCW_ORD_LIST_STR,
MARK TYPE STRING,
ORDER_NUM TYPE STRING,
ITEM_NUM TYPE STRING,
MATNR TYPE STRING,
MAKTX TYPE STRING,
GAMNG TYPE STRING,
GMEIN TYPE STRING,
GASMG TYPE STRING,
PSTTR TYPE STRING,
PEDTR TYPE STRING,
PERTR TYPE STRING,
SGT_SCAT TYPE STRING,
STATUS TYPE STRING,
WRF_CHARSTC1 TYPE STRING,
WRF_CHARSTC1_TXT TYPE STRING,
WRF_CHARSTC2 TYPE STRING,
WRF_CHARSTC2_TXT TYPE STRING,
WRF_CHARSTC3 TYPE STRING,
WRF_CHARSTC3_TXT TYPE STRING,
COLOR_ATINN TYPE STRING,
SIZE1_ATINN TYPE STRING,
SIZE2_ATINN TYPE STRING,
FSH_SEASON_YEAR TYPE STRING,
FSH_SEASON TYPE STRING,
FSH_COLLECTION TYPE STRING,
FSH_THEME TYPE STRING,
VFMNG TYPE STRING,
AUFFX TYPE STRING,
BEDID TYPE STRING,
GSTRS TYPE STRING,
GLTRS TYPE STRING,
TRMDT TYPE STRING,
TRMER TYPE STRING,
TRMHK TYPE STRING,
LVSCH TYPE STRING,
KAPFX TYPE STRING,
VBELN TYPE STRING,
POSNR TYPE STRING,
DISPO TYPE STRING,
DWERK TYPE STRING,
PLWRK TYPE STRING,
FEVOR TYPE STRING,
WEMNG TYPE STRING,
RSNUM TYPE STRING,
TERKZ TYPE STRING,
PAART TYPE STRING,
SOBES TYPE STRING,
FSH_MG_AT1 TYPE STRING,
FSH_MG_AT2 TYPE STRING,
FSH_MG_AT3 TYPE STRING,
FSH_VAR_GROUP TYPE STRING,
DAUAT TYPE STRING,
SERNR TYPE STRING,
PROJN TYPE STRING,
UMSKZ TYPE STRING,
PLGRP TYPE STRING,
FLG_BUNDLE TYPE STRING,
LFDAT TYPE STRING,
EKORG TYPE STRING,
EKGRP TYPE STRING,
LIFNR TYPE STRING,
FLIEF TYPE STRING,
SOBSL TYPE STRING,
CSTATUS TYPE STRING,
KUNNR TYPE STRING,
KONNR TYPE STRING,
FRGDT TYPE STRING,
BADAT TYPE STRING,
PREIS TYPE STRING,
RESWK TYPE STRING,
IDNLF TYPE STRING,
INFNR TYPE STRING,
NAME1 TYPE STRING,
OBJNR TYPE STRING,
PARTIAL_DEL_FLAG TYPE STRING,
ATTYP TYPE STRING,
TERKZ_TX TYPE STRING,
VERID TYPE STRING,
PLAUF TYPE STRING,
AUFLD TYPE STRING,
OFMNG TYPE STRING,
GSMNG TYPE STRING,END OF T_EKKO_STR. DATA: WA_FSH_S_PCW_ORD_LIST_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_FSH_S_PCW_ORD_LIST_STR-MARK sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-ORDER_NUM sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-ITEM_NUM sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-MATNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-MAKTX sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-GAMNG sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-GMEIN sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-GASMG sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PSTTR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PEDTR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PERTR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-SGT_SCAT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-STATUS sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-WRF_CHARSTC1 sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-WRF_CHARSTC1_TXT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-WRF_CHARSTC2 sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-WRF_CHARSTC2_TXT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-WRF_CHARSTC3 sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-WRF_CHARSTC3_TXT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-COLOR_ATINN sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-SIZE1_ATINN sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-SIZE2_ATINN sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_SEASON_YEAR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_SEASON sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_COLLECTION sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_THEME sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-VFMNG sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-AUFFX sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-BEDID sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-GSTRS sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-GLTRS sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-TRMDT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-TRMER sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-TRMHK sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-LVSCH sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-KAPFX sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-VBELN sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-POSNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-DISPO sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-DWERK sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PLWRK sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FEVOR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-WEMNG sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-RSNUM sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-TERKZ sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PAART sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-SOBES sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_MG_AT1 sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_MG_AT2 sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_MG_AT3 sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FSH_VAR_GROUP sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-DAUAT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-SERNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PROJN sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-UMSKZ sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PLGRP sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FLG_BUNDLE sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-LFDAT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-EKORG sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-EKGRP sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-LIFNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FLIEF sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-SOBSL sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-CSTATUS sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-KUNNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-KONNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-FRGDT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-BADAT sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PREIS sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-RESWK sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-IDNLF sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-INFNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-NAME1 sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-OBJNR sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PARTIAL_DEL_FLAG sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-ATTYP sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-TERKZ_TX sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-VERID sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-PLAUF sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-AUFLD sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-OFMNG sy-vline
WA_FSH_S_PCW_ORD_LIST_STR-GSMNG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.