ABAP Select data from SAP table VIMI16ZS 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 VIMI16ZS 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 VIMI16ZS. 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 VIMI16ZS 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_VIMI16ZS TYPE STANDARD TABLE OF VIMI16ZS, WA_VIMI16ZS TYPE VIMI16ZS, 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: <VIMI16ZS> TYPE VIMI16ZS. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_VIMI16ZS. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM VIMI16ZS INTO TABLE IT_VIMI16ZS. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM VIMI16ZS * INTO TABLE @DATA(IT_VIMI16ZS2). *--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_VIMI16ZS INDEX 1 INTO DATA(WA_VIMI16ZS2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_VIMI16ZS ASSIGNING <VIMI16ZS>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<VIMI16ZS>-ERHBTR = 1.
<VIMI16ZS>-BERHBTRFE = 1.
<VIMI16ZS>-BINDDIFF = 1.
<VIMI16ZS>-XKOARTK = 1.
<VIMI16ZS>-XKOARTM = 1.
ENDLOOP. LOOP AT IT_VIMI16ZS INTO WA_VIMI16ZS. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_VIMI16ZS-XKOARTL, sy-vline,
WA_VIMI16ZS-XMODK, sy-vline,
WA_VIMI16ZS-XMODM, sy-vline,
WA_VIMI16ZS-XWAERSK, sy-vline,
WA_VIMI16ZS-XWAERSL, sy-vline,
WA_VIMI16ZS-XFEINSK, sy-vline.
ENDLOOP. *Add any further fields from structure WA_VIMI16ZS 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_VIMI16ZS 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_VIMI16ZS INTO WA_VIMI16ZS. *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_VIMI16ZS_STR,
ERHBTR TYPE STRING,
BERHBTRFE TYPE STRING,
BINDDIFF TYPE STRING,
XKOARTK TYPE STRING,
XKOARTM TYPE STRING,
XKOARTL TYPE STRING,
XMODK TYPE STRING,
XMODM TYPE STRING,
XWAERSK TYPE STRING,
XWAERSL TYPE STRING,
XFEINSK TYPE STRING,
XFEINSL TYPE STRING,
XSTDORT TYPE STRING,
INDTXT TYPE STRING,
SWHRKNDCUK TYPE STRING,
BANPASSCUK TYPE STRING,
BANPBMCUK TYPE STRING,
BAUTANPCUK TYPE STRING,
BCHBASMCUK TYPE STRING,
BERHABSCUK TYPE STRING,
BERHGESCUK TYPE STRING,
BGESZULCUK TYPE STRING,
BKNDALTCUK TYPE STRING,
BMSPBASCUK TYPE STRING,
BMSPBISCUK TYPE STRING,
BMSPGRDCUK TYPE STRING,
BMSPVONCUK TYPE STRING,
BMSPZUACUK TYPE STRING,
BMZUGBMCUK TYPE STRING,
BNEUABSCUK TYPE STRING,
BNEUMIECUK TYPE STRING,
BVGLAVGCUK TYPE STRING,
BERHBTRCUK TYPE STRING,
BKNDAFECUK TYPE STRING,
BANPAFECUK TYPE STRING,
BERHBFECUK TYPE STRING,
IHPZS TYPE STRING,
IHPZSALT TYPE STRING,
ITEUR TYPE STRING,
ITEURALT TYPE STRING,
BERHHPZS TYPE STRING,
BERHUTBK TYPE STRING,
BERHTEUR TYPE STRING,
BERHGSCH TYPE STRING,END OF T_EKKO_STR. DATA: WA_VIMI16ZS_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_VIMI16ZS_STR-ERHBTR sy-vline
WA_VIMI16ZS_STR-BERHBTRFE sy-vline
WA_VIMI16ZS_STR-BINDDIFF sy-vline
WA_VIMI16ZS_STR-XKOARTK sy-vline
WA_VIMI16ZS_STR-XKOARTM sy-vline
WA_VIMI16ZS_STR-XKOARTL sy-vline
WA_VIMI16ZS_STR-XMODK sy-vline
WA_VIMI16ZS_STR-XMODM sy-vline
WA_VIMI16ZS_STR-XWAERSK sy-vline
WA_VIMI16ZS_STR-XWAERSL sy-vline
WA_VIMI16ZS_STR-XFEINSK sy-vline
WA_VIMI16ZS_STR-XFEINSL sy-vline
WA_VIMI16ZS_STR-XSTDORT sy-vline
WA_VIMI16ZS_STR-INDTXT sy-vline
WA_VIMI16ZS_STR-SWHRKNDCUK sy-vline
WA_VIMI16ZS_STR-BANPASSCUK sy-vline
WA_VIMI16ZS_STR-BANPBMCUK sy-vline
WA_VIMI16ZS_STR-BAUTANPCUK sy-vline
WA_VIMI16ZS_STR-BCHBASMCUK sy-vline
WA_VIMI16ZS_STR-BERHABSCUK sy-vline
WA_VIMI16ZS_STR-BERHGESCUK sy-vline
WA_VIMI16ZS_STR-BGESZULCUK sy-vline
WA_VIMI16ZS_STR-BKNDALTCUK sy-vline
WA_VIMI16ZS_STR-BMSPBASCUK sy-vline
WA_VIMI16ZS_STR-BMSPBISCUK sy-vline
WA_VIMI16ZS_STR-BMSPGRDCUK sy-vline
WA_VIMI16ZS_STR-BMSPVONCUK sy-vline
WA_VIMI16ZS_STR-BMSPZUACUK sy-vline
WA_VIMI16ZS_STR-BMZUGBMCUK sy-vline
WA_VIMI16ZS_STR-BNEUABSCUK sy-vline
WA_VIMI16ZS_STR-BNEUMIECUK sy-vline
WA_VIMI16ZS_STR-BVGLAVGCUK sy-vline
WA_VIMI16ZS_STR-BERHBTRCUK sy-vline
WA_VIMI16ZS_STR-BKNDAFECUK sy-vline
WA_VIMI16ZS_STR-BANPAFECUK sy-vline
WA_VIMI16ZS_STR-BERHBFECUK sy-vline
WA_VIMI16ZS_STR-IHPZS sy-vline
WA_VIMI16ZS_STR-IHPZSALT sy-vline
WA_VIMI16ZS_STR-ITEUR sy-vline
WA_VIMI16ZS_STR-ITEURALT sy-vline
WA_VIMI16ZS_STR-BERHHPZS sy-vline
WA_VIMI16ZS_STR-BERHUTBK sy-vline
WA_VIMI16ZS_STR-BERHTEUR sy-vline
WA_VIMI16ZS_STR-BERHGSCH sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.