Monday, July 23, 2007

ABAP Performance and Tuning

What tools can be used to help with performance tuning?

ST05 is the SQL Trace transaction and can be used to measure the performance of the select statements of the program. SE30 is the Runtime Analysis transaction and can be used to measure the application performance. It also gives some tips on how to improve the performance through efficient code.

One of the best tools for static performance analyzing is Code Inspector (SCI). There are many options for finding common mistakes and possible performance bottleneck's.

What are the steps to optimise the ABAP Code?

  1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
  2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
  3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
  4. Either enable buffering in your database table or create Indexes to speed up the query.
  5. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
  6. Avoid using nested SELECT statement, SELECT within LOOPs.
  7. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
  8. Avoid using SELECT * and Select only the required fields from the table.
  9. Avoid nested loops when working with large internal tables.
  10. Use assign instead of into in LOOPs for table types with large work areas
  11. When in doubt call transaction SE30 and use the examples and check your code
  12. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search.
  13. Use "CHECK" instead of IF/ENDIF whenever possible.
  14. Use "CASE" instead of IF/ENDIF whenever possible.
  15. Use "MOVE" with individual variable/field moves instead of "MOVE-CORRESPONDING", creates more coding but is more effcient.

back to top

What is the difference between SELECT SINGLE and SELECT ... UP TO 1 ROWS?

SELECT SINGLE returns the first matching row for the given condition and it may not be unique, if there are more matching rows for the given condition.

SELECT ... UP TO 1 ROWS retrieves all the matching records and applies aggregation and ordering and returns the first record.

Inorder to check for the existence of a record then it is better to use SELECT SINGLE than using SELECT ... UP TO 1 ROWS since it uses low memory and has better performance.

back to top

Which is the better - JOINS or SELECT... FOR ALL ENTRIES...?

When using FOR ALL ENTRIES the number of matching records is restricted to the number of records in the internal table. If the number of records in the database tables is too large then join would cause overheads in performance. Additionally a JOIN bypasses the table buffering.

back to top

Does SAP publish guides and cookbooks on performance monitoring and testing?

Yes it does. You'll find a collection of resources for Performance monitoring and testing under SAP NetWeaver Administration on SDN.

back to top

User Collect Statement to do Sum in the internal table.

Instead of using logic to do summation use collect statement.

Avoid use of nested loops :

For example: if there is a loop like this:

loop at itab1

loop at itab2

end loop.

end loop.

in the production environment it may be possible that such loop may take much time n get dump error.

instead we can use

loop at itab1

Read itab2 key itab1-f1 '' f1 is any field of itab1

itab1-f2

v = sy-tabix.

now

loop at itab2 from v

end loop.

clear v.

in this case we can save lot of time by checking only relevant rows.


Test & Analysis Tools

  • ABAP Performance Trace (ST05)
  • ABAP Runtime Trace (SE30)
  • Coverage Analyzer (SCOV)
  • eCATT (SECATT)
  • Global Performance Analysis (ST30)
  • Memory Inspector (S_MEMORY_INSPECTOR)