ABAP Select data from SAP table WMON_PICK_WAVE 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 WMON_PICK_WAVE 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 WMON_PICK_WAVE. 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 WMON_PICK_WAVE 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_WMON_PICK_WAVE TYPE STANDARD TABLE OF WMON_PICK_WAVE,
      WA_WMON_PICK_WAVE TYPE WMON_PICK_WAVE,
      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: <WMON_PICK_WAVE> TYPE WMON_PICK_WAVE.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM WMON_PICK_WAVE
*  INTO TABLE @DATA(IT_WMON_PICK_WAVE2).
*--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_WMON_PICK_WAVE INDEX 1 INTO DATA(WA_WMON_PICK_WAVE2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_WMON_PICK_WAVE ASSIGNING <WMON_PICK_WAVE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<WMON_PICK_WAVE>-SAMMG = 1.
<WMON_PICK_WAVE>-ALV_CROSS = 1.
<WMON_PICK_WAVE>-ALV_EXPAND = 1.
<WMON_PICK_WAVE>-ERNAM = 1.
<WMON_PICK_WAVE>-BEDAT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_WMON_PICK_WAVE-BEGINNZT, sy-vline,
WA_WMON_PICK_WAVE-ENDEZT, sy-vline,
WA_WMON_PICK_WAVE-LVSTK_ICON, sy-vline,
WA_WMON_PICK_WAVE-LVSTK, sy-vline,
WA_WMON_PICK_WAVE-LVSTA_BEZ, sy-vline,
WA_WMON_PICK_WAVE-PKSTK_ICON, sy-vline.
ENDLOOP. *Add any further fields from structure WA_WMON_PICK_WAVE 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_WMON_PICK_WAVE 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_WMON_PICK_WAVE INTO WA_WMON_PICK_WAVE. *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 SAMMG CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_WMON_PICK_WAVE-SAMMG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_WMON_PICK_WAVE-SAMMG.
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_WMON_PICK_WAVE_STR,
SAMMG TYPE STRING,
ALV_CROSS TYPE STRING,
ALV_EXPAND TYPE STRING,
ERNAM TYPE STRING,
BEDAT TYPE STRING,
BEGINNZT TYPE STRING,
ENDEZT TYPE STRING,
LVSTK_ICON TYPE STRING,
LVSTK TYPE STRING,
LVSTA_BEZ TYPE STRING,
PKSTK_ICON TYPE STRING,
PKSTK TYPE STRING,
PKSTK_BEZ TYPE STRING,
TRSTA_ICON TYPE STRING,
TRSTA TYPE STRING,
TRSTA_BEZ TYPE STRING,
WBSTK_ICON TYPE STRING,
WBSTK TYPE STRING,
WBSTA_BEZ TYPE STRING,
FKSTK_ICON TYPE STRING,
FKSTK TYPE STRING,
FKSTA_BEZ TYPE STRING,
VESTK_ICON TYPE STRING,
VESTK TYPE STRING,
TOTAL_DEL TYPE STRING,
LVSTK_ABS TYPE STRING,
LVSTK_REL TYPE STRING,
PKSTK_ABS TYPE STRING,
PKSTK_REL TYPE STRING,
TRSTA_ABS TYPE STRING,
TRSTA_REL TYPE STRING,
WBSTK_ABS TYPE STRING,
WBSTK_REL TYPE STRING,
FKSTK_ABS TYPE STRING,
FKSTK_REL TYPE STRING,
ALV_DUMMY_1 TYPE STRING,
ALV_DUMMY_2 TYPE STRING,
ALV_DUMMY_3 TYPE STRING,
ALV_DUMMY_4 TYPE STRING,
ALV_DUMMY_5 TYPE STRING,
ALV_COLOUR TYPE STRING,END OF T_EKKO_STR. DATA: WA_WMON_PICK_WAVE_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_WMON_PICK_WAVE_STR-SAMMG sy-vline
WA_WMON_PICK_WAVE_STR-ALV_CROSS sy-vline
WA_WMON_PICK_WAVE_STR-ALV_EXPAND sy-vline
WA_WMON_PICK_WAVE_STR-ERNAM sy-vline
WA_WMON_PICK_WAVE_STR-BEDAT sy-vline
WA_WMON_PICK_WAVE_STR-BEGINNZT sy-vline
WA_WMON_PICK_WAVE_STR-ENDEZT sy-vline
WA_WMON_PICK_WAVE_STR-LVSTK_ICON sy-vline
WA_WMON_PICK_WAVE_STR-LVSTK sy-vline
WA_WMON_PICK_WAVE_STR-LVSTA_BEZ sy-vline
WA_WMON_PICK_WAVE_STR-PKSTK_ICON sy-vline
WA_WMON_PICK_WAVE_STR-PKSTK sy-vline
WA_WMON_PICK_WAVE_STR-PKSTK_BEZ sy-vline
WA_WMON_PICK_WAVE_STR-TRSTA_ICON sy-vline
WA_WMON_PICK_WAVE_STR-TRSTA sy-vline
WA_WMON_PICK_WAVE_STR-TRSTA_BEZ sy-vline
WA_WMON_PICK_WAVE_STR-WBSTK_ICON sy-vline
WA_WMON_PICK_WAVE_STR-WBSTK sy-vline
WA_WMON_PICK_WAVE_STR-WBSTA_BEZ sy-vline
WA_WMON_PICK_WAVE_STR-FKSTK_ICON sy-vline
WA_WMON_PICK_WAVE_STR-FKSTK sy-vline
WA_WMON_PICK_WAVE_STR-FKSTA_BEZ sy-vline
WA_WMON_PICK_WAVE_STR-VESTK_ICON sy-vline
WA_WMON_PICK_WAVE_STR-VESTK sy-vline
WA_WMON_PICK_WAVE_STR-TOTAL_DEL sy-vline
WA_WMON_PICK_WAVE_STR-LVSTK_ABS sy-vline
WA_WMON_PICK_WAVE_STR-LVSTK_REL sy-vline
WA_WMON_PICK_WAVE_STR-PKSTK_ABS sy-vline
WA_WMON_PICK_WAVE_STR-PKSTK_REL sy-vline
WA_WMON_PICK_WAVE_STR-TRSTA_ABS sy-vline
WA_WMON_PICK_WAVE_STR-TRSTA_REL sy-vline
WA_WMON_PICK_WAVE_STR-WBSTK_ABS sy-vline
WA_WMON_PICK_WAVE_STR-WBSTK_REL sy-vline
WA_WMON_PICK_WAVE_STR-FKSTK_ABS sy-vline
WA_WMON_PICK_WAVE_STR-FKSTK_REL sy-vline
WA_WMON_PICK_WAVE_STR-ALV_DUMMY_1 sy-vline
WA_WMON_PICK_WAVE_STR-ALV_DUMMY_2 sy-vline
WA_WMON_PICK_WAVE_STR-ALV_DUMMY_3 sy-vline
WA_WMON_PICK_WAVE_STR-ALV_DUMMY_4 sy-vline
WA_WMON_PICK_WAVE_STR-ALV_DUMMY_5 sy-vline
WA_WMON_PICK_WAVE_STR-ALV_COLOUR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.