Skip to Content

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:

  1. Ignorance of
    • The existence of such practices.
    • The reason behind having such practices.
  2. 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.

  • Comments:

    • 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 Queries:

    • 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.

 

  • Loop/Read:

    • 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.

 

  • Declaration:

    • 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.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Joachim Rees

    Hi Anish,

    thanks for sharing.

    I think it’s a good idea that you wrote down your good practices, and maybe use this also as a refference for others.*thumps up*

     

    I can agree with the general direction of your tipps!

    I also agree with

    Use for all entries wherever necessary.

    -> wherever necessary -> it never is 🙂

    I think Matthew Billingham will agree, and also on this:

    Would rather recommend never to use standard tables

     

     

    And for some fun:

    “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.”

     

    I do agree, and it reminded me of:

    “we put a loop in your loop so you can loop while your looping”  🙂

    (Explanation if needed: https://knowyourmeme.com/memes/xzibit-yo-dawg )

     

    keep on blogging!

    Joachim

    (2) 
    1. Matthew Billingham

      FAE is necessary sometimes in BW routines. This is because you implement your routine in method, where the incoming data is in the form of an internal table – it’s already been selected. You have no control over this.

      Sometimes, you can get round this in various ways, but often you just have to bite the bullet. There’s an OSS note somewhere which explains the db hints you can use, when the DB is HANA, so that it works ok.

      (1) 

Leave a Reply