ABAP Select data from SAP table WVKP_PRICING_DOC_STY 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 WVKP_PRICING_DOC_STY 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 WVKP_PRICING_DOC_STY. 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 WVKP_PRICING_DOC_STY 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_WVKP_PRICING_DOC_STY TYPE STANDARD TABLE OF WVKP_PRICING_DOC_STY,
      WA_WVKP_PRICING_DOC_STY TYPE WVKP_PRICING_DOC_STY,
      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: <WVKP_PRICING_DOC_STY> TYPE WVKP_PRICING_DOC_STY.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM WVKP_PRICING_DOC_STY
*  INTO TABLE @DATA(IT_WVKP_PRICING_DOC_STY2).
*--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_WVKP_PRICING_DOC_STY INDEX 1 INTO DATA(WA_WVKP_PRICING_DOC_STY2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_WVKP_PRICING_DOC_STY ASSIGNING <WVKP_PRICING_DOC_STY>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<WVKP_PRICING_DOC_STY>-KBELN = 1.
<WVKP_PRICING_DOC_STY>-KBELP = 1.
<WVKP_PRICING_DOC_STY>-ERNAM = 1.
<WVKP_PRICING_DOC_STY>-ERDAT = 1.
<WVKP_PRICING_DOC_STY>-LIGRU = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_WVKP_PRICING_DOC_STY-LIVAR, sy-vline,
WA_WVKP_PRICING_DOC_STY-KBART, sy-vline,
WA_WVKP_PRICING_DOC_STY-ESTAR, sy-vline,
WA_WVKP_PRICING_DOC_STY-ERZET, sy-vline,
WA_WVKP_PRICING_DOC_STY-AENAM, sy-vline,
WA_WVKP_PRICING_DOC_STY-AEDAT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_WVKP_PRICING_DOC_STY 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_WVKP_PRICING_DOC_STY 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_WVKP_PRICING_DOC_STY INTO WA_WVKP_PRICING_DOC_STY. *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 KBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_WVKP_PRICING_DOC_STY-KBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_WVKP_PRICING_DOC_STY-KBELN.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit EAN11, internal->external for field EAN11 CALL FUNCTION 'CONVERSION_EXIT_EAN11_OUTPUT' EXPORTING input = WA_WVKP_PRICING_DOC_STY-EAN11 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_WVKP_PRICING_DOC_STY-EAN11.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit KOTAB, internal->external for field VKOTABN CALL FUNCTION 'CONVERSION_EXIT_KOTAB_OUTPUT' EXPORTING input = WA_WVKP_PRICING_DOC_STY-VKOTABN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_WVKP_PRICING_DOC_STY-VKOTABN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit KOTAB, internal->external for field VKOTABA CALL FUNCTION 'CONVERSION_EXIT_KOTAB_OUTPUT' EXPORTING input = WA_WVKP_PRICING_DOC_STY-VKOTABA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_WVKP_PRICING_DOC_STY-VKOTABA.
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_WVKP_PRICING_DOC_STY_STR,
KBELN TYPE STRING,
KBELP TYPE STRING,
ERNAM TYPE STRING,
ERDAT TYPE STRING,
LIGRU TYPE STRING,
LIVAR TYPE STRING,
KBART TYPE STRING,
ESTAR TYPE STRING,
ERZET TYPE STRING,
AENAM TYPE STRING,
AEDAT TYPE STRING,
VORGA TYPE STRING,
FRBNR TYPE STRING,
EKKAB TYPE STRING,
EKKBI TYPE STRING,
VKKAB TYPE STRING,
VKKBI TYPE STRING,
EKNUM TYPE STRING,
VKNUM TYPE STRING,
EKAPP TYPE STRING,
EKALS TYPE STRING,
VKALS TYPE STRING,
MATKL TYPE STRING,
MATNR TYPE STRING,
VRKPE TYPE STRING,
VRKME TYPE STRING,
EAN11 TYPE STRING,
VKORG TYPE STRING,
VTWEG TYPE STRING,
WERKS TYPE STRING,
EKORG TYPE STRING,
HWAER TYPE STRING,
LIFNR TYPE STRING,
LTSNR TYPE STRING,
WAERS TYPE STRING,
EKPGR TYPE STRING,
EKPNN TYPE STRING,
AUFSG TYPE STRING,
PAUFS TYPE STRING,
PENDP TYPE STRING,
VKPNE TYPE STRING,
VKPBR TYPE STRING,
KWAER TYPE STRING,
ENDPR TYPE STRING,
SPANE TYPE STRING,
SPABR TYPE STRING,
ENDPA TYPE STRING,
SPANA TYPE STRING,
SPABA TYPE STRING,
ROTPR TYPE STRING,
MITPR TYPE STRING,
EMPPR TYPE STRING,
VORPR TYPE STRING,
VKP01 TYPE STRING,
VKP02 TYPE STRING,
VKP03 TYPE STRING,
PROZ1 TYPE STRING,
PROZ2 TYPE STRING,
EVAUF TYPE STRING,
EVPRS TYPE STRING,
EVSPA TYPE STRING,
BPSTA TYPE STRING,
PLTYP TYPE STRING,
VKABA TYPE STRING,
VKBIA TYPE STRING,
INFWK TYPE STRING,
ESOKZ TYPE STRING,
EVPAU TYPE STRING,
CKNUM TYPE STRING,
VWAER TYPE STRING,
EVWRS TYPE STRING,
EGKAL TYPE STRING,
INIPR TYPE STRING,
KNUMH_V TYPE STRING,
EKERV TYPE STRING,
BWERA TYPE STRING,
EKERA TYPE STRING,
EFNAM TYPE STRING,
VKERV TYPE STRING,
VKERA TYPE STRING,
LIFEL TYPE STRING,
ECKKZ TYPE STRING,
PVGRD TYPE STRING,
FAMNR TYPE STRING,
GRP01 TYPE STRING,
FMTYP TYPE STRING,
SMATN TYPE STRING,
FCHAL TYPE STRING,
FHIDE TYPE STRING,
EPRGR TYPE STRING,
EPRG2 TYPE STRING,
NEPGR TYPE STRING,
NEPG2 TYPE STRING,
INIAM TYPE STRING,
EPTYP TYPE STRING,
EPTY2 TYPE STRING,
RKTYP TYPE STRING,
RKTY2 TYPE STRING,
BGINT TYPE STRING,
STPLGR TYPE STRING,
VLGWK TYPE STRING,
KALEB TYPE STRING,
VKSCH TYPE STRING,
VKOTABN TYPE STRING,
KALEA TYPE STRING,
VKSCA TYPE STRING,
VKOTABA TYPE STRING,
FILGR TYPE STRING,
MAKT_MAKTX TYPE STRING,
T006A_MSEHT TYPE STRING,
TVKOT_VTEXT TYPE STRING,
TVTWT_VTEXT TYPE STRING,
T001W_NAME1 TYPE STRING,
T189T_PTEXT TYPE STRING,
UPDKZ TYPE STRING,
SELKZ TYPE STRING,
BPSTA_ALT TYPE STRING,END OF T_EKKO_STR. DATA: WA_WVKP_PRICING_DOC_STY_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_WVKP_PRICING_DOC_STY_STR-KBELN sy-vline
WA_WVKP_PRICING_DOC_STY_STR-KBELP sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ERNAM sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ERDAT sy-vline
WA_WVKP_PRICING_DOC_STY_STR-LIGRU sy-vline
WA_WVKP_PRICING_DOC_STY_STR-LIVAR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-KBART sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ESTAR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ERZET sy-vline
WA_WVKP_PRICING_DOC_STY_STR-AENAM sy-vline
WA_WVKP_PRICING_DOC_STY_STR-AEDAT sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VORGA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-FRBNR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKKAB sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKKBI sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKKAB sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKKBI sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKNUM sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKNUM sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKAPP sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKALS sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKALS sy-vline
WA_WVKP_PRICING_DOC_STY_STR-MATKL sy-vline
WA_WVKP_PRICING_DOC_STY_STR-MATNR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VRKPE sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VRKME sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EAN11 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKORG sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VTWEG sy-vline
WA_WVKP_PRICING_DOC_STY_STR-WERKS sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKORG sy-vline
WA_WVKP_PRICING_DOC_STY_STR-HWAER sy-vline
WA_WVKP_PRICING_DOC_STY_STR-LIFNR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-LTSNR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-WAERS sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKPGR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKPNN sy-vline
WA_WVKP_PRICING_DOC_STY_STR-AUFSG sy-vline
WA_WVKP_PRICING_DOC_STY_STR-PAUFS sy-vline
WA_WVKP_PRICING_DOC_STY_STR-PENDP sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKPNE sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKPBR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-KWAER sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ENDPR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-SPANE sy-vline
WA_WVKP_PRICING_DOC_STY_STR-SPABR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ENDPA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-SPANA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-SPABA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ROTPR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-MITPR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EMPPR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VORPR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKP01 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKP02 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKP03 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-PROZ1 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-PROZ2 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EVAUF sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EVPRS sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EVSPA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-BPSTA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-PLTYP sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKABA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKBIA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-INFWK sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ESOKZ sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EVPAU sy-vline
WA_WVKP_PRICING_DOC_STY_STR-CKNUM sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VWAER sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EVWRS sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EGKAL sy-vline
WA_WVKP_PRICING_DOC_STY_STR-INIPR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-KNUMH_V sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKERV sy-vline
WA_WVKP_PRICING_DOC_STY_STR-BWERA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EKERA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EFNAM sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKERV sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKERA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-LIFEL sy-vline
WA_WVKP_PRICING_DOC_STY_STR-ECKKZ sy-vline
WA_WVKP_PRICING_DOC_STY_STR-PVGRD sy-vline
WA_WVKP_PRICING_DOC_STY_STR-FAMNR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-GRP01 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-FMTYP sy-vline
WA_WVKP_PRICING_DOC_STY_STR-SMATN sy-vline
WA_WVKP_PRICING_DOC_STY_STR-FCHAL sy-vline
WA_WVKP_PRICING_DOC_STY_STR-FHIDE sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EPRGR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EPRG2 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-NEPGR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-NEPG2 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-INIAM sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EPTYP sy-vline
WA_WVKP_PRICING_DOC_STY_STR-EPTY2 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-RKTYP sy-vline
WA_WVKP_PRICING_DOC_STY_STR-RKTY2 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-BGINT sy-vline
WA_WVKP_PRICING_DOC_STY_STR-STPLGR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VLGWK sy-vline
WA_WVKP_PRICING_DOC_STY_STR-KALEB sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKSCH sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKOTABN sy-vline
WA_WVKP_PRICING_DOC_STY_STR-KALEA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKSCA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-VKOTABA sy-vline
WA_WVKP_PRICING_DOC_STY_STR-FILGR sy-vline
WA_WVKP_PRICING_DOC_STY_STR-MAKT_MAKTX sy-vline
WA_WVKP_PRICING_DOC_STY_STR-T006A_MSEHT sy-vline
WA_WVKP_PRICING_DOC_STY_STR-TVKOT_VTEXT sy-vline
WA_WVKP_PRICING_DOC_STY_STR-TVTWT_VTEXT sy-vline
WA_WVKP_PRICING_DOC_STY_STR-T001W_NAME1 sy-vline
WA_WVKP_PRICING_DOC_STY_STR-T189T_PTEXT sy-vline
WA_WVKP_PRICING_DOC_STY_STR-UPDKZ sy-vline
WA_WVKP_PRICING_DOC_STY_STR-SELKZ sy-vline
WA_WVKP_PRICING_DOC_STY_STR-BPSTA_ALT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.