18-Performance Tuning in SAP ABAP
18-Performance Tuning in SAP ABAP
18-Performance Tuning in SAP ABAP
Run-time analysis
Check efficiency of SAP ABAP programs and Function modules using SAP
run-time analysis
code in terms of what is the load on the database server, application server, presentation
server etc.
The run-time analysis will display the load in a graph with %'s and the time in micro
seconds.
The graph will be displayed with either red color or green color.
If the graph contains green color, then the program execution time is very good or very
less.
If the graph contains red color, the program execution time is very bad or very long .
Always make sure the the load on database server should be less than 40% and should
be green.
Go to SE30, provide program name, click on execute button, the out put will bi displayed, click on
back and click on evaluate to see run-time analysis.
In the above image you can see ABAP and database layers are in red color, means the time
taken to process these layers is more.
Program:2
Now change the above program like below and test again.
REPORT ZSAN_SE30.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
You can see the database layer is in green color means the standards are good.
A good program with coding standards always have database layers is in green color.
SQL Trace which is used to trace time execution for open SQL statements like select,
insert, update, delete etc.
Enqueue Trace which is used to trace locking and unlocking of lock objects.
Buffer Trace, this is used to monitor table buffer accesses.
RFC Trace, this is used to trace remote calls made of a application.
HTTP Trace which is used to trace HTTP requests(ex: browser requests) of SAP
applications.
To perform trace operations go to ST05, select trace, activate trace, open another session and
execute the application which we wants to trace, comeback to ST05, deactivate the trace and
display the trace.
Bad example
Good example
WHERE MATNR =
'0001'.
BINARY SEARCH.
Programming Standard
Bad example
Good example
WHERE MATNR =
IT_MARA-MATNR.
ENDIF.
ENDLOOP.<br>ENDLOOP.<br>
VKORG
VTWEG FROM MVKE INTO TABLE IT_MVKE
FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
LOOP AT IT_MARA INTO WA_MARA.
LOOP AT IT_MVKE INTO WA_MVKE WHERE MATNR = WA_MARA-MATNR.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MVKE-VKORG, WA_MVKEVTWEG.
ENDLOOP.
ENDLOOP.
SELECT MATNR
VKORG
VTWEG FROM MVKE INTO TABLE IT_MVKE
FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
SORT: IT_MARA, IT_MVKE.
DATA V_INDEX TYPE SY-TABIX.
LOOP AT IT_MARA INTO WA_MARA.
READ TABLE IT_MVKE INTO WA_MVKE WITH KEY MATNR = WA_MARA-MATNR BINARY SEARCH.
IF SY-SUBRC = 0.
V_INDEX = SY-TABIX.
LOOP AT IT_MVKE INTO WA_MVKE FROM V_INDEX. "no where condition for loop
IF WA_MVKE-MATNR <> WA_MARA-MATNR.
EXIT.
ENDIF.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MVKE-VKORG, WA_MVKEVTWEG.
ENDLOOP.
ENDIF.
CLEAR: WA_MARA, WA_MVKE.
ENDLOOP.
1. When reading data from database table, never use SELECT *, always use
select with list of fields.
2. Always specify key fields in where conditions of SELECT statements,
because these will have primary index.
3. Sometimes we may need to use non-key fields in where conditions of
SELECT statements, in that case create secondary indexes and use.
4. Never use select with corresponding in SELECT statements.
5. Always use read table with binary search and make you have sorted the
internal table in ascending order before using read table binary search.
6. Never use select joins for more than 3 tables.
7. Always use select for all entries for more than 3 tables.
8. Always check whether the parent internal table is initial or not before using for
all entries.
9. Never use nested loops, instead use parallel cursor .
10. Never use select statements inside loops, instead use for all entries.