Professional Documents
Culture Documents
The performance of any ABAP program mainly depends on the database accesses used in it. The more optimized the selections, the
better the performance. Consider the points mentioned in the following sections while writing any ABAP code that accesses the
database.
Avoid SELECT *
The SELECT * command is to be avoided rigorously, (unless you need every field in the table), because it drags every field in the table
through the I/O bottleneck thus slowing the program.
Avoid SELECT-ENDSELECT
Selecting data into an internal table using an array fetch versus a SELECT-ENDELECT loop will give at least a 2x performance
improvement. After the data has been put into the internal data, then row-level processing can be done..
Example:
select ... from table <..>
into <itab>
where ...
loop at <itab>
<do the row-level processing here>
endloop.
Using Indexes
When accessing the database, careful consideration should be given to index access in order to make the program as efficient as
possible. Tune the Query so that optimum indexing will happen.
Use the Where clause appropriately to use the proper index both should be in same order use ST05 or SE30 to analyse which index is
used.
1. Corresponding Internal table is not empty. If the Internal table is empty, the statement will select ALL the entries in the Database
2. The Internal table is sorted by the File used in the Where Clause: This makes selection faster. (And delete adjacent duplicates for
the key fields.)
Select Distinct
Whenever it's possible avoid SELECT DISTINCT, instead select data into internal table, sort and use DELETE ADJACENT DUPLICATES.
Order By
ORDER BY will bypass buffer. So, performance will decrease. If you want to sort data, it is efficient to SORT them in an internal table
rather than using ORDER BY. Only use an ORDER BY in your SELECT if the order matches the index, which should be used.
Append Lines of
Whenever it is possible use APPEND LINES OF to append the internal Tables instead of using loop and then APPEND Statement.
DELETE <itab>.
ENDLOOP.
Use
DELETE <itab> WHERE <field> = 0001.
Subroutine Usage
For good modularization, the decision of whether or not to execute a subroutine should be made before the subroutine is called.
Example:
IF f1 NE 0.
PERFORM sub1.
ENDIF.
FORM sub1.
...
ENDFORM.
Hashed table
If the number of entries in the Internal Table is high then use Hashed Table with Keys to access the table.
Transporting
With READ or MODIFY Statements use TRANSPORTING and specify the fields being transported.
Using LDB
In order to improve performance in case of an LDB, individual tables can be excluded from selection. Under the section Table
Selection in the Documentation of LDB the fields with proper description has been given those fields can be set in the application
report at the time of INITIALIZATION or at the START OF SELECTION. This can enhance the performance.
Use WHILE
Use WHILE instead of a DO+EXIT-construction, as WHILE is easier to understand and faster to execute
Identical Structures
If two structures are identical, use MOVE x to y, rather than MOVE-CORRESPONDING x to y
When records a and b have the exact same structure, it is more efficient to MOVE a TO b than to MOVE-CORRESPONDING a TO b.
MOVE BSEG TO *BSEG.
is better than
MOVE-CORRESPONDING BSEG TO *BSEG.
Order of tests
*Ensure that the first tested condition in an IF statement is most frequently true. For a logical AND statement put the most likely
FALSE case first, and conversely for a logical OR statement put the most likely TRUE statement first. (But this will only lead to a
noticeable performance improvement if the test is performed *very many times with a loop.
Nested loop
Ensure that instead of nested loop, parallel cursor method is used wherever possible. Parallel cursor method involves finding out the
index using READ statement & searching only the relevant entries. This will give huge performance benefits. And if possible, RFC
parallelization method can also be considered.
Nested loop
Loop at T1 into W1.
Loop at T2 into W2 where F1 = W1-F1.
Endloop
Endloop
Parallel cursor method
Loop at T1 into W1.
Read table T2 into W2 with key F1 = W1-F1 Binary Search.
l_index = SY-tabix.
Loop at T2 into W3 from l_index.
If W3-F1 <> W1-F1.
Exit.
Endif.
Endloop
Endloop
Use Parallel Cursor methods for nested loop into the internal tables if second internal table contains considerable number of records.
Index tables
Try to make use of INDEX tables as much as possible to improve the performance.
e.g.: If data needs to be fetched from VBAP table based on Material number which is not a key field, prior looking for a secondary index
with material, try to find whether any INDEX TABLE exists. In this case VAPMA is an index table which will return the SD Document
number and item where a material exists.
Note: In all the cases Index table may not exists and even if Index table exists make sure its active. i.e. the index table contains
approximately the same no entries compared to the main table
Performance diagnosis
To diagnose performance problems, it is recommended to use the SAP transaction SE30, ABAP/4 Runtime Analysis. The utility allows statistical
analysis of transactions and programs.
SQL Trace
Use transaction ST05 (SQL Trace) to see what indices your database accesses are using. Check these indices against your where clause to
assure they are significant. Check other indices for this table and where you have to change your where clause to use it.