ABAP Select data from SAP table E1VBUKF 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 E1VBUKF 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 E1VBUKF. 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 E1VBUKF 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_E1VBUKF TYPE STANDARD TABLE OF E1VBUKF, WA_E1VBUKF TYPE E1VBUKF, 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: <E1VBUKF> TYPE E1VBUKF. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_E1VBUKF. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM E1VBUKF INTO TABLE IT_E1VBUKF. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM E1VBUKF * INTO TABLE @DATA(IT_E1VBUKF2). *--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_E1VBUKF INDEX 1 INTO DATA(WA_E1VBUKF2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_E1VBUKF ASSIGNING <E1VBUKF>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<E1VBUKF>-SUPKZ = 1.
<E1VBUKF>-VBELN = 1.
<E1VBUKF>-RFSTK = 1.
<E1VBUKF>-RFGSK = 1.
<E1VBUKF>-BESTK = 1.
ENDLOOP. LOOP AT IT_E1VBUKF INTO WA_E1VBUKF. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_E1VBUKF-LFSTK, sy-vline,
WA_E1VBUKF-LFGSK, sy-vline,
WA_E1VBUKF-WBSTK, sy-vline,
WA_E1VBUKF-FKSTK, sy-vline,
WA_E1VBUKF-FKSAK, sy-vline,
WA_E1VBUKF-BUCHK, sy-vline.
ENDLOOP. *Add any further fields from structure WA_E1VBUKF 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_E1VBUKF 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_E1VBUKF INTO WA_E1VBUKF. *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_E1VBUKF_STR,
SUPKZ TYPE STRING,
VBELN TYPE STRING,
RFSTK TYPE STRING,
RFGSK TYPE STRING,
BESTK TYPE STRING,
LFSTK TYPE STRING,
LFGSK TYPE STRING,
WBSTK TYPE STRING,
FKSTK TYPE STRING,
FKSAK TYPE STRING,
BUCHK TYPE STRING,
ABSTK TYPE STRING,
GBSTK TYPE STRING,
KOSTK TYPE STRING,
LVSTK TYPE STRING,
UVALS TYPE STRING,
UVVLS TYPE STRING,
UVFAS TYPE STRING,
UVALL TYPE STRING,
UVVLK TYPE STRING,
UVFAK TYPE STRING,
UVPRS TYPE STRING,
VBTYP TYPE STRING,
VBOBJ TYPE STRING,
AEDAT TYPE STRING,
FKIVK TYPE STRING,
RELIK TYPE STRING,
UVK01 TYPE STRING,
UVK02 TYPE STRING,
UVK03 TYPE STRING,
UVK04 TYPE STRING,
UVK05 TYPE STRING,
UVS01 TYPE STRING,
UVS02 TYPE STRING,
UVS03 TYPE STRING,
UVS04 TYPE STRING,
UVS05 TYPE STRING,
PKSTK TYPE STRING,
CMPSA TYPE STRING,
CMPSB TYPE STRING,
CMPSC TYPE STRING,
CMPSD TYPE STRING,
CMPSE TYPE STRING,
CMPSF TYPE STRING,
CMPSG TYPE STRING,
CMPSH TYPE STRING,
CMPSI TYPE STRING,
CMPSJ TYPE STRING,
CMPSK TYPE STRING,
CMPSL TYPE STRING,
CMPS0 TYPE STRING,
CMPS1 TYPE STRING,
CMPS2 TYPE STRING,
CMGST TYPE STRING,
TRSTA TYPE STRING,
KOQUK TYPE STRING,
COSTA TYPE STRING,END OF T_EKKO_STR. DATA: WA_E1VBUKF_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_E1VBUKF_STR-SUPKZ sy-vline
WA_E1VBUKF_STR-VBELN sy-vline
WA_E1VBUKF_STR-RFSTK sy-vline
WA_E1VBUKF_STR-RFGSK sy-vline
WA_E1VBUKF_STR-BESTK sy-vline
WA_E1VBUKF_STR-LFSTK sy-vline
WA_E1VBUKF_STR-LFGSK sy-vline
WA_E1VBUKF_STR-WBSTK sy-vline
WA_E1VBUKF_STR-FKSTK sy-vline
WA_E1VBUKF_STR-FKSAK sy-vline
WA_E1VBUKF_STR-BUCHK sy-vline
WA_E1VBUKF_STR-ABSTK sy-vline
WA_E1VBUKF_STR-GBSTK sy-vline
WA_E1VBUKF_STR-KOSTK sy-vline
WA_E1VBUKF_STR-LVSTK sy-vline
WA_E1VBUKF_STR-UVALS sy-vline
WA_E1VBUKF_STR-UVVLS sy-vline
WA_E1VBUKF_STR-UVFAS sy-vline
WA_E1VBUKF_STR-UVALL sy-vline
WA_E1VBUKF_STR-UVVLK sy-vline
WA_E1VBUKF_STR-UVFAK sy-vline
WA_E1VBUKF_STR-UVPRS sy-vline
WA_E1VBUKF_STR-VBTYP sy-vline
WA_E1VBUKF_STR-VBOBJ sy-vline
WA_E1VBUKF_STR-AEDAT sy-vline
WA_E1VBUKF_STR-FKIVK sy-vline
WA_E1VBUKF_STR-RELIK sy-vline
WA_E1VBUKF_STR-UVK01 sy-vline
WA_E1VBUKF_STR-UVK02 sy-vline
WA_E1VBUKF_STR-UVK03 sy-vline
WA_E1VBUKF_STR-UVK04 sy-vline
WA_E1VBUKF_STR-UVK05 sy-vline
WA_E1VBUKF_STR-UVS01 sy-vline
WA_E1VBUKF_STR-UVS02 sy-vline
WA_E1VBUKF_STR-UVS03 sy-vline
WA_E1VBUKF_STR-UVS04 sy-vline
WA_E1VBUKF_STR-UVS05 sy-vline
WA_E1VBUKF_STR-PKSTK sy-vline
WA_E1VBUKF_STR-CMPSA sy-vline
WA_E1VBUKF_STR-CMPSB sy-vline
WA_E1VBUKF_STR-CMPSC sy-vline
WA_E1VBUKF_STR-CMPSD sy-vline
WA_E1VBUKF_STR-CMPSE sy-vline
WA_E1VBUKF_STR-CMPSF sy-vline
WA_E1VBUKF_STR-CMPSG sy-vline
WA_E1VBUKF_STR-CMPSH sy-vline
WA_E1VBUKF_STR-CMPSI sy-vline
WA_E1VBUKF_STR-CMPSJ sy-vline
WA_E1VBUKF_STR-CMPSK sy-vline
WA_E1VBUKF_STR-CMPSL sy-vline
WA_E1VBUKF_STR-CMPS0 sy-vline
WA_E1VBUKF_STR-CMPS1 sy-vline
WA_E1VBUKF_STR-CMPS2 sy-vline
WA_E1VBUKF_STR-CMGST sy-vline
WA_E1VBUKF_STR-TRSTA sy-vline
WA_E1VBUKF_STR-KOQUK sy-vline
WA_E1VBUKF_STR-COSTA sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.