ABAP Select data from SAP table E1FVBUK 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 E1FVBUK 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 E1FVBUK. 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 E1FVBUK 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_E1FVBUK TYPE STANDARD TABLE OF E1FVBUK,
      WA_E1FVBUK TYPE E1FVBUK,
      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: <E1FVBUK> TYPE E1FVBUK.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM E1FVBUK
*  INTO TABLE @DATA(IT_E1FVBUK2).
*--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_E1FVBUK INDEX 1 INTO DATA(WA_E1FVBUK2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_E1FVBUK ASSIGNING <E1FVBUK>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<E1FVBUK>-SUPKZ = 1.
<E1FVBUK>-VBELN = 1.
<E1FVBUK>-RFSTK = 1.
<E1FVBUK>-RFGSK = 1.
<E1FVBUK>-BESTK = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_E1FVBUK-LFSTK, sy-vline,
WA_E1FVBUK-LFGSK, sy-vline,
WA_E1FVBUK-WBSTK, sy-vline,
WA_E1FVBUK-FKSTK, sy-vline,
WA_E1FVBUK-FKSAK, sy-vline,
WA_E1FVBUK-BUCHK, sy-vline.
ENDLOOP. *Add any further fields from structure WA_E1FVBUK 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_E1FVBUK 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_E1FVBUK INTO WA_E1FVBUK. *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_E1FVBUK_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_E1FVBUK_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_E1FVBUK_STR-SUPKZ sy-vline
WA_E1FVBUK_STR-VBELN sy-vline
WA_E1FVBUK_STR-RFSTK sy-vline
WA_E1FVBUK_STR-RFGSK sy-vline
WA_E1FVBUK_STR-BESTK sy-vline
WA_E1FVBUK_STR-LFSTK sy-vline
WA_E1FVBUK_STR-LFGSK sy-vline
WA_E1FVBUK_STR-WBSTK sy-vline
WA_E1FVBUK_STR-FKSTK sy-vline
WA_E1FVBUK_STR-FKSAK sy-vline
WA_E1FVBUK_STR-BUCHK sy-vline
WA_E1FVBUK_STR-ABSTK sy-vline
WA_E1FVBUK_STR-GBSTK sy-vline
WA_E1FVBUK_STR-KOSTK sy-vline
WA_E1FVBUK_STR-LVSTK sy-vline
WA_E1FVBUK_STR-UVALS sy-vline
WA_E1FVBUK_STR-UVVLS sy-vline
WA_E1FVBUK_STR-UVFAS sy-vline
WA_E1FVBUK_STR-UVALL sy-vline
WA_E1FVBUK_STR-UVVLK sy-vline
WA_E1FVBUK_STR-UVFAK sy-vline
WA_E1FVBUK_STR-UVPRS sy-vline
WA_E1FVBUK_STR-VBTYP sy-vline
WA_E1FVBUK_STR-VBOBJ sy-vline
WA_E1FVBUK_STR-AEDAT sy-vline
WA_E1FVBUK_STR-FKIVK sy-vline
WA_E1FVBUK_STR-RELIK sy-vline
WA_E1FVBUK_STR-UVK01 sy-vline
WA_E1FVBUK_STR-UVK02 sy-vline
WA_E1FVBUK_STR-UVK03 sy-vline
WA_E1FVBUK_STR-UVK04 sy-vline
WA_E1FVBUK_STR-UVK05 sy-vline
WA_E1FVBUK_STR-UVS01 sy-vline
WA_E1FVBUK_STR-UVS02 sy-vline
WA_E1FVBUK_STR-UVS03 sy-vline
WA_E1FVBUK_STR-UVS04 sy-vline
WA_E1FVBUK_STR-UVS05 sy-vline
WA_E1FVBUK_STR-PKSTK sy-vline
WA_E1FVBUK_STR-CMPSA sy-vline
WA_E1FVBUK_STR-CMPSB sy-vline
WA_E1FVBUK_STR-CMPSC sy-vline
WA_E1FVBUK_STR-CMPSD sy-vline
WA_E1FVBUK_STR-CMPSE sy-vline
WA_E1FVBUK_STR-CMPSF sy-vline
WA_E1FVBUK_STR-CMPSG sy-vline
WA_E1FVBUK_STR-CMPSH sy-vline
WA_E1FVBUK_STR-CMPSI sy-vline
WA_E1FVBUK_STR-CMPSJ sy-vline
WA_E1FVBUK_STR-CMPSK sy-vline
WA_E1FVBUK_STR-CMPSL sy-vline
WA_E1FVBUK_STR-CMPS0 sy-vline
WA_E1FVBUK_STR-CMPS1 sy-vline
WA_E1FVBUK_STR-CMPS2 sy-vline
WA_E1FVBUK_STR-CMGST sy-vline
WA_E1FVBUK_STR-TRSTA sy-vline
WA_E1FVBUK_STR-KOQUK sy-vline
WA_E1FVBUK_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.