“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
ABAP Performance Tuning Tips
1. ABAP Performance Tuning Tips
By : Jay Dalwadi
- Tofetch data you must write perfect select statement.
- WHERE clause in your SELECT statement to restrict the volume of data.
- Please use ‘into table’ instead of ‘into corresponding’.
- always use CASE … ENDCASE instead of IF…ENDIF.
- No SELECT * is used and For selecting single row SELECT UP to 1 Rows or Select Single
- Do not delete the records of internal table inside the Loop – End loop.
- Usage of JOIN is limited to a maximum of 2 or max 3 database tables are joined at one
time
- the internal table used in FOR ALL ENTRIES is not INITIALotherwise it will be retrieve
all entries from the database table.
- if possible, Update/Insert statement is used instead of Modify.
- Use transaction SE30 to check the code.
- Work-Areas is used instead of header lines
- Avoid using join statements if standard views exist.
- Avoid Executing an identical Select (same SELECT, same parameter) multiple times in
the program
- Use assign (field symbol) instead of into in LOOPs for table types with large work areas
- Delete adjacent duplicate entries from internal table before selection from database table
using “ FOR ALL ENTRIES” statement
- In the WHERE condition don’t use negative condition with ‘NOT’ operators .
If possible always use positive condition.
- Sort fields and Sort Order on the SORT statement should be mentioned explicitly
e.g. SORT ITAB BY FLD1 FLD2 ASCENDING)
INDEX: please use secondary Index for improving performance should not be taken
without thought. Give first preference who’s author IS SAP. Index speeds up the
performance
- Avoid use of nested loops.
Use sorted tables when nested loops are required also use a condition for the inner loop.
Otherwise in the production environment it may be possible that the loop takes a lot of
time and dumps.
loop at itab1.
loop at itab2 where f1 = itab1-f1.
....
endloop.
end loop.
2. - Always use BINARY SEARCH with READ TABLE statement
SORT itab2 BY f1.loop at itab1.
Read table itab2 with key f1 = itab1-f1 BINARY SEARCH.
if sy-subrc = 0.
idx = sy-tabix.
loop at itab2 from idx.
if itab2-f1 <> itab1-f1.
exit.
endif.
....
endloop.
endif.
endloop.
- Use FOR ALL ENTRIES or INNER JOIN in your SELECT to reduce hits
e.g .SELECT A~VBELN A~KUNNR A~KUNAG B~Name1
into table i_likp
FROM LIKP AS A
INNER JOIN KNA1 AS B
ON A~kunnr = B~KUNNR.
* For with limited data using for all entries:
* Minimize entries in I_likp by deleting duplicate kunnr.
LOOP AT i_likp INTO w_likp.
w_likp2-KUNAG = w_likp-KUNAG.
APPEND w_likp2 TO i_likp2.
ENDLOOP.
SORT i_likp2 BY kunnr.
DELETE ADJACENT DUPLICATES FROM i_likp2 COMPARING kunn * GET DATA
FROM kna1
IF NOT i_likp2[] IS INITIAL.
SELECT kunnr name1
INTO TABLE i_kna1
FROM kna1
FOR ALL ENTRIES IN i_likp2
WHERE kunnr = i_likp2-KUNNR.
ENDIF.