ABAP Select data from SAP table VFKK_VBAK_SHORT 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 VFKK_VBAK_SHORT 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 VFKK_VBAK_SHORT. 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 VFKK_VBAK_SHORT 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_VFKK_VBAK_SHORT TYPE STANDARD TABLE OF VFKK_VBAK_SHORT,
      WA_VFKK_VBAK_SHORT TYPE VFKK_VBAK_SHORT,
      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: <VFKK_VBAK_SHORT> TYPE VFKK_VBAK_SHORT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM VFKK_VBAK_SHORT
*  INTO TABLE @DATA(IT_VFKK_VBAK_SHORT2).
*--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_VFKK_VBAK_SHORT INDEX 1 INTO DATA(WA_VFKK_VBAK_SHORT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_VFKK_VBAK_SHORT ASSIGNING <VFKK_VBAK_SHORT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<VFKK_VBAK_SHORT>-VBELN = 1.
<VFKK_VBAK_SHORT>-ERDAT = 1.
<VFKK_VBAK_SHORT>-ERZET = 1.
<VFKK_VBAK_SHORT>-ERNAM = 1.
<VFKK_VBAK_SHORT>-ANGDT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_VFKK_VBAK_SHORT-BNDDT, sy-vline,
WA_VFKK_VBAK_SHORT-AUDAT, sy-vline,
WA_VFKK_VBAK_SHORT-VBTYP, sy-vline,
WA_VFKK_VBAK_SHORT-TRVOG, sy-vline,
WA_VFKK_VBAK_SHORT-AUART, sy-vline,
WA_VFKK_VBAK_SHORT-AUGRU, sy-vline.
ENDLOOP. *Add any further fields from structure WA_VFKK_VBAK_SHORT 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_VFKK_VBAK_SHORT 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_VFKK_VBAK_SHORT INTO WA_VFKK_VBAK_SHORT. *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 VBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VFKK_VBAK_SHORT-VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VFKK_VBAK_SHORT-VBELN.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

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

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

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

*Conversion exit ALPHA, internal->external for field MSR_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VFKK_VBAK_SHORT-MSR_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VFKK_VBAK_SHORT-MSR_ID.
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_VFKK_VBAK_SHORT_STR,
VBELN TYPE STRING,
ERDAT TYPE STRING,
ERZET TYPE STRING,
ERNAM TYPE STRING,
ANGDT TYPE STRING,
BNDDT TYPE STRING,
AUDAT TYPE STRING,
VBTYP TYPE STRING,
TRVOG TYPE STRING,
AUART TYPE STRING,
AUGRU TYPE STRING,
GWLDT TYPE STRING,
SUBMI TYPE STRING,
LIFSK TYPE STRING,
FAKSK TYPE STRING,
NETWR TYPE STRING,
WAERK TYPE STRING,
VKORG TYPE STRING,
VTWEG TYPE STRING,
SPART TYPE STRING,
VKGRP TYPE STRING,
VKBUR TYPE STRING,
GSBER TYPE STRING,
GSKST TYPE STRING,
GUEBG TYPE STRING,
GUEEN TYPE STRING,
KNUMV TYPE STRING,
VDATU TYPE STRING,
VPRGR TYPE STRING,
AUTLF TYPE STRING,
VBKLA TYPE STRING,
VBKLT TYPE STRING,
KALSM TYPE STRING,
VSBED TYPE STRING,
FKARA TYPE STRING,
AWAHR TYPE STRING,
KTEXT TYPE STRING,
BSTNK TYPE STRING,
BSARK TYPE STRING,
BSTDK TYPE STRING,
BSTZD TYPE STRING,
IHREZ TYPE STRING,
BNAME TYPE STRING,
TELF1 TYPE STRING,
MAHZA TYPE STRING,
MAHDT TYPE STRING,
KUNNR TYPE STRING,
KOSTL TYPE STRING,
STAFO TYPE STRING,
STWAE TYPE STRING,
AEDAT TYPE STRING,
KVGR1 TYPE STRING,
KVGR2 TYPE STRING,
KVGR3 TYPE STRING,
KVGR4 TYPE STRING,
KVGR5 TYPE STRING,
KNUMA TYPE STRING,
KOKRS TYPE STRING,
PS_PSP_PNR TYPE STRING,
KURST TYPE STRING,
KKBER TYPE STRING,
KNKLI TYPE STRING,
GRUPP TYPE STRING,
SBGRP TYPE STRING,
CTLPC TYPE STRING,
CMWAE TYPE STRING,
CMFRE TYPE STRING,
CMNUP TYPE STRING,
CMNGV TYPE STRING,
AMTBL TYPE STRING,
HITYP_PR TYPE STRING,
ABRVW TYPE STRING,
ABDIS TYPE STRING,
VGBEL TYPE STRING,
OBJNR TYPE STRING,
BUKRS_VF TYPE STRING,
TAXK1 TYPE STRING,
TAXK2 TYPE STRING,
TAXK3 TYPE STRING,
TAXK4 TYPE STRING,
TAXK5 TYPE STRING,
TAXK6 TYPE STRING,
TAXK7 TYPE STRING,
TAXK8 TYPE STRING,
TAXK9 TYPE STRING,
XBLNR TYPE STRING,
ZUONR TYPE STRING,
VGTYP TYPE STRING,
KALSM_CH TYPE STRING,
AGRZR TYPE STRING,
AUFNR TYPE STRING,
QMNUM TYPE STRING,
VBELN_GRP TYPE STRING,
SCHEME_GRP TYPE STRING,
ABRUF_PART TYPE STRING,
ABHOD TYPE STRING,
ABHOV TYPE STRING,
ABHOB TYPE STRING,
RPLNR TYPE STRING,
VZEIT TYPE STRING,
STCEG_L TYPE STRING,
LANDTX TYPE STRING,
XEGDR TYPE STRING,
ENQUEUE_GRP TYPE STRING,
DAT_FZAU TYPE STRING,
FMBDAT TYPE STRING,
VSNMR_V TYPE STRING,
HANDLE TYPE STRING,
PROLI TYPE STRING,
CONT_DG TYPE STRING,
CRM_GUID TYPE STRING,
UPD_TMSTMP TYPE STRING,
MSR_ID TYPE STRING,
TM_CTRL_KEY TYPE STRING,
VBTYP_LONG TYPE STRING,
VGTYP_LONG TYPE STRING,END OF T_EKKO_STR. DATA: WA_VFKK_VBAK_SHORT_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_VFKK_VBAK_SHORT_STR-VBELN sy-vline
WA_VFKK_VBAK_SHORT_STR-ERDAT sy-vline
WA_VFKK_VBAK_SHORT_STR-ERZET sy-vline
WA_VFKK_VBAK_SHORT_STR-ERNAM sy-vline
WA_VFKK_VBAK_SHORT_STR-ANGDT sy-vline
WA_VFKK_VBAK_SHORT_STR-BNDDT sy-vline
WA_VFKK_VBAK_SHORT_STR-AUDAT sy-vline
WA_VFKK_VBAK_SHORT_STR-VBTYP sy-vline
WA_VFKK_VBAK_SHORT_STR-TRVOG sy-vline
WA_VFKK_VBAK_SHORT_STR-AUART sy-vline
WA_VFKK_VBAK_SHORT_STR-AUGRU sy-vline
WA_VFKK_VBAK_SHORT_STR-GWLDT sy-vline
WA_VFKK_VBAK_SHORT_STR-SUBMI sy-vline
WA_VFKK_VBAK_SHORT_STR-LIFSK sy-vline
WA_VFKK_VBAK_SHORT_STR-FAKSK sy-vline
WA_VFKK_VBAK_SHORT_STR-NETWR sy-vline
WA_VFKK_VBAK_SHORT_STR-WAERK sy-vline
WA_VFKK_VBAK_SHORT_STR-VKORG sy-vline
WA_VFKK_VBAK_SHORT_STR-VTWEG sy-vline
WA_VFKK_VBAK_SHORT_STR-SPART sy-vline
WA_VFKK_VBAK_SHORT_STR-VKGRP sy-vline
WA_VFKK_VBAK_SHORT_STR-VKBUR sy-vline
WA_VFKK_VBAK_SHORT_STR-GSBER sy-vline
WA_VFKK_VBAK_SHORT_STR-GSKST sy-vline
WA_VFKK_VBAK_SHORT_STR-GUEBG sy-vline
WA_VFKK_VBAK_SHORT_STR-GUEEN sy-vline
WA_VFKK_VBAK_SHORT_STR-KNUMV sy-vline
WA_VFKK_VBAK_SHORT_STR-VDATU sy-vline
WA_VFKK_VBAK_SHORT_STR-VPRGR sy-vline
WA_VFKK_VBAK_SHORT_STR-AUTLF sy-vline
WA_VFKK_VBAK_SHORT_STR-VBKLA sy-vline
WA_VFKK_VBAK_SHORT_STR-VBKLT sy-vline
WA_VFKK_VBAK_SHORT_STR-KALSM sy-vline
WA_VFKK_VBAK_SHORT_STR-VSBED sy-vline
WA_VFKK_VBAK_SHORT_STR-FKARA sy-vline
WA_VFKK_VBAK_SHORT_STR-AWAHR sy-vline
WA_VFKK_VBAK_SHORT_STR-KTEXT sy-vline
WA_VFKK_VBAK_SHORT_STR-BSTNK sy-vline
WA_VFKK_VBAK_SHORT_STR-BSARK sy-vline
WA_VFKK_VBAK_SHORT_STR-BSTDK sy-vline
WA_VFKK_VBAK_SHORT_STR-BSTZD sy-vline
WA_VFKK_VBAK_SHORT_STR-IHREZ sy-vline
WA_VFKK_VBAK_SHORT_STR-BNAME sy-vline
WA_VFKK_VBAK_SHORT_STR-TELF1 sy-vline
WA_VFKK_VBAK_SHORT_STR-MAHZA sy-vline
WA_VFKK_VBAK_SHORT_STR-MAHDT sy-vline
WA_VFKK_VBAK_SHORT_STR-KUNNR sy-vline
WA_VFKK_VBAK_SHORT_STR-KOSTL sy-vline
WA_VFKK_VBAK_SHORT_STR-STAFO sy-vline
WA_VFKK_VBAK_SHORT_STR-STWAE sy-vline
WA_VFKK_VBAK_SHORT_STR-AEDAT sy-vline
WA_VFKK_VBAK_SHORT_STR-KVGR1 sy-vline
WA_VFKK_VBAK_SHORT_STR-KVGR2 sy-vline
WA_VFKK_VBAK_SHORT_STR-KVGR3 sy-vline
WA_VFKK_VBAK_SHORT_STR-KVGR4 sy-vline
WA_VFKK_VBAK_SHORT_STR-KVGR5 sy-vline
WA_VFKK_VBAK_SHORT_STR-KNUMA sy-vline
WA_VFKK_VBAK_SHORT_STR-KOKRS sy-vline
WA_VFKK_VBAK_SHORT_STR-PS_PSP_PNR sy-vline
WA_VFKK_VBAK_SHORT_STR-KURST sy-vline
WA_VFKK_VBAK_SHORT_STR-KKBER sy-vline
WA_VFKK_VBAK_SHORT_STR-KNKLI sy-vline
WA_VFKK_VBAK_SHORT_STR-GRUPP sy-vline
WA_VFKK_VBAK_SHORT_STR-SBGRP sy-vline
WA_VFKK_VBAK_SHORT_STR-CTLPC sy-vline
WA_VFKK_VBAK_SHORT_STR-CMWAE sy-vline
WA_VFKK_VBAK_SHORT_STR-CMFRE sy-vline
WA_VFKK_VBAK_SHORT_STR-CMNUP sy-vline
WA_VFKK_VBAK_SHORT_STR-CMNGV sy-vline
WA_VFKK_VBAK_SHORT_STR-AMTBL sy-vline
WA_VFKK_VBAK_SHORT_STR-HITYP_PR sy-vline
WA_VFKK_VBAK_SHORT_STR-ABRVW sy-vline
WA_VFKK_VBAK_SHORT_STR-ABDIS sy-vline
WA_VFKK_VBAK_SHORT_STR-VGBEL sy-vline
WA_VFKK_VBAK_SHORT_STR-OBJNR sy-vline
WA_VFKK_VBAK_SHORT_STR-BUKRS_VF sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK1 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK2 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK3 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK4 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK5 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK6 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK7 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK8 sy-vline
WA_VFKK_VBAK_SHORT_STR-TAXK9 sy-vline
WA_VFKK_VBAK_SHORT_STR-XBLNR sy-vline
WA_VFKK_VBAK_SHORT_STR-ZUONR sy-vline
WA_VFKK_VBAK_SHORT_STR-VGTYP sy-vline
WA_VFKK_VBAK_SHORT_STR-KALSM_CH sy-vline
WA_VFKK_VBAK_SHORT_STR-AGRZR sy-vline
WA_VFKK_VBAK_SHORT_STR-AUFNR sy-vline
WA_VFKK_VBAK_SHORT_STR-QMNUM sy-vline
WA_VFKK_VBAK_SHORT_STR-VBELN_GRP sy-vline
WA_VFKK_VBAK_SHORT_STR-SCHEME_GRP sy-vline
WA_VFKK_VBAK_SHORT_STR-ABRUF_PART sy-vline
WA_VFKK_VBAK_SHORT_STR-ABHOD sy-vline
WA_VFKK_VBAK_SHORT_STR-ABHOV sy-vline
WA_VFKK_VBAK_SHORT_STR-ABHOB sy-vline
WA_VFKK_VBAK_SHORT_STR-RPLNR sy-vline
WA_VFKK_VBAK_SHORT_STR-VZEIT sy-vline
WA_VFKK_VBAK_SHORT_STR-STCEG_L sy-vline
WA_VFKK_VBAK_SHORT_STR-LANDTX sy-vline
WA_VFKK_VBAK_SHORT_STR-XEGDR sy-vline
WA_VFKK_VBAK_SHORT_STR-ENQUEUE_GRP sy-vline
WA_VFKK_VBAK_SHORT_STR-DAT_FZAU sy-vline
WA_VFKK_VBAK_SHORT_STR-FMBDAT sy-vline
WA_VFKK_VBAK_SHORT_STR-VSNMR_V sy-vline
WA_VFKK_VBAK_SHORT_STR-HANDLE sy-vline
WA_VFKK_VBAK_SHORT_STR-PROLI sy-vline
WA_VFKK_VBAK_SHORT_STR-CONT_DG sy-vline
WA_VFKK_VBAK_SHORT_STR-CRM_GUID sy-vline
WA_VFKK_VBAK_SHORT_STR-UPD_TMSTMP sy-vline
WA_VFKK_VBAK_SHORT_STR-MSR_ID sy-vline
WA_VFKK_VBAK_SHORT_STR-TM_CTRL_KEY sy-vline
WA_VFKK_VBAK_SHORT_STR-VBTYP_LONG sy-vline
WA_VFKK_VBAK_SHORT_STR-VGTYP_LONG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.