ABAP Select data from SAP table PKW_HKWPPVN0_ALV 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 PKW_HKWPPVN0_ALV 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 PKW_HKWPPVN0_ALV. 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 PKW_HKWPPVN0_ALV 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_PKW_HKWPPVN0_ALV TYPE STANDARD TABLE OF PKW_HKWPPVN0_ALV,
      WA_PKW_HKWPPVN0_ALV TYPE PKW_HKWPPVN0_ALV,
      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: <PKW_HKWPPVN0_ALV> TYPE PKW_HKWPPVN0_ALV.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PKW_HKWPPVN0_ALV
*  INTO TABLE @DATA(IT_PKW_HKWPPVN0_ALV2).
*--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_PKW_HKWPPVN0_ALV INDEX 1 INTO DATA(WA_PKW_HKWPPVN0_ALV2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PKW_HKWPPVN0_ALV ASSIGNING <PKW_HKWPPVN0_ALV>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PKW_HKWPPVN0_ALV>-PERNR = 1.
<PKW_HKWPPVN0_ALV>-FNAME = 1.
<PKW_HKWPPVN0_ALV>-BUKRS = 1.
<PKW_HKWPPVN0_ALV>-PVNP1 = 1.
<PKW_HKWPPVN0_ALV>-PVNC1 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PKW_HKWPPVN0_ALV-PVND1, sy-vline,
WA_PKW_HKWPPVN0_ALV-PVNP2, sy-vline,
WA_PKW_HKWPPVN0_ALV-PVNC2, sy-vline,
WA_PKW_HKWPPVN0_ALV-PVND2, sy-vline,
WA_PKW_HKWPPVN0_ALV-PVNP3, sy-vline,
WA_PKW_HKWPPVN0_ALV-PVNC3, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PKW_HKWPPVN0_ALV 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_PKW_HKWPPVN0_ALV 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_PKW_HKWPPVN0_ALV INTO WA_PKW_HKWPPVN0_ALV. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PKW_HKWPPVN0_ALV_STR,
PERNR TYPE STRING,
FNAME TYPE STRING,
BUKRS TYPE STRING,
PVNP1 TYPE STRING,
PVNC1 TYPE STRING,
PVND1 TYPE STRING,
PVNP2 TYPE STRING,
PVNC2 TYPE STRING,
PVND2 TYPE STRING,
PVNP3 TYPE STRING,
PVNC3 TYPE STRING,
PVND3 TYPE STRING,
PVNP4 TYPE STRING,
PVNC4 TYPE STRING,
PVND4 TYPE STRING,
PVNP5 TYPE STRING,
PVNC5 TYPE STRING,
PVND5 TYPE STRING,
PVNP6 TYPE STRING,
PVNC6 TYPE STRING,
PVND6 TYPE STRING,
PVNP7 TYPE STRING,
PVNC7 TYPE STRING,
PVND7 TYPE STRING,
PVNP8 TYPE STRING,
PVNC8 TYPE STRING,
PVND8 TYPE STRING,
PVNP9 TYPE STRING,
PVNC9 TYPE STRING,
PVND9 TYPE STRING,
PVNP10 TYPE STRING,
PVNC10 TYPE STRING,
PVND10 TYPE STRING,
PVNP11 TYPE STRING,
PVNC11 TYPE STRING,
PVND11 TYPE STRING,
PVNP12 TYPE STRING,
PVNC12 TYPE STRING,
PVND12 TYPE STRING,
PVNP13 TYPE STRING,
PVNC13 TYPE STRING,
PVND13 TYPE STRING,
PVNP14 TYPE STRING,
PVNC14 TYPE STRING,
PVND14 TYPE STRING,
PVNP15 TYPE STRING,
PVNC15 TYPE STRING,
PVND15 TYPE STRING,
PVNP16 TYPE STRING,
PVNC16 TYPE STRING,
PVND16 TYPE STRING,
PVNP17 TYPE STRING,
PVNC17 TYPE STRING,
PVND17 TYPE STRING,
PVNP18 TYPE STRING,
PVNC18 TYPE STRING,
PVND18 TYPE STRING,
PVNP19 TYPE STRING,
PVNC19 TYPE STRING,
PVND19 TYPE STRING,
PVNP20 TYPE STRING,
PVNC20 TYPE STRING,
PVND20 TYPE STRING,
WAERS TYPE STRING,END OF T_EKKO_STR. DATA: WA_PKW_HKWPPVN0_ALV_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_PKW_HKWPPVN0_ALV_STR-PERNR sy-vline
WA_PKW_HKWPPVN0_ALV_STR-FNAME sy-vline
WA_PKW_HKWPPVN0_ALV_STR-BUKRS sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP1 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC1 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND1 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP2 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC2 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND2 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP3 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC3 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND3 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP4 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC4 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND4 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP5 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC5 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND5 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP6 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC6 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND6 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP7 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC7 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND7 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP8 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC8 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND8 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP9 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC9 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND9 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP10 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC10 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND10 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP11 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC11 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND11 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP12 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC12 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND12 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP13 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC13 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND13 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP14 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC14 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND14 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP15 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC15 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND15 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP16 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC16 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND16 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP17 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC17 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND17 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP18 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC18 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND18 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP19 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC19 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND19 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNP20 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVNC20 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-PVND20 sy-vline
WA_PKW_HKWPPVN0_ALV_STR-WAERS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.