ABAP Select data from SAP table EINE 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 EINE 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 EINE. 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 EINE 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_EINE TYPE STANDARD TABLE OF EINE,
      WA_EINE TYPE EINE,
      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: <EINE> TYPE EINE.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM EINE
*  INTO TABLE @DATA(IT_EINE2).
*--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_EINE INDEX 1 INTO DATA(WA_EINE2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_EINE ASSIGNING <EINE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<EINE>-MANDT = 1.
<EINE>-INFNR = 1.
<EINE>-EKORG = 1.
<EINE>-ESOKZ = 1.
<EINE>-WERKS = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_EINE-LOEKZ, sy-vline,
WA_EINE-ERDAT, sy-vline,
WA_EINE-ERNAM, sy-vline,
WA_EINE-EKGRP, sy-vline,
WA_EINE-WAERS, sy-vline,
WA_EINE-BONUS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_EINE 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_EINE 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_EINE INTO WA_EINE. *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 INFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EINE-INFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EINE-INFNR.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit PERKZ, internal->external for field IPRKZ CALL FUNCTION 'CONVERSION_EXIT_PERKZ_OUTPUT' EXPORTING input = WA_EINE-IPRKZ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EINE-IPRKZ.
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_EINE_STR,
MANDT TYPE STRING,
INFNR TYPE STRING,
EKORG TYPE STRING,
ESOKZ TYPE STRING,
WERKS TYPE STRING,
LOEKZ TYPE STRING,
ERDAT TYPE STRING,
ERNAM TYPE STRING,
EKGRP TYPE STRING,
WAERS TYPE STRING,
BONUS TYPE STRING,
MGBON TYPE STRING,
MINBM TYPE STRING,
NORBM TYPE STRING,
APLFZ TYPE STRING,
UEBTO TYPE STRING,
UEBTK TYPE STRING,
UNTTO TYPE STRING,
ANGNR TYPE STRING,
ANGDT TYPE STRING,
ANFNR TYPE STRING,
ANFPS TYPE STRING,
ABSKZ TYPE STRING,
AMODV TYPE STRING,
AMODB TYPE STRING,
AMOBM TYPE STRING,
AMOBW TYPE STRING,
AMOAM TYPE STRING,
AMOAW TYPE STRING,
AMORS TYPE STRING,
BSTYP TYPE STRING,
EBELN TYPE STRING,
EBELP TYPE STRING,
DATLB TYPE STRING,
NETPR TYPE STRING,
PEINH TYPE STRING,
BPRME TYPE STRING,
PRDAT TYPE STRING,
BPUMZ TYPE STRING,
BPUMN TYPE STRING,
MTXNO TYPE STRING,
WEBRE TYPE STRING,
EFFPR TYPE STRING,
EKKOL TYPE STRING,
SKTOF TYPE STRING,
KZABS TYPE STRING,
MWSKZ TYPE STRING,
TXDAT_FROM TYPE STRING,
TAX_COUNTRY TYPE STRING,
BWTAR TYPE STRING,
EBONU TYPE STRING,
EVERS TYPE STRING,
EXPRF TYPE STRING,
BSTAE TYPE STRING,
MEPRF TYPE STRING,
INCO1 TYPE STRING,
INCO2 TYPE STRING,
XERSN TYPE STRING,
EBON2 TYPE STRING,
EBON3 TYPE STRING,
EBONF TYPE STRING,
MHDRZ TYPE STRING,
VERID TYPE STRING,
BSTMA TYPE STRING,
RDPRF TYPE STRING,
MEGRU TYPE STRING,
J_1BNBM TYPE STRING,
SPE_CRE_REF_DOC TYPE STRING,
IPRKZ TYPE STRING,
CO_ORDER TYPE STRING,
VENDOR_RMA_REQ TYPE STRING,
DIFF_INVOICE TYPE STRING,
INCOV TYPE STRING,
INCO2_L TYPE STRING,
INCO3_L TYPE STRING,
AUT_SOURCE TYPE STRING,
DUMMY_EINE_INCL_EEW_PS TYPE STRING,
ISEOPBLOCKED TYPE STRING,
FSH_DCI_CORR TYPE STRING,
FSH_RLT TYPE STRING,
FSH_MLT TYPE STRING,
FSH_PLT TYPE STRING,
FSH_TLT TYPE STRING,
MRPIND TYPE STRING,
SGT_SSREL TYPE STRING,
TRANSPORT_CHAIN TYPE STRING,
STAGING_TIME TYPE STRING,END OF T_EKKO_STR. DATA: WA_EINE_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_EINE_STR-MANDT sy-vline
WA_EINE_STR-INFNR sy-vline
WA_EINE_STR-EKORG sy-vline
WA_EINE_STR-ESOKZ sy-vline
WA_EINE_STR-WERKS sy-vline
WA_EINE_STR-LOEKZ sy-vline
WA_EINE_STR-ERDAT sy-vline
WA_EINE_STR-ERNAM sy-vline
WA_EINE_STR-EKGRP sy-vline
WA_EINE_STR-WAERS sy-vline
WA_EINE_STR-BONUS sy-vline
WA_EINE_STR-MGBON sy-vline
WA_EINE_STR-MINBM sy-vline
WA_EINE_STR-NORBM sy-vline
WA_EINE_STR-APLFZ sy-vline
WA_EINE_STR-UEBTO sy-vline
WA_EINE_STR-UEBTK sy-vline
WA_EINE_STR-UNTTO sy-vline
WA_EINE_STR-ANGNR sy-vline
WA_EINE_STR-ANGDT sy-vline
WA_EINE_STR-ANFNR sy-vline
WA_EINE_STR-ANFPS sy-vline
WA_EINE_STR-ABSKZ sy-vline
WA_EINE_STR-AMODV sy-vline
WA_EINE_STR-AMODB sy-vline
WA_EINE_STR-AMOBM sy-vline
WA_EINE_STR-AMOBW sy-vline
WA_EINE_STR-AMOAM sy-vline
WA_EINE_STR-AMOAW sy-vline
WA_EINE_STR-AMORS sy-vline
WA_EINE_STR-BSTYP sy-vline
WA_EINE_STR-EBELN sy-vline
WA_EINE_STR-EBELP sy-vline
WA_EINE_STR-DATLB sy-vline
WA_EINE_STR-NETPR sy-vline
WA_EINE_STR-PEINH sy-vline
WA_EINE_STR-BPRME sy-vline
WA_EINE_STR-PRDAT sy-vline
WA_EINE_STR-BPUMZ sy-vline
WA_EINE_STR-BPUMN sy-vline
WA_EINE_STR-MTXNO sy-vline
WA_EINE_STR-WEBRE sy-vline
WA_EINE_STR-EFFPR sy-vline
WA_EINE_STR-EKKOL sy-vline
WA_EINE_STR-SKTOF sy-vline
WA_EINE_STR-KZABS sy-vline
WA_EINE_STR-MWSKZ sy-vline
WA_EINE_STR-TXDAT_FROM sy-vline
WA_EINE_STR-TAX_COUNTRY sy-vline
WA_EINE_STR-BWTAR sy-vline
WA_EINE_STR-EBONU sy-vline
WA_EINE_STR-EVERS sy-vline
WA_EINE_STR-EXPRF sy-vline
WA_EINE_STR-BSTAE sy-vline
WA_EINE_STR-MEPRF sy-vline
WA_EINE_STR-INCO1 sy-vline
WA_EINE_STR-INCO2 sy-vline
WA_EINE_STR-XERSN sy-vline
WA_EINE_STR-EBON2 sy-vline
WA_EINE_STR-EBON3 sy-vline
WA_EINE_STR-EBONF sy-vline
WA_EINE_STR-MHDRZ sy-vline
WA_EINE_STR-VERID sy-vline
WA_EINE_STR-BSTMA sy-vline
WA_EINE_STR-RDPRF sy-vline
WA_EINE_STR-MEGRU sy-vline
WA_EINE_STR-J_1BNBM sy-vline
WA_EINE_STR-SPE_CRE_REF_DOC sy-vline
WA_EINE_STR-IPRKZ sy-vline
WA_EINE_STR-CO_ORDER sy-vline
WA_EINE_STR-VENDOR_RMA_REQ sy-vline
WA_EINE_STR-DIFF_INVOICE sy-vline
WA_EINE_STR-INCOV sy-vline
WA_EINE_STR-INCO2_L sy-vline
WA_EINE_STR-INCO3_L sy-vline
WA_EINE_STR-AUT_SOURCE sy-vline
WA_EINE_STR-DUMMY_EINE_INCL_EEW_PS sy-vline
WA_EINE_STR-ISEOPBLOCKED sy-vline
WA_EINE_STR-FSH_DCI_CORR sy-vline
WA_EINE_STR-FSH_RLT sy-vline
WA_EINE_STR-FSH_MLT sy-vline
WA_EINE_STR-FSH_PLT sy-vline
WA_EINE_STR-FSH_TLT sy-vline
WA_EINE_STR-MRPIND sy-vline
WA_EINE_STR-SGT_SSREL sy-vline
WA_EINE_STR-TRANSPORT_CHAIN sy-vline
WA_EINE_STR-STAGING_TIME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.