Recently i met a case of ABAP performance issue on cluster table.  i think blog is a good place to

share this topic.  Your comments are really appreciate.

 

Issue description and analysis

 

Database perspective:  SQL trace showed a table cluster  KOCLU:

SQL_Trace.gif

ExecutionPlan.gif

the Full table scan on table cluster KOCLU is done , which is the reason of this exepensive SQL Statement.

but why DBI ignore the values of the primary key fields as these values are already provied in the ABAP Source code.

ABAP perspective

source Code.gif

Cluster table KONV is only existing ABAP Dictionary and stored in the table cluster KOCLU on the database level.

KONV Primary key fields:         

MANDT
KNUMV
KPOSN
STUNR
ZAEHK

From the fields list above, the key field KNUMV was specified but not transfered to database side.

the reason behind this is the OR operation. After this is removed, the key fields were transfered to the

database side and the Index range scan was chosen instead of the full table scan.

Here is the Main concept of eliminating the high percentage of identical selects by local buffer.

  1. Two internal tables (A and B) are defined to buffer the result  of the “select statement “ on table bseg. Table A is for the search criteria that is existing in the database and table B is for the search criteria that is not existing in the database.

      
  2. Read internal table A, if existing, return the value. If not go to step 3.
      
  3. Read internal table B for the record that does not exist in the database, if it doesnot exist in the buffer, go to step 4.
      
  4. Make the database access and fetch the record and log the result in the two internal tables.

 

types: begin of s_bseg,

        bukrs like bseg-bukrs,

        gjahr like bseg-gjahr,

        belnr like bseg-belnr,

        buzei like bseg-buzei,

        wskto like bseg-wskto,

        shkzg like bseg-shkzg,

       end of s_bseg.

      

data: itb_bseg_found type sorted table of s_bseg with non-unique key bukrs gjahr belnr buzei,

      itb_bseg_notfound type sorted table of s_bseg with non-unique key bukrs gjahr belnr buzeiwa_bseg s_bseg.

 

   

      Read table itb_bseg_found into wa_bseg with key

bukrs = bsas-bukrs

                                  gjahr = bsas-gjahr

                                  belnr = bsas-belnr

                               buzei = bsas-buzei.

      if sy-subrc = 0.

  bseg-wskto = wa_bseg-wskto.

       bseg-shkzg = wa_bseg-shkzg.                   

      else.

      Read table itb_bseg_notfound transporting no fields with key

bukrs = bsas-bukrs

gjahr = bsas-gjahr

belnr = bsas-belnr

buzei = bsas-buzei.

     

      if sy-subrc <> 0. 

    SELECT SINGLE wskto shkzg

      FROM bseg

      INTO (bseg-wskto, bseg-shkzg)

      WHERE bukrs = bsas-bukrs AND

            gjahr = bsas-gjahr AND

            belnr = bsas-belnr AND

            buzei = bsas-buzei.

           

  wa_bseg-bukrs = bsas-bukrs.

              wa_bseg-gjahr = bsas-gjahr.

              wa_bseg-belnr = bsas-belnr.

              wa_bseg-buzei = bsas-buzei.

              wa_bseg-wskto = bseg-wskto.

              wa_bseg-shkzg = bseg-shkzg.            

             

        if sy-subrc = 0.

          insert wa_bseg into table itb_bseg_found.

        else.

          insert wa_bseg into table itb_bseg_notfound.

        endif.

    endif.

    endif.

 

Note: Change the data type of internal tables itb_bseg_found and itb_bseg_notfound to statistics if this is

called in the funcational module or form.

Welcome to comment on this topic.

Filter Blog

By author: By date:
By tag: