ABAP Select data from SAP table QBEXT_TS_QINF_ENHANCED 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 QBEXT_TS_QINF_ENHANCED 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 QBEXT_TS_QINF_ENHANCED. 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 QBEXT_TS_QINF_ENHANCED 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_QBEXT_TS_QINF_ENHANCED TYPE STANDARD TABLE OF QBEXT_TS_QINF_ENHANCED,
      WA_QBEXT_TS_QINF_ENHANCED TYPE QBEXT_TS_QINF_ENHANCED,
      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: <QBEXT_TS_QINF_ENHANCED> TYPE QBEXT_TS_QINF_ENHANCED.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM QBEXT_TS_QINF_ENHANCED
*  INTO TABLE @DATA(IT_QBEXT_TS_QINF_ENHANCED2).
*--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_QBEXT_TS_QINF_ENHANCED INDEX 1 INTO DATA(WA_QBEXT_TS_QINF_ENHANCED2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_QBEXT_TS_QINF_ENHANCED ASSIGNING <QBEXT_TS_QINF_ENHANCED>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<QBEXT_TS_QINF_ENHANCED>-MANDT = 1.
<QBEXT_TS_QINF_ENHANCED>-MATNR = 1.
<QBEXT_TS_QINF_ENHANCED>-ZAEHL = 1.
<QBEXT_TS_QINF_ENHANCED>-ERSTELLER = 1.
<QBEXT_TS_QINF_ENHANCED>-ERSTELLDAT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_QBEXT_TS_QINF_ENHANCED-AENDERER, sy-vline,
WA_QBEXT_TS_QINF_ENHANCED-AENDERDAT, sy-vline,
WA_QBEXT_TS_QINF_ENHANCED-CHANGEDDATETIME, sy-vline,
WA_QBEXT_TS_QINF_ENHANCED-LIEFERANT, sy-vline,
WA_QBEXT_TS_QINF_ENHANCED-WERK, sy-vline,
WA_QBEXT_TS_QINF_ENHANCED-FREI_DAT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_QBEXT_TS_QINF_ENHANCED 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_QBEXT_TS_QINF_ENHANCED 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_QBEXT_TS_QINF_ENHANCED INTO WA_QBEXT_TS_QINF_ENHANCED. *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 MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_QBEXT_TS_QINF_ENHANCED-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_QBEXT_TS_QINF_ENHANCED-MATNR.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ISOLA, internal->external for field SPRACHE CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_QBEXT_TS_QINF_ENHANCED-SPRACHE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_QBEXT_TS_QINF_ENHANCED-SPRACHE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field SPRAS CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_QBEXT_TS_QINF_ENHANCED-SPRAS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_QBEXT_TS_QINF_ENHANCED-SPRAS.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit NUMCV, internal->external for field REVLV CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_QBEXT_TS_QINF_ENHANCED-REVLV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_QBEXT_TS_QINF_ENHANCED-REVLV.
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_QBEXT_TS_QINF_ENHANCED_STR,
MANDT TYPE STRING,
MATNR TYPE STRING,
ZAEHL TYPE STRING,
ERSTELLER TYPE STRING,
ERSTELLDAT TYPE STRING,
AENDERER TYPE STRING,
AENDERDAT TYPE STRING,
CHANGEDDATETIME TYPE STRING,
LIEFERANT TYPE STRING,
WERK TYPE STRING,
FREI_DAT TYPE STRING,
FREI_MGKZ TYPE STRING,
ME TYPE STRING,
FREI_MNG TYPE STRING,
BEST_MG TYPE STRING,
DAT_RUECK TYPE STRING,
SPERRGRUND TYPE STRING,
SPRACHE TYPE STRING,
SPERRFKT TYPE STRING,
QVVORH TYPE STRING,
NOINSP TYPE STRING,
QSSYSFAM TYPE STRING,
QSSYSDAT TYPE STRING,
VARIABNAHM TYPE STRING,
LTEXTKZ TYPE STRING,
SPRAS TYPE STRING,
PLOS TYPE STRING,
PLOS2 TYPE STRING,
PPAP_IS_REQUIRED TYPE STRING,
PPAP_LEVEL TYPE STRING,
PPAP_STATUS TYPE STRING,
PPAP_ID TYPE STRING,
STSMA TYPE STRING,
OBJNR TYPE STRING,
NOINSPABN TYPE STRING,
VORLABN TYPE STRING,
REVLV TYPE STRING,
LOEKZ TYPE STRING,
CERTCONTROL TYPE STRING,
DUMMY_QINF_INCL_EEW_PS TYPE STRING,
QINFFEHL TYPE STRING,
QVFEHL TYPE STRING,
DATUM TYPE STRING,
MENGE TYPE STRING,
QINFQSSYSDAT TYPE STRING,
QMATSSQSS TYPE STRING,
STSCURR TYPE STRING,
STSNEXT TYPE STRING,
QMPUR TYPE STRING,
SSQSS TYPE STRING,END OF T_EKKO_STR. DATA: WA_QBEXT_TS_QINF_ENHANCED_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_QBEXT_TS_QINF_ENHANCED_STR-MANDT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-MATNR sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-ZAEHL sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-ERSTELLER sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-ERSTELLDAT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-AENDERER sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-AENDERDAT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-CHANGEDDATETIME sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-LIEFERANT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-WERK sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-FREI_DAT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-FREI_MGKZ sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-ME sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-FREI_MNG sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-BEST_MG sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-DAT_RUECK sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-SPERRGRUND sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-SPRACHE sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-SPERRFKT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QVVORH sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-NOINSP sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QSSYSFAM sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QSSYSDAT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-VARIABNAHM sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-LTEXTKZ sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-SPRAS sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-PLOS sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-PLOS2 sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-PPAP_IS_REQUIRED sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-PPAP_LEVEL sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-PPAP_STATUS sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-PPAP_ID sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-STSMA sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-OBJNR sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-NOINSPABN sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-VORLABN sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-REVLV sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-LOEKZ sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-CERTCONTROL sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-DUMMY_QINF_INCL_EEW_PS sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QINFFEHL sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QVFEHL sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-DATUM sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-MENGE sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QINFQSSYSDAT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QMATSSQSS sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-STSCURR sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-STSNEXT sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-QMPUR sy-vline
WA_QBEXT_TS_QINF_ENHANCED_STR-SSQSS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.