ABAP Performance Tuning

34
IBM Global Services ABAP Performance Tuning May 2006 © 2006 IBM Corporation ABAP Performance Tuning

description

ABAP Performance Tuning

Transcript of ABAP Performance Tuning

Online DebuggingIncrease efficiency of ABAP code.
Identify performance problems and correct them.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Run time analysis
Transaction SE30
To analyze the performance of any transaction or program created within the ABAP Workbench.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
To examine the database calls of reports and transactions.
Only one user can use the trace tool at a time. So, it is very important to switch off the tool as soon as the execution is over.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
CHECK: SBOOK_WA-CARRID = 'LH' AND 1201 s
SBOOK_WA-CONNID = '0400'.
WHERE CARRID = 'LH' AND 861 s
CONNID = '0400'.
ENDSELECT.
Always specify your conditions in the Where-clause instead of checking them yourself with Check-statements. The database system can then use an index (if possible) and the network load is considerably less.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
EXIT.
ENDSELECT.
WHERE CARRID = 'LH'.
 
If you are interested in only one row of a database table or view with a certain condition, use the Select ... Up To 1 Rows statement instead of a Select-Endselect loop.
If all primary key fields are supplied in the Where condition you can even use Select Single. Select Single requires one communication with the database system, whereas Select-Endselect needs two.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
WHERE SPRSL = 'D' AND
ARBGB = '00'. 18386 s
WHERE SPRSL = 'D' AND 587 s
ARBGB = '00'. 
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself. Network load is considerably less.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
WHERE DOMNAME LIKE 'CHAR%' 20880 s
AND AS4LOCAL = 'A'.
 
Use a select list or a view instead of Select * , if you are only interested in specific columns of the table. Network load is considerably less.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
APPEND T006_WA TO X006.
 
It is always faster to use the Into Table version of a Select statement than to use Append statements.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Select-Endselect vs. Array-Select
SELECT * FROM T006
ENDLOOP.
ENDSELECT.
 
Selecting data into an internal table using an array fetch versus a Select-Endselect-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.
If you process your data only once, use a Select-Endselect-loop instead of collecting data in an internal table with Select Into Table. Internal table handling takes up much more space.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Select with join
AND CONNID = SPFLI_WA-CONNID.
SELECT * INTO WA
FROM SPFLI AS P INNER JOIN SFLIGHT AS F 1660 s
ON P~CARRID = F~CARRID AND
P~CONNID = F~CONNID.
 
To read data from several logically connected tables, use a join instead of nested Select statements. Network load is considerably less.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
INSERT INTO CUSTOMERS VALUES TAB_WA. 2 s
ENDLOOP.
 
Whenever possible, use array operations instead of single-row operations to modify your database tables. Frequent communication between the application program and database system produces considerable overhead.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
SFLIGHT_WA-SEATSOCC =
 
Whenever possible, use column updates instead of single-row updates to update your database tables. Network load is considerably less.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Is the program using SELECT … ORDER BY statements?
Data should be read into an internal table first and then sorted, unless there is an appropriate index on the ORDER BY fields.
The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server.
Are there SELECTs without WHERE condition against files that grow constantly (BSEG, MKPF, VBAK)?
Program design is wrong - back to the drawing board.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
For all entries
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
·         Mixing processing and reading of data
·         Fast
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
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 that a BETWEEN statement is used instead of an OR statement:·        
FOR ALL ENTRIES IN i_tab
WHERE mykey >= i_tab-low
and         mykey <= i_tab-high.
When using FOR ALL ENTRIES, the driver table must not be empty, otherwise the selection is not limited.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Check for Equality and Link Using AND
The database index search is particularly efficient if you check all index fields for equality (= or EQ) and link the expressions using AND.
Using OR
The optimizer usually stops working when an OR expression occurs in the condition. This means that the columns checked using OR are not included in the index search.
You should try to reformulate conditions that apply OR expressions to columns relevant to the index, for example, into an IN condition.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Using Positive Conditions
The database system only supports queries that describe the result in positive terms, for example, EQ or LIKE. It does not support negative expressions like NE or NOT LIKE.
If possible, avoid using the NOT operator in the WHERE clause, because it is not supported by database indexes; invert the logical expression instead.
Using Part of the Index
If you construct an index from several columns, the system can still use it even if you only specify a few of the columns in a condition. However, in this case, the sequence of the columns in the index is important.
A column can only be used in the index search if all of the columns before it in the index definition have also been specified in the condition.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
ITAB = WA.
 
 
Avoid unnecessary MOVEs by using the explicit work area operations.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
* Entries: 1000
* 5 entries of which match the key condition Time 341 s
 LOOP AT ITAB INTO WA.
CHECK WA-K = 'X'.
* Entries: 1000
* 5 entries of which match the key condition Time 113 s
 LOOP AT ITAB INTO WA WHERE K = 'X'.
" ...
 
LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally. As with any logical expressions, the performance is better if the operands of a comparison share a common type. The performance can be further enhanced if LOOP ... WHERE is combined with FROM i1 and/or TO i2, if possible.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Small Internal Table vs. Complete Internal Table
 
data: tvbak like vbak occurs 0 with header line.
Use this:
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Modifying single lines
  
 
 
* component are moved.
 
With the MODIFY variant "MODIFY itab ... TRANSPORTING f1 f2 ..." the task of updating a line of an internal table can be accelerated. he longer the table line is, the larger the speed-up is. The effect increases for tables with complex structured line types.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
* The READ ends with SY-SUBRC=4
READ TABLE ITAB INTO WA
WITH KEY K = 'X'. 332
 
 
 READ TABLE ITAB INTO WA
WITH KEY K = 'X' 6
BINARY SEARCH.
If internal tables are assumed to have many (>20) entries, a linear search through all entries is very time-consuming. Try to keep the table ordered and use binary search or used a table of type SORTED TABLE.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
* Line width: 500
 
ENDLOOP.
* Line width: 500
 
 
With the APPEND variant "APPEND LINES OF itab1 TO itab2" the task of appending a table to another table can be transferred to the kernel.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
* 500 pairs of duplictaes
IF WA = PREV_LINE.
DELETE ITAB. 1697
* 500 pairs of duplictaes
COMPARING K.
 
With the DELETE variant "DELETE ADJACENT DUPLICATES" the task of deleting duplicate entries can be transferred to the kernel.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
ELSEIF C1A = 'E'. WRITE '5'. 7
ELSEIF C1A = 'F'. WRITE '6'.
ELSEIF C1A = 'G'. WRITE '7'.
ELSEIF C1A = 'H'. WRITE '8'.
ENDIF.
WHEN 'E'. WRITE '5'.
WHEN 'F'. WRITE '6'.
WHEN 'G'. WRITE '7'.
WHEN 'H'. WRITE '8'.
ENDCASE.
CASE statements are clearer and after about five nested IFs, the performance of CASE is more efficient. When coding IF or CASE, testing conditions should be nested so that the most frequently true conditions are processed first.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
kunnr = t_bseg-kunnr .
Select kunnr name1 from kna1 into table t_kna1 .
Sort t_kna1 by kunnr .
Loop at t_bseg .
Read table t_kna1 into wa_kna1 with key kunnr = t_bseg-kunnr binary search .
w_name = wa_kna1-name1 .
Use local variables in modularization units.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Coding Standards
Program attributes should be properly maintained. Check ‘Editor lock’ checkbox is not set.
Program should have a header flower box before "REPORT" statement according to the program specification.
CODE one command per line. This will allow for easier deleting, commenting, debugging, and most important, understanding.
Use Pretty Printer to align ABAP statements properly. Blank lines should be used to separate different sections of code.
Indent the source code for better understanding.
Program Documentation including half line comment should be maintained.
Every logical section of the program should be well documented in business language.
Follow proper naming conventions for program, DDIC objects, variables, internal tables, work areas, etc.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Check SY-SUBRC after performing data access statements such as select, read, get statements, etc. when applicable. If not required, put in a comment stating the reason.
Code executed more than once should be placed in a subroutine .
Avoid leaving "dead" code in the program. Comment out variables that are not referenced and code that is not executed.
Use EXTENDED SYNTAX CHECK after completion of development, minimize the number of errors and warning as much as possible
Remove the breakpoints in a program before transporting it to production server.
Internal tables with header lines are not allowed in the Object Oriented context.
Obsolete statements should not be used: TABLES, RANGES, INCLUDE STRUCTURE, OCCURS, LIKE.
Do not hard code values in code, use constants instead (but with meaningful names).
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
Using SORT within loop should be avoided.
After the APPEND statement inside a loop, clear the work area that has been appended.
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation
1.     Keep the Result Set Small
2.     Minimize the Amount of Data Transferred
3.     Minimize the Number of Data Transfers
4.     Minimize the Search Overhead
5.     Reduce the Database Load
Online Debugging | 3.14
IBM Global Services
© 2006 IBM Corporation