In my little experience in the SAP ABAP/BW realm, I have encountered umpteen people, in BW space, especially while coding in routines (no offence to any community); not following the best practices of ABAP coding. Or rather, not following even the ‘good’ practices of ABAP coding.
This could be due to, either:
- Ignorance of
- The existence of such practices.
- The reason behind having such practices.
- Plain defiance or overlooking, just to complete the task in hand.
Argument 1 could be due to many factors and is something that can be easily worked upon.
Argument 2 is something that surely needs to be changed upon and developers should be educated and reasoned with the importance behind following some rules.
Here, I would take the liberty, to call us, developers, as “the lazy-bit” while trying to finish our task in hand, to get the desired results or rather in the BW space, the result would be, to get the data in the target.
I understand it is probably a bit of an exhaustive activity for the developers, in the BW space, to go and look for the DSAG guidelines or the ABAP practices in the SAP documents.
Hence I have attempted, to make a bare-minimum list, conversely as I would like to call it, the quick-look list for anyone to refer to and practice while coding in ABAP in BW.
I would like to request the BW developers to ‘at-least’ try and follow the below practices.
The practices, that I have listed below are being followed at my work-place. These are simple and once you implement it a couple of; it shall end up becoming a habit. And a good-habit at that one.
Before I start with the quick-look list, let me re-iterate, that I am not trying to teach anyone here; but following these won’t do any harm; rather it would only make the job of any developer easier.
- Use comments wherever needed.
- Comments should make sense and should help us understand why a particular code block/snippet was written.
- Use comment blocks or single line comments wherever applicable.
- Check your pretty printer settings and then click pretty printer before you save and activate your code.
- Select only the required fields; no Select * from
- Select all required fields from a table in a single select statement. Try and hit a database table only once.
- Try using all key fields in a where clause and avoid using non key fields in the same.
- Select inside a loop is a strict NO.
- Use for all entries wherever necessary.
- Sort and delete duplicates from the internal table before using for all entries.
- Check if internal table is not initial before using for all entries.
- Try and avoid using loop inside loop. If using internal loops; please use partial looping. Sort internal table before using partial looping. Partial Looping can be achieved by using loops with where clause.
- Try and use <field-symbols> rather than work-area when looping into or reading into.
- Try and use Read instead of loops inside loops.
- Try to use Sorted Tables or Hashed Tables for internal tables wherever possible. This way you need not use Binary Search.
- Please sort before you use Binary Search with a standard table. Would rather recommend never to use standard tables/binary search.
- Always check sy-subrc value after every read. Only if the value is 0, process further, else handle the exception.
- Name of the declared object should make proper sense.
- Always follow a convention for declaration which will help make the code easier to understand and trace. Check the latest SAP guidelines for the same.
- Declare and define structure to be used for internal tables, with the required fields. Don’t directly use the existing DDIC table as most of the times we won’t be using all the fields of the DDIC table. This will help save memory.
Please do note, that “I am still learning” and hence the title being “good” and not “the best”.
Please comment below with other best practices that are being followed by you or at your work place. I would like to keep updating/correcting this list as with the help of other members.