Top 15 ABAP Coding Practices

The following best ABAP coding practices will help you make your ABAP program more performance and robust:

  1. Make sure that the code has explicit comments about the functionality of the implemented code logic.
  2. Unused variables or constants must be removed from the program.
  3. Limit hard coding elements.
  4. Declare elements (variables, internal tables, etc…) locally when used only in sub routines and pass globally declared elements to sub routines via parameters.
  5. Reduce code redundancy (avoid duplication of codes) by modularizing code whenever possible.
  6. Make sure that variables, work areas or internal tables have been cleared properly when required (especially inside loop).
  7. Implement appropriate checks in loop to prevent infinite loop.
  8. Before the FOR ALL ENTRIES statement, check if the table is not empty first, SORT the table and DELETE ADJACENT DUPLICATES from the table using the same set of keys that will be used on the FOR ALL ENTRIES statement. Please note: Empty tables in FOR ALL ENTRIES will retrieved all entries from database tables and can cause performance issue.
  9. Make sure all primary keys have been selected in FOR ALL ENTRIES select statement else it will retrieve only none duplicates lines of the selected fields.
  10. Make sure \’FOR ALL ENTRIES\’ is not done on cluster tables.
  11. No database statement (like SELECT, INSERT, UPDATE, DELETE, etc..) inside loop.
  12. Avoid multiple select statements on the same database table in the same program.
  13. The \’SORT INT_TABL BY <FIELDS X Y X>\’ statement must be used instead of just SORT INT_TABL (this will sort all fields in the internal table and this affect the performance). Also avoid sorting inside loop.
  14. Make sure BINARY SEARCH statement is used in READ statement and make sure table is sorted correctly before using BINARY search.
  15. Use \’SELECT UP TO 1 ROWS\’ when you don\’t have all primary keys and \’SELECT SINGLE\’ when you have all primary keys.

Happy coding.