ABAP Select data from SAP table EQUZ 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 EQUZ 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 EQUZ. 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 EQUZ 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_EQUZ TYPE STANDARD TABLE OF EQUZ,
      WA_EQUZ TYPE EQUZ,
      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: <EQUZ> TYPE EQUZ.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM EQUZ
*  INTO TABLE @DATA(IT_EQUZ2).
*--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_EQUZ INDEX 1 INTO DATA(WA_EQUZ2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_EQUZ ASSIGNING <EQUZ>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<EQUZ>-MANDT = 1.
<EQUZ>-EQUNR = 1.
<EQUZ>-DATBI = 1.
<EQUZ>-EQLFN = 1.
<EQUZ>-EQUZN = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_EQUZ-ERDAT, sy-vline,
WA_EQUZ-ERNAM, sy-vline,
WA_EQUZ-AEDAT, sy-vline,
WA_EQUZ-AENAM, sy-vline,
WA_EQUZ-TIMBI, sy-vline,
WA_EQUZ-ESTAI, sy-vline.
ENDLOOP. *Add any further fields from structure WA_EQUZ 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_EQUZ 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_EQUZ INTO WA_EQUZ. *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 EQUNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EQUZ-EQUNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EQUZ-EQUNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field SUBMT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_EQUZ-SUBMT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EQUZ-SUBMT.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

*Conversion exit ALPHA, internal->external for field J_3GPMAUFV CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EQUZ-J_3GPMAUFV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EQUZ-J_3GPMAUFV.
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_EQUZ_STR,
MANDT TYPE STRING,
EQUNR TYPE STRING,
DATBI TYPE STRING,
EQLFN TYPE STRING,
EQUZN TYPE STRING,
ERDAT TYPE STRING,
ERNAM TYPE STRING,
AEDAT TYPE STRING,
AENAM TYPE STRING,
TIMBI TYPE STRING,
ESTAI TYPE STRING,
ESTAE TYPE STRING,
STNAM TYPE STRING,
LVORM TYPE STRING,
DATAB TYPE STRING,
IWERK TYPE STRING,
IWERKI TYPE STRING,
SUBMT TYPE STRING,
MAPAR TYPE STRING,
HEQUI TYPE STRING,
HEQNR TYPE STRING,
INGRP TYPE STRING,
INGRPI TYPE STRING,
PM_OBJTY TYPE STRING,
GEWRK TYPE STRING,
GEWRKI TYPE STRING,
TIDNR TYPE STRING,
TIDNRI TYPE STRING,
ILOAN TYPE STRING,
KUND1 TYPE STRING,
KUND2 TYPE STRING,
KUND3 TYPE STRING,
LIZNR TYPE STRING,
RBNR TYPE STRING,
EZDAT TYPE STRING,
EZBER TYPE STRING,
EZNUM TYPE STRING,
RBNR_I TYPE STRING,
IBLNR TYPE STRING,
BLDAT TYPE STRING,
PVS_FOCUS TYPE STRING,
PPEGUID TYPE STRING,
TECHS TYPE STRING,
FUNCID TYPE STRING,
FRCFIT TYPE STRING,
FRCRMV TYPE STRING,
SEGCHANGEDDATETIME TYPE STRING,
REF_DESIGNATOR TYPE STRING,
PVS_NODE TYPE STRING,
PVS_OTYPE TYPE STRING,
PVS_APPLOBJ_TYPE TYPE STRING,
TOP_EQUI TYPE STRING,
TOP_EQUI_FLAG TYPE STRING,
J_3GEIGNER TYPE STRING,
J_3GVERWAL TYPE STRING,
J_3GPMAUFE TYPE STRING,
J_3GPMAUFV TYPE STRING,
J_3GPACHT TYPE STRING,END OF T_EKKO_STR. DATA: WA_EQUZ_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_EQUZ_STR-MANDT sy-vline
WA_EQUZ_STR-EQUNR sy-vline
WA_EQUZ_STR-DATBI sy-vline
WA_EQUZ_STR-EQLFN sy-vline
WA_EQUZ_STR-EQUZN sy-vline
WA_EQUZ_STR-ERDAT sy-vline
WA_EQUZ_STR-ERNAM sy-vline
WA_EQUZ_STR-AEDAT sy-vline
WA_EQUZ_STR-AENAM sy-vline
WA_EQUZ_STR-TIMBI sy-vline
WA_EQUZ_STR-ESTAI sy-vline
WA_EQUZ_STR-ESTAE sy-vline
WA_EQUZ_STR-STNAM sy-vline
WA_EQUZ_STR-LVORM sy-vline
WA_EQUZ_STR-DATAB sy-vline
WA_EQUZ_STR-IWERK sy-vline
WA_EQUZ_STR-IWERKI sy-vline
WA_EQUZ_STR-SUBMT sy-vline
WA_EQUZ_STR-MAPAR sy-vline
WA_EQUZ_STR-HEQUI sy-vline
WA_EQUZ_STR-HEQNR sy-vline
WA_EQUZ_STR-INGRP sy-vline
WA_EQUZ_STR-INGRPI sy-vline
WA_EQUZ_STR-PM_OBJTY sy-vline
WA_EQUZ_STR-GEWRK sy-vline
WA_EQUZ_STR-GEWRKI sy-vline
WA_EQUZ_STR-TIDNR sy-vline
WA_EQUZ_STR-TIDNRI sy-vline
WA_EQUZ_STR-ILOAN sy-vline
WA_EQUZ_STR-KUND1 sy-vline
WA_EQUZ_STR-KUND2 sy-vline
WA_EQUZ_STR-KUND3 sy-vline
WA_EQUZ_STR-LIZNR sy-vline
WA_EQUZ_STR-RBNR sy-vline
WA_EQUZ_STR-EZDAT sy-vline
WA_EQUZ_STR-EZBER sy-vline
WA_EQUZ_STR-EZNUM sy-vline
WA_EQUZ_STR-RBNR_I sy-vline
WA_EQUZ_STR-IBLNR sy-vline
WA_EQUZ_STR-BLDAT sy-vline
WA_EQUZ_STR-PVS_FOCUS sy-vline
WA_EQUZ_STR-PPEGUID sy-vline
WA_EQUZ_STR-TECHS sy-vline
WA_EQUZ_STR-FUNCID sy-vline
WA_EQUZ_STR-FRCFIT sy-vline
WA_EQUZ_STR-FRCRMV sy-vline
WA_EQUZ_STR-SEGCHANGEDDATETIME sy-vline
WA_EQUZ_STR-REF_DESIGNATOR sy-vline
WA_EQUZ_STR-PVS_NODE sy-vline
WA_EQUZ_STR-PVS_OTYPE sy-vline
WA_EQUZ_STR-PVS_APPLOBJ_TYPE sy-vline
WA_EQUZ_STR-TOP_EQUI sy-vline
WA_EQUZ_STR-TOP_EQUI_FLAG sy-vline
WA_EQUZ_STR-J_3GEIGNER sy-vline
WA_EQUZ_STR-J_3GVERWAL sy-vline
WA_EQUZ_STR-J_3GPMAUFE sy-vline
WA_EQUZ_STR-J_3GPMAUFV sy-vline
WA_EQUZ_STR-J_3GPACHT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.