ABAP Select data from SAP table ESH_QL_QLOG 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 ESH_QL_QLOG 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 ESH_QL_QLOG. 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 ESH_QL_QLOG 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_ESH_QL_QLOG TYPE STANDARD TABLE OF ESH_QL_QLOG,
      WA_ESH_QL_QLOG TYPE ESH_QL_QLOG,
      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: <ESH_QL_QLOG> TYPE ESH_QL_QLOG.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ESH_QL_QLOG
*  INTO TABLE @DATA(IT_ESH_QL_QLOG2).
*--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_ESH_QL_QLOG INDEX 1 INTO DATA(WA_ESH_QL_QLOG2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ESH_QL_QLOG ASSIGNING <ESH_QL_QLOG>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ESH_QL_QLOG>-MANDT = 1.
<ESH_QL_QLOG>-EXEC_ID = 1.
<ESH_QL_QLOG>-SESSION_ID = 1.
<ESH_QL_QLOG>-QUERY_TYPE = 1.
<ESH_QL_QLOG>-EXEC_MODE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ESH_QL_QLOG-EXEC_TSTP, sy-vline,
WA_ESH_QL_QLOG-EXEC_USER, sy-vline,
WA_ESH_QL_QLOG-REF_TYPE, sy-vline,
WA_ESH_QL_QLOG-REF_ID, sy-vline,
WA_ESH_QL_QLOG-INTERVAL_FROM, sy-vline,
WA_ESH_QL_QLOG-INTERVAL_TO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ESH_QL_QLOG 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_ESH_QL_QLOG 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_ESH_QL_QLOG INTO WA_ESH_QL_QLOG. *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_ESH_QL_QLOG_STR,
MANDT TYPE STRING,
EXEC_ID TYPE STRING,
SESSION_ID TYPE STRING,
QUERY_TYPE TYPE STRING,
EXEC_MODE TYPE STRING,
EXEC_TSTP TYPE STRING,
EXEC_USER TYPE STRING,
REF_TYPE TYPE STRING,
REF_ID TYPE STRING,
INTERVAL_FROM TYPE STRING,
INTERVAL_TO TYPE STRING,
TIMEOUT TYPE STRING,
VALIDITY_DATE TYPE STRING,
SEARCH_LANGU TYPE STRING,
SEARCH_MODE TYPE STRING,
FUZZY_SIMILARITY TYPE STRING,
HITS TYPE STRING,
TOTAL_HITS TYPE STRING,
ENDED_WITH_EXC TYPE STRING,
STAT_CONN_ALL TYPE STRING,
STAT_CONN_SUCC TYPE STRING,
STAT_CONN_NORES TYPE STRING,
STAT_CONN_ERROR TYPE STRING,
STAT_ACTIONS TYPE STRING,
RUNTIME_TOTAL TYPE STRING,
RUNTIME_HANA TYPE STRING,
RUNTIME_HANA_CPU TYPE STRING,
MAX_RANK_VALUE TYPE STRING,
SEARCH_SERVICE TYPE STRING,
EVENT_CLTSP TYPE STRING,
LQAID TYPE STRING,
CALLER TYPE STRING,
CALLER_APPL_COMP TYPE STRING,
DISCARDED TYPE STRING,END OF T_EKKO_STR. DATA: WA_ESH_QL_QLOG_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_ESH_QL_QLOG_STR-MANDT sy-vline
WA_ESH_QL_QLOG_STR-EXEC_ID sy-vline
WA_ESH_QL_QLOG_STR-SESSION_ID sy-vline
WA_ESH_QL_QLOG_STR-QUERY_TYPE sy-vline
WA_ESH_QL_QLOG_STR-EXEC_MODE sy-vline
WA_ESH_QL_QLOG_STR-EXEC_TSTP sy-vline
WA_ESH_QL_QLOG_STR-EXEC_USER sy-vline
WA_ESH_QL_QLOG_STR-REF_TYPE sy-vline
WA_ESH_QL_QLOG_STR-REF_ID sy-vline
WA_ESH_QL_QLOG_STR-INTERVAL_FROM sy-vline
WA_ESH_QL_QLOG_STR-INTERVAL_TO sy-vline
WA_ESH_QL_QLOG_STR-TIMEOUT sy-vline
WA_ESH_QL_QLOG_STR-VALIDITY_DATE sy-vline
WA_ESH_QL_QLOG_STR-SEARCH_LANGU sy-vline
WA_ESH_QL_QLOG_STR-SEARCH_MODE sy-vline
WA_ESH_QL_QLOG_STR-FUZZY_SIMILARITY sy-vline
WA_ESH_QL_QLOG_STR-HITS sy-vline
WA_ESH_QL_QLOG_STR-TOTAL_HITS sy-vline
WA_ESH_QL_QLOG_STR-ENDED_WITH_EXC sy-vline
WA_ESH_QL_QLOG_STR-STAT_CONN_ALL sy-vline
WA_ESH_QL_QLOG_STR-STAT_CONN_SUCC sy-vline
WA_ESH_QL_QLOG_STR-STAT_CONN_NORES sy-vline
WA_ESH_QL_QLOG_STR-STAT_CONN_ERROR sy-vline
WA_ESH_QL_QLOG_STR-STAT_ACTIONS sy-vline
WA_ESH_QL_QLOG_STR-RUNTIME_TOTAL sy-vline
WA_ESH_QL_QLOG_STR-RUNTIME_HANA sy-vline
WA_ESH_QL_QLOG_STR-RUNTIME_HANA_CPU sy-vline
WA_ESH_QL_QLOG_STR-MAX_RANK_VALUE sy-vline
WA_ESH_QL_QLOG_STR-SEARCH_SERVICE sy-vline
WA_ESH_QL_QLOG_STR-EVENT_CLTSP sy-vline
WA_ESH_QL_QLOG_STR-LQAID sy-vline
WA_ESH_QL_QLOG_STR-CALLER sy-vline
WA_ESH_QL_QLOG_STR-CALLER_APPL_COMP sy-vline
WA_ESH_QL_QLOG_STR-DISCARDED sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.