Need for Performance Tuning
In this world of SAP programming, ABAP is the universal language. in most of the projects, the focus is on getting a team of ABAP programmers as soon as possible, handing over the technical specifications to them and asking them to church n out of the ABAP programs within the "given deadlines ".
Often due to this pressure of schedules and deliveries, the main focus of making a efficient program takes a back seat. an efficient ABAP program is one which delivers the required output to the user in a finite time as per the complexity of the program, rather than hearing the comment "I put the program to run, have my lunch and come back to check the results ".
Leaving aside the hyperbole, a performance optimized ABAP program saves the time of the end user, thus increasing the productivity of the user, and in turn keeping the user and the management happy.
This tutorial focuses on presenting various performance tuning tips and tricks to make the ABAP programs efficient in doing their work. this tutorial also assumes that the reader is well versed in all the concepts and syntax of ABAP programming.
Note: Performance of a program is also often limited due to hardware restrictions, which is out of the scope of this article.
========================================================== ========================================================== ===
This tutorial contains a number of pages, each one explaining a tip or trick. you can either browse them one by one (click on the next button, or jump straight to a tip or trick which interests you:
-
Introduction (this page)
-
Selection criteria
-
Aggregate functions
-
Views instead of base tables
-
The "into table" clause
-
Modifying a group of lines
Use of binary search option
-
Appending two internal tables
-
Table Buffering
-
Use of "for all" entries
-
Proper structure of "where" clause
-
Proper use of "move" Statement
-
Proper use of "inner join"
-
Use of "ABAP sort" instead of "order"
-
Tools for analysis of performance
Use of selection criteriaUse standard query
Instead of selecting all the data and doing the processing during the selection, it is advisable to restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code.
Not recommended
Select * From zflight.
Check: zflight-airln = 'lf 'and zflight-fligh = 'bw222 '.
Endselect.
Recommended
Select * From zflight where airln = 'lf 'and fligh = '000000 '.
Endselect.
One more point to be noted here is of the select *. often this is a lazy coding practice. when a programmer gives select * even if one or two fields are to be selected, this can significantly slow the program and put unnecessary load on the entire system. when the application server sends this request to the database server, and the database server has to pass on the entire structure for each row back to the application server. this consumes both CPU and networking resources, especially for large structures.
Thus it is advisable to select only those fields that are needed, so that the database server passes only a small amount of data back.
Also it is advisable to avoid selecting the data fields into local variables as this also puts unnecessary load on the server. instead attempt must be made to select the fields into an internal table.
Use of Aggregate functionsUse Aggregate functions
Use the already provided aggregate functions, instead of finding out the minimum/maximum values using ABAP code.
Not recommended
Maxnu = 0.
Select * From zflight where airln = 'lf 'and cntry = 'in '.
Check zflight-fligh> maxnu.
Maxnu = zflight-fligh.
Endselect.
Recommended
Select max (fligh) from zflight into maxnu where airln = 'lf 'and cntry = 'in '.
The other Aggregate functions that can be used are min (to find the minimum value), AVG (to find the average of a data interval), sum (to add up a data interval) and count (counting the lines in a data selection ).
Use of views instead of base tablesReplacing basic tables with views
When times ABAP programmers deal with base tables and nested selects. instead it is always advisable to see whether there is any view provided by SAP on those base tables, so that the data can be filtered out directly, rather than specially coding for it.
Not recommended
Select * From zcntry where cntry like 'in % '.
Select single * From zflight where cntry = zcntry-cntry and airln = 'lf '.
Endselect.
Recommended
Select * From zcnfl where cntry like 'in % 'and airln = 'lf '.
Endselect.
========================================================== ========================================================== ===
Use of the into Table clause of select statementInsert table clause when selecting a statement
Instead of appending one record at a time into an internal table, it is advisable to select all the records in a single shot.
Not recommended
Refresh: int_fligh.
Select * From zflight into int_fligh.
Append int_fligh. Clear int_fligh.
Endselect.
Recommended
Refresh: int_fligh.
Select * From zflight into Table int_fligh.
========================================================== ========================================================== ===
Modifying a group of lines of an internal tableModify a group of rows in the internal table
Use the variations of the modify command to speed up this kind of processing.
Not recommended
Loop at int_fligh.
The IF int_fligh-flag is initial.
Int_fligh-flag = 'x '.
Endif.
Modify int_fligh.
Endloop.
Recommended
Int_fligh-flag = 'x '.
Modify int_fligh transporting flag where flag is initial.
========================================================== ========================================================== ===
Use of binary search optionUse semi-Query
When a programmer uses the READ command, the table is sequentially searched. this slows down the processing. instead of this, use the binary search addition. the binary search algorithm helps faster search of a value in an internal table. it is advisable to sort the internal table before doing a binary search. binary Search repeatedly divides the search interval in half. if the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.
Not recommended
Read Table int_fligh with key airln = 'lf '.
Recommended
Read Table int_fligh with key airln = 'lf 'binary search.
========================================================== ========================================================== ===