Thursday, August 30, 2007

How to improve the performance of ABAP Program.

1. Always check the driver internal tables is not empty, while using FOR ALL ENTRIES

2. Avoid for all entries in JOINS

3. Try to avoid joins and use FOR ALL ENTRIES.

4. Try to restrict the joins to 1 level only ie only for tables

5. Avoid using Select *.

6. Avoid having multiple Selects from the same table in the same object.

7. Try to minimize the number of variables to save memory.

8. The sequence of fields in 'where clause' must be as per primary/secondary index

9. Avoid creation of index as far as possible

10. Avoid operators like <>, > , < & like % in where clause conditions 11. Avoid select/select single statements in loops. 12. Try to use 'binary search' in READ internal table. Ensure table is sorted before using BINARY SEARCH. 13. Avoid using aggregate functions(SUM, MAX etc) in selects( GROUP BY,HAVING,) 14. Avoid using ORDER BY in selects. 15. Avoid Nested Selects 16. Avoid Nested Loops of Internal Tables 17. Try to use FIELD SYMBOLS. 18. Try to avoid into Corresponding Fields of 19. Avoid using Select Distinct, Use DELETE ADJACENT Note: Also by going to transaction SE30->tips and tricks you can get the idea

Performance Optimization

Q) What is "Performance Tuning"? Why do we need it?

Depending on the complexity and volumes of data, ABAP programs often are vulnerable to time-out issues and short dumps. Users, in general (SAP/Non SAP) get annoyed by time consumiung applicationsas they (the programs) often affect user productivity, TCO of software and many more critical factors pertaining to the management of the software. This is where the need "Performance Tuning" arises.

So, what exactly is Performance Tuning?

This simply means - ensuring that an ABAP program performs efficiently. A good ABAP program to bring the desired output to the user within the desired timeframe. Thus increasing the productivity of users, saving a lot of time and keeping the management happy in the bargain.

Q) List out the benefits of Performance Tuning/Optimization.
  • Maximum user productivity
  • Minimum time-outs
  • Lower total cost of ownership - due to reduced timelines and increased productivity of users
  • Faster ROI (return on investment)
  • Easier upgradation

Q) List out the steps for Performance Tuning/Optimization.

Data declaration

  • Remove all code and variables that are not used in the program
  • Avoid declaring internal tables using LIKE or TYPE reference. Instead, use BEGIN OF... ... END OF ITAB.
  • Avoid declaring internal tables using 'occurs 0' & 'with header line'

SELECTs & DB access

  • Use selection criteria to effectively select and limit the number of database reads
  • Select only those columns that are needed – Do not use a SELECT * unless necessary
  • To populate an internal table thru a SELECT, use the INTO TABLE addition
  • To update table entries, specify the columns
  • Design your SELECT Query to Use as much index fields as possible from left to right in your WHERE statement
  • Use a SELECT SINGLE if the primary keys are known, otherwise SELECT UPTO 1 ROWS
  • Do not use nested SELECTs – Use views, joins or the FOR ALL ENTRIES option
  • Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
  • Do not use SELECTs in loops
  • Restrict the database access by using the WHERE clause – do not use a CHECK
  • Use indexes wherever available
  • Avoid NOT in the WHERE condition
  • Do not select the same data more than once
  • Avoid the SELECT DISTINCT Statement. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.

Processing data

  • Use aggregate functions wherever required instead of additional logic
  • Use sort on the internal table for small amounts of data and database ORDER BY for larger amount
  • Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search.
  • Use "CHECK" instead of IF/ENDIF whenever possible.
  • Use "CASE" instead of IF/ENDIF whenever possible.
  • Use "MOVE" with individual variable/field moves instead of "MOVE-CORRESPONDING"

Performing Checks

  • Perform the Extended Program Check
  • Perform Runtime Analyses

Q) List out the tools used Performance Tuning/Optimization.

  • Run time analysis transaction SE30
    This transaction gives all the analysis of an ABAP program with respect to the database and the non-database processing.
  • SQL Trace transaction ST05
    The trace list has many lines that are not related to the SELECT statement in the ABAP program. This is because the execution of any ABAP program requires additional administrative SQL calls. To restrict the list output, use the filter introducing the trace list.

No comments: