ABAP Select data from SAP table E1MBXYI 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 E1MBXYI 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 E1MBXYI. 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 E1MBXYI 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_E1MBXYI TYPE STANDARD TABLE OF E1MBXYI,
      WA_E1MBXYI TYPE E1MBXYI,
      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: <E1MBXYI> TYPE E1MBXYI.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM E1MBXYI
*  INTO TABLE @DATA(IT_E1MBXYI2).
*--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_E1MBXYI INDEX 1 INTO DATA(WA_E1MBXYI2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_E1MBXYI ASSIGNING <E1MBXYI>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<E1MBXYI>-BEAKZ = 1.
<E1MBXYI>-XSTOB = 1.
<E1MBXYI>-MATNR = 1.
<E1MBXYI>-WERKS = 1.
<E1MBXYI>-LGORT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_E1MBXYI-CHARG, sy-vline,
WA_E1MBXYI-BWART, sy-vline,
WA_E1MBXYI-INSMK, sy-vline,
WA_E1MBXYI-SOBKZ, sy-vline,
WA_E1MBXYI-KZVBR, sy-vline,
WA_E1MBXYI-LIFNR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_E1MBXYI 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_E1MBXYI 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_E1MBXYI INTO WA_E1MBXYI. *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 MATN5, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN5_OUTPUT' EXPORTING input = WA_E1MBXYI-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_E1MBXYI-MATNR.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

*Conversion exit MATN5, internal->external for field UMMAT CALL FUNCTION 'CONVERSION_EXIT_MATN5_OUTPUT' EXPORTING input = WA_E1MBXYI-UMMAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_E1MBXYI-UMMAT.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

*Conversion exit FMCIS, internal->external for field FIPOS CALL FUNCTION 'CONVERSION_EXIT_FMCIS_OUTPUT' EXPORTING input = WA_E1MBXYI-FIPOS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_E1MBXYI-FIPOS.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit ALPHA, internal->external for field VBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_E1MBXYI-VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_E1MBXYI-VBELN.
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_E1MBXYI_STR,
BEAKZ TYPE STRING,
XSTOB TYPE STRING,
MATNR TYPE STRING,
WERKS TYPE STRING,
LGORT TYPE STRING,
CHARG TYPE STRING,
BWART TYPE STRING,
INSMK TYPE STRING,
SOBKZ TYPE STRING,
KZVBR TYPE STRING,
LIFNR TYPE STRING,
KUNNR TYPE STRING,
KDAUF TYPE STRING,
KDPOS TYPE STRING,
KDEIN TYPE STRING,
SHKZG TYPE STRING,
WAERS TYPE STRING,
DMBTR TYPE STRING,
BWTAR TYPE STRING,
ERFMG TYPE STRING,
ERFME TYPE STRING,
BPMNG TYPE STRING,
BPRME TYPE STRING,
EBELN TYPE STRING,
EBELP TYPE STRING,
ELIKZ TYPE STRING,
SGTXT TYPE STRING,
WEMPF TYPE STRING,
ABLAD TYPE STRING,
KOSTL TYPE STRING,
AUFNR TYPE STRING,
ANLN1 TYPE STRING,
ANLN2 TYPE STRING,
RSNUM TYPE STRING,
RSPOS TYPE STRING,
KZEAR TYPE STRING,
UMMAT TYPE STRING,
UMWRK TYPE STRING,
UMLGO TYPE STRING,
UMCHA TYPE STRING,
KZBEW TYPE STRING,
WEUNB TYPE STRING,
LGNUM TYPE STRING,
LGTYP TYPE STRING,
LGPLA TYPE STRING,
GRUND TYPE STRING,
EVERS TYPE STRING,
EVERE TYPE STRING,
IMKEY TYPE STRING,
KSTRG TYPE STRING,
PAOBJNR TYPE STRING,
PRCTR TYPE STRING,
PS_PSP_PNR TYPE STRING,
NPLNR TYPE STRING,
AUFPL TYPE STRING,
APLZL TYPE STRING,
AUFPS TYPE STRING,
VPTNR TYPE STRING,
FIPOS TYPE STRING,
GSBER TYPE STRING,
BSTMG TYPE STRING,
BSTME TYPE STRING,
EXBWR TYPE STRING,
KONTO TYPE STRING,
RSHKZ TYPE STRING,
BDMNG TYPE STRING,
ENMNG TYPE STRING,
QPLOS TYPE STRING,
UMZST TYPE STRING,
UMZUS TYPE STRING,
UMBAR TYPE STRING,
UMSOK TYPE STRING,
LFBJA TYPE STRING,
LFBNR TYPE STRING,
LFPOS TYPE STRING,
SJAHR TYPE STRING,
SMBLN TYPE STRING,
SMBLP TYPE STRING,
EXVKW TYPE STRING,
QM_ZUSTD TYPE STRING,
POSNR TYPE STRING,
VBELN TYPE STRING,
QM_UMZST TYPE STRING,
BWLVS TYPE STRING,
UMREZ TYPE STRING,
UMREN TYPE STRING,
VFDAT TYPE STRING,
DABRZ TYPE STRING,
MATNR_EXTERNAL TYPE STRING,
MATNR_VERSION TYPE STRING,
MATNR_GUID TYPE STRING,
UMMAT_EXTERNAL TYPE STRING,
UMMAT_VERSION TYPE STRING,
UMMAT_GUID TYPE STRING,
FIPEX TYPE STRING,
MATNR_LONG TYPE STRING,
UMMAT_LONG TYPE STRING,END OF T_EKKO_STR. DATA: WA_E1MBXYI_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_E1MBXYI_STR-BEAKZ sy-vline
WA_E1MBXYI_STR-XSTOB sy-vline
WA_E1MBXYI_STR-MATNR sy-vline
WA_E1MBXYI_STR-WERKS sy-vline
WA_E1MBXYI_STR-LGORT sy-vline
WA_E1MBXYI_STR-CHARG sy-vline
WA_E1MBXYI_STR-BWART sy-vline
WA_E1MBXYI_STR-INSMK sy-vline
WA_E1MBXYI_STR-SOBKZ sy-vline
WA_E1MBXYI_STR-KZVBR sy-vline
WA_E1MBXYI_STR-LIFNR sy-vline
WA_E1MBXYI_STR-KUNNR sy-vline
WA_E1MBXYI_STR-KDAUF sy-vline
WA_E1MBXYI_STR-KDPOS sy-vline
WA_E1MBXYI_STR-KDEIN sy-vline
WA_E1MBXYI_STR-SHKZG sy-vline
WA_E1MBXYI_STR-WAERS sy-vline
WA_E1MBXYI_STR-DMBTR sy-vline
WA_E1MBXYI_STR-BWTAR sy-vline
WA_E1MBXYI_STR-ERFMG sy-vline
WA_E1MBXYI_STR-ERFME sy-vline
WA_E1MBXYI_STR-BPMNG sy-vline
WA_E1MBXYI_STR-BPRME sy-vline
WA_E1MBXYI_STR-EBELN sy-vline
WA_E1MBXYI_STR-EBELP sy-vline
WA_E1MBXYI_STR-ELIKZ sy-vline
WA_E1MBXYI_STR-SGTXT sy-vline
WA_E1MBXYI_STR-WEMPF sy-vline
WA_E1MBXYI_STR-ABLAD sy-vline
WA_E1MBXYI_STR-KOSTL sy-vline
WA_E1MBXYI_STR-AUFNR sy-vline
WA_E1MBXYI_STR-ANLN1 sy-vline
WA_E1MBXYI_STR-ANLN2 sy-vline
WA_E1MBXYI_STR-RSNUM sy-vline
WA_E1MBXYI_STR-RSPOS sy-vline
WA_E1MBXYI_STR-KZEAR sy-vline
WA_E1MBXYI_STR-UMMAT sy-vline
WA_E1MBXYI_STR-UMWRK sy-vline
WA_E1MBXYI_STR-UMLGO sy-vline
WA_E1MBXYI_STR-UMCHA sy-vline
WA_E1MBXYI_STR-KZBEW sy-vline
WA_E1MBXYI_STR-WEUNB sy-vline
WA_E1MBXYI_STR-LGNUM sy-vline
WA_E1MBXYI_STR-LGTYP sy-vline
WA_E1MBXYI_STR-LGPLA sy-vline
WA_E1MBXYI_STR-GRUND sy-vline
WA_E1MBXYI_STR-EVERS sy-vline
WA_E1MBXYI_STR-EVERE sy-vline
WA_E1MBXYI_STR-IMKEY sy-vline
WA_E1MBXYI_STR-KSTRG sy-vline
WA_E1MBXYI_STR-PAOBJNR sy-vline
WA_E1MBXYI_STR-PRCTR sy-vline
WA_E1MBXYI_STR-PS_PSP_PNR sy-vline
WA_E1MBXYI_STR-NPLNR sy-vline
WA_E1MBXYI_STR-AUFPL sy-vline
WA_E1MBXYI_STR-APLZL sy-vline
WA_E1MBXYI_STR-AUFPS sy-vline
WA_E1MBXYI_STR-VPTNR sy-vline
WA_E1MBXYI_STR-FIPOS sy-vline
WA_E1MBXYI_STR-GSBER sy-vline
WA_E1MBXYI_STR-BSTMG sy-vline
WA_E1MBXYI_STR-BSTME sy-vline
WA_E1MBXYI_STR-EXBWR sy-vline
WA_E1MBXYI_STR-KONTO sy-vline
WA_E1MBXYI_STR-RSHKZ sy-vline
WA_E1MBXYI_STR-BDMNG sy-vline
WA_E1MBXYI_STR-ENMNG sy-vline
WA_E1MBXYI_STR-QPLOS sy-vline
WA_E1MBXYI_STR-UMZST sy-vline
WA_E1MBXYI_STR-UMZUS sy-vline
WA_E1MBXYI_STR-UMBAR sy-vline
WA_E1MBXYI_STR-UMSOK sy-vline
WA_E1MBXYI_STR-LFBJA sy-vline
WA_E1MBXYI_STR-LFBNR sy-vline
WA_E1MBXYI_STR-LFPOS sy-vline
WA_E1MBXYI_STR-SJAHR sy-vline
WA_E1MBXYI_STR-SMBLN sy-vline
WA_E1MBXYI_STR-SMBLP sy-vline
WA_E1MBXYI_STR-EXVKW sy-vline
WA_E1MBXYI_STR-QM_ZUSTD sy-vline
WA_E1MBXYI_STR-POSNR sy-vline
WA_E1MBXYI_STR-VBELN sy-vline
WA_E1MBXYI_STR-QM_UMZST sy-vline
WA_E1MBXYI_STR-BWLVS sy-vline
WA_E1MBXYI_STR-UMREZ sy-vline
WA_E1MBXYI_STR-UMREN sy-vline
WA_E1MBXYI_STR-VFDAT sy-vline
WA_E1MBXYI_STR-DABRZ sy-vline
WA_E1MBXYI_STR-MATNR_EXTERNAL sy-vline
WA_E1MBXYI_STR-MATNR_VERSION sy-vline
WA_E1MBXYI_STR-MATNR_GUID sy-vline
WA_E1MBXYI_STR-UMMAT_EXTERNAL sy-vline
WA_E1MBXYI_STR-UMMAT_VERSION sy-vline
WA_E1MBXYI_STR-UMMAT_GUID sy-vline
WA_E1MBXYI_STR-FIPEX sy-vline
WA_E1MBXYI_STR-MATNR_LONG sy-vline
WA_E1MBXYI_STR-UMMAT_LONG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.