Show TOC

Background documentationPerformance Tips for ABAP Programming

 

In the BW system and the SAP source system, there are a number of places where you can write your own ABAP code:

  • In customer exits

  • In BAdIs

  • As routines in transformation

There are a number of rules that you should follow to ensure that your code does not impair performance:

  • Avoid nested loops as far as possible.

  • Avoid unnecessary loops. There is often an alternative. To implement deletion of records from an internal table for example, you can use a single statement instead of a loop over each record.

  • Avoid unnecessary database accesses. Only select records that you really need from the database, and use aggregate functions and grouping functions (SUM, MAX, MIN or GROUP BY, ORDER BY, HAVING).

  • Select the data once only If required, save them in global or static variables or instance attributes.

  • Avoid nested selections. Use the statement FOR ALL ENTRIES for views or subqueries instead. Be careful when using FOR ALL ENTRIES: Make sure that the internal table is not empty.

  • Use ARRAY operations rather than access by SINGLE. In other words, read an entire database table or a large part of a table into an internal table (in the start routine for a transformation) and access this internal table for each record to be read instead of reading directly from the database. Make sure though that these internal tables are not too large.

  • Avoid full-table scans. Use sorted tables and a binary search or hash tables instead. Hash tables are useful for accessing individual records and if data in the table changes frequently. Sorted tables are useful for accessing ranges, and normally require less memory space than hash tables.

  • If you access database tables directly, you should specify the entire key in the WHERE condition (to be able to use the primary key) or the part of the key that is used in one of the table's secondary indexes. Where possible, avoid using NOT in the WHERE condition, as table indexes are not supported for this. Note that the only part of the index that is used is that which is specified without gaps from the start.

    Example: Index contains fields F1, F2, F3, F4. A WHERE statement after F1, F3 and F4 only uses field F1 of the Index. The result set that still has to be searched after F3 and F4 will therefore have this size.

For more tips on performance in ABAP programming, see Tips and Tricks in the runtime analysis. To view this, choose Start of the navigation path SAP Menu Next navigation step Tools Next navigation step ABAP Workbench Next navigation step Test Next navigation step Runtime Analysis End of the navigation path.