Quantcast
Channel: SCN : Blog List - ABAP Development
Viewing all articles
Browse latest Browse all 943

Performance Tuning in BI Routines - ABAP Programming

$
0
0

  This blog gives you a detailed description of Performance tuning needed in ABAP routines (transformation) and hints to write the optimized code.


  ABAP Routines – Deployment in Transformation

 

  1. Characteristics or Field Routine
    • Not preferred as it executes for each and every field
  2. Expert Routine
    • Not preferred as it requires ABAP coding for entire Transformation
  3. Start Routine
    • Preferred  based on the requirement(used mostly when changes are need to be done at sourcepackage level)
  4. End Routine
    • Preferred based on the requirement(used mostly when changes are need to be done at result package level)

Types of declarations:-

  1. Global Declaration
    • Should be declared here only when required in both the routines(either start/field/end routines).
    • When populated it is carried across the routines.
    • Should be cleared (either using clear/refresh command) when not used.

   2.  Declaration in Routines

    • Only used within the specific routine.
    • Data cannot be transferred to other routines.
    • Data will be cleared at the end of the routine.

Declaration of data fields:

Structures –

    • Always try to use declaration of data fields as TYPES instead of DATA.
    • Avoid use of TABLES statement for declaring Internal Tables and Structures.
    • Try to use only the required fields for Internal table instead of entire DB Tables.

Example:

TYPES:BEGIN OF ty_structure,      

              field1 TYPE <data_element1>,  

                  field2 TYPE <data_element2>,   

                END OF ty_structure.

DATA: it_table1 TYPE TABLE OF ty_structure,                    Declaration of Internal Table       

            wa_table1 TYPE ty_structure.                                        Declaration of Work Area


Field Symbols –

    • Field symbols are placeholders and do not physically reserve space.

    Syntax:             FIELD-SYMBOLS <FS> TYPE <Data Objects>.

    • This Field symbol should be assigned by any data object before using it.
    • Addressing a Field symbol means it address the field assigned to it.
    • Equivalent to MODIFY Statement when used as Work area for Internal Table.

Example:

  FIELD-SYMBOLS<fs_wa> type ty_structure.

   READ TABLE it_table1 assigning <fs_wa> INDEX 1.

       IF sy-subrc = 0.

        <fs_wa>-field2 = <fs_wa>-field1 + <fs_wa>-field2.

       ENDIF.

  ASSIGN wa_table1 to <fs_wa>.


Internal Tables –

    • Type of Internal Tables should be based on the handling of data.
    • HASHED Tables are preferred for handling huge volume of data. Only unique entries can be loaded to it.
    • STANDARD Tables should be used when INDEX operations are required which is not possible in HASHED tables.
    • When multiple entries for the same key (Header and Detail Records) are required for processing STANDARD Tables should be used.

Example:  

                  DATA: it_table1_h TYPE HASHED TABLE OF ty_structure WITHUNIQUE KEY field1,   

                  it_table1 TYPE STANDARD TABLE OF ty_structure.

    • Reading an entry from STANDARD Table should be used with BINARY SEARCH. It should be sorted before based on the where condition.
    • Reading an entry from HASHED Table should be used with all the key fields when declared and also with keyword “TABLE KEY”. No Sorting should be made.
    • SY-SUBRC should be checked whenever Internal table is read using READ TABLE.

Example:  

              READ TABLE it_table1_h ASSIGNING <fs_wa> WITH TABLE KEY field1 = ‘100’.  

              SORTit_table1 BY field1ASCENDING.

              READ TABLE it_table1 ASSIGNING<fs_wa> WITH KEY field1 = ‘100’ BINARY SEARCH.


Nested Loops – Performance Killer

    • At any cause Nested Loops should be avoided and can be replaced by Parallel Cursor concept.
    • Main Internal Table can be of any type but the Inner Internal table should be of STANDARD table and should be sorted before based on the where condition.
    • Any number of Nested loops can be avoided by using the Parallel Cursor concept.

Parallel Cursor Concept

    • Looping the inner Internal table based on the INDEX.
    • Use Read Table statement instead of using two loops to read the Internal tables..


Example:      

                  DATA: l_tabix TYPE sy-tabix. 

                              LOOP AT it_table1_h ASSIGNING<fs_wa>. 

                                READ TABLE it_table1 TRANSPORTING NO FIELDS WITH KEY field1 = <fs_wa>-field1 BINARY SEARCH.       

                                  IF sy-subrc = 0.

                                    l_tabix = sy-tabix. 

                                    LOOP AT it_table1 ASSIGNING<fs_wa2> INDEX l_tabix.

                                    IF<fs_wa2>-field1 <> <fs_wa>-field1.

                                       EXIT.

                                   ELSE.    

                                 ……..                                       <code for processing>.                                      ……..         

                                   ENDIF.                        

                                  ENDLOOP.  

                       ENDIF. 

                   ENDLOOP.


Points to Remember while using Select statements :-
      • Only required fields should be fetched from DB table.
      • Selection fields should be in the order as in DB table.
      • INTO CORRESPONDING FIELDS OF TABLE should be avoided.
      • Selection of entries should be restricted based on the required entries for selection.Use FOR ALL ENTRIES.
      • Entries in the Internal Table used in FOR ALL ENTRIES should be unique.
      • Fields in the WHERE condition should be primary key fields of the DB table with the same order as in DB.
      • Use of conditions like <, >, <>, LIKE, IN should be avoided in WHERE condition.
      • SELECT statements should not be used in the LOOP statements.
      • SELECT ENDSELECT should be avoided rather SELECT INTO TABLE should be used. Reduce the load on the Database Server.


Use the transaction code SE30 – ABAP Runtime Analysis to check the performance of the program.


Viewing all articles
Browse latest Browse all 943

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>