Performance Tuning
Contributed by Henrik Frank
For all entries
Nested selects
Select using JOINS
Use the selection criteria
Use the aggregated functions
Select with view
Select with index support
Select … Into table
Select with selection list
Key access to multiple lines
Copying internal tables
Modifying a set of lines
Deleting a sequence of lines
Linear search vs. binary
Comparison of internal tables
Modify selected components
Appending two internal tables
Deleting a set of lines
Tools available in SAP to pin-point a performance problem
Optimizing the load of the database
The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
The plus
Large amount of data Mixing processing and reading of data Fast internal reprocessing of data FastThe Minus
Difficult to program/understand Memory could be critical (use FREE or PACKAGE size)Some steps that might make FOR ALL ENTRIES more efficient:
Removing duplicates from the driver table Sorting the driver table If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement: FOR ALL ENTRIES IN i_tab WHERE mykey >= i_tab-low and mykey <= i_tab-high.The plus:
Small amount of data Mixing processing and reading of data Easy to code - and understandThe minus:
Large amount of data when mixed processing isn’t needed Performance killer no. 1The plus
Very large amount of data Similar to Nested selects - when the accesses are planned by the programmer In some cases the fastest Not so memory criticalThe minus
Very difficult to program/understand Mixing processing and reading of data not possible
Using buffered tables improves the performance considerably. Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed. These statements are:
Select DISTINCT ORDER BY / GROUP BY / HAVING clause Any WHERE clause that contains a sub query or IS NULL expression JOIN s A SELECT... FOR UPDATEIf you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause.
The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server.
If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it.
As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.