ABAp Performance
ABAp Performance
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. Create new indices if necessary, but do not forget to check the impact by
consulting onsite coordinator.
TYPE (data element) command is used while declaring the fields whenever feasible
instead of LIKE. Remember not always the data element name matches with the table
field name
In SELECT statement, only the required fields are selected in the same order as they
reside on the database table/structure/view
No SELECT * is used
Always select into an internal table, except when the table will be very large (i.e.,
when the internal table will be greater than 500,000 records). Use “Up to N Rows”
when the number of records needed is known
Nested Select is not used instead “Inner Join” and/or “For all Entries” is used. “For all
Entries” is to be used over “Loop at ITAB / Select / ENDLOOP” (FOR ALL
ENTRIES retrieves a unique result set so ensure you retrieve the full key from the
database)
o When creating joins over database tables there should be an index at least on
the inner table for the fields in the join condition else use “ FOR ALL
ENTRIES” select statement
Usage of JOIN is limited to a maximum of 2 i.e. not more than 3 database tables are
joined at one time
CHECK that the internal table used in FOR ALL ENTRIES is NOT empty as this will
retrieve all entries from the table
Delete adjacent duplicate entries from internal table before selection from database
table using “ FOR ALL ENTRIES” statement
For copying internal tables use ‘=’ operator instead of Looping & Appending
Sort internal table by fields in the correct order, which are used in a READ TABLE
statement using BINARY SEARCH. If the order of sorting is invalid the BINARY
SEARCH will never work
For large internal tables where only some rows are to be processed, use SORT and
then the READ TABLE command is used to set index to first relevant row before
looping from that index. Use CHECK or IF…EXIT…ENDIF as appropriate to exit
from the loop
Sort fields and Sort Order on the SORT statement should be mentioned explicitly (e.g.
SORT ITAB BY FLD1 FLD2 ASCENDING)
Hashed table is used for processing large amount of data (provided that you access
single records only, and all with a fully specified key)
Sorted table is used for range accesses involving table key or index accesses
Fields specified in the WHERE condition with the critical operators NOT and <>
(negative SQL statements) cannot be used for a search using database indexes.
Whenever possible formulate SQL statements positively
When coding IF or CASE, testing conditions are nested so that the most frequently
true conditions are processed first. Also CASE is used instead of IF when testing
multiple fields “equal to” something
After the APPEND statement inside a loop, the work area that has been appended is
cleared
Internal tables, Work areas & Global Variables are freed when no longer needed (e.g.
using the FREE / REFRESH command), especially when the tables are large or the
program is a batch program
Do not delete the records of internal table inside the Loop – End loop.
Do not use: LOOP AT ITAB WHERE EQUNR = ‘00001011’.
DELETE ITAB.
ENDLOOP.
Use: DELETE ITAB WHERE EQUNR = ‘00001011’.
Use the MODIFY ITAB ... TRANSPORTING f1 f2 ... for single line, and MODIFY
ITAB ... TRANSPORTING f1 f2 ... WHERE condition for a set of line, to accelerate
the updating of internal table
Try to avoid logical databases. If your program uses a logical database, but does not
require all fields belonging to a certain GET event, always use the FIELDS addition
to reduce the amount of data selected by the logical database
Avoid the aggregate (Count, Max, Min) functions in the database selection
Use Parallel Cursor methods for nested loop into the internal tables if second internal
table contains considerable number of records