Skip to Content

General guidelines for ABAP coding in BW:

<strong>Business Case:</strong></p><p>ABAP coding is very widely used in any BW implementation for writing routines in transformation. Bad ABAP code written in transformation can adversely affect the data accuracy as well as data loading performance.   This document is prepared for SAP BW developer to follow some best practices while writing ABAP code in BW. By following these best practices, you will be able to achieve best data loading performance as well as data accuracy.</p><p>1) When to use Start Routine: </p><p>Make use of Start Routine for the scenarios listed below* 

    1. Processing all the data packet records at once. For example, to delete records or update records with new value.
    2. To acquire the runtime information of a data transfer process (DTP).
    3. To populate internal table and utilize in field level routine.

 2) How to define Internal Table: 

    Example:</p><p>              TYPES: BEGIN OF TYPE_<name>,</p><p>                 …………….</p><p>               END OF TYPE_<name>.</p><p>               DATA: T_<name> TYPE SORTED TABLE OF TYPE_<name> </p><p>                         WITH NON-UNIQUE KEY <key1> <key2> ……</p><p> Or</p><p>                DATA: T_<name> TYPE HASHED TABLE OF TYPE_<name> </p><p>                          WITH UNIQUE KEY <key1> <key2> ……</p><p> </p><p>3) How to Read Internal Table:

      1. Always read Internal table using ASSIGNING Field Symbol unless there is a need for the Work Area.


    +                  + READ TABLE <itab> ASSIGNING <field_symbol></p><p>                          WITH TABLE KEY <key1> = ….. </p><p>                           <key2> = ……</p><p>4) How to loop on SOURCE_PACKAGE :</p><ul><li>Always use Field Symbols while looping on SOURCE_PACKAGE unless there is a need for the Work Area.</li><li>Always use Field Symbols to modify SOURCE_PACKAGE field content.</li></ul><p>Example:* 5) Try to avoid: Example:     Example:</p><p>          SELECT EBELN EBELP MATNR</p><p>                INTO CORRESPONDING FIELDS OF TABLE itab</p><p>                FROM EKPO.</p><p>          LOOP AT SOURCE_PACKAGE assigning <SOURCE_FIELDS>.</p><p>               READ TABLE itab ASSIGNING <l_itab></p><p>                    WITH TABLE KEY <key1> = ……. <key2> =  ….</p><p>          ENDLOOP.</p><p> </p><ul><li>Avoid SELECT inside field level routine. Instead it is always advisable to collect all the data in an internal table in the start routine and then read that internal table inside field level routine.</li></ul><p>6) Important DON’Ts 

      1. DO NOT include the statement BREAK-POINT in any code sent to production.
      2. DO NOT directly update, insert or delete records from SAP tables such as Master data table or DSO Active table.
      3. DO NOT directly use text literals (such as ‘P’, ‘BASIS’, etc). Instead declare them as constants in the global area of the start routine.

     7) Points to be considered for the optimal data loading performance: Follow the points mentioned in the item 5 “Try to avoid” above.

      1. Use JOIN to select multiple tables with same parameters.
      2. Check if record already exists in the internal table before executing SELECT or   calling function module:

    It is a best practice to store data selected from database table into an internal table and read that internal table to verify if record with similar combination does exist in that internal table before executing SELECT or calling function module. This way you can avoid duplicate selects on the database and improve the data loading performance.

    Example:When you use “FOR ALL ENTRIES IN” statement in SELECT, do not forget to check if reference internal table is not initial.

      Example:</p><p>            IF <reference internal table> IS NOT INITIAL.</p><p>                 SELECT EBELN EBELP MATNR</p><p>             INTO CORRESPONDING FIELDS OF TABLE <itab></p><p>             FROM <table></p><p>             FOR ALL ENTRIENS IN <reference internal table></p><p>            WHERE …</p><p>       ENDIF.</p><p> </p><p>8) Points to be considered from data accuracy stand point:

      To report this post you need to login first.


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

      1. Martin Maruskin
        Hi, thanks for blogging. Just to add couple of SAP Notes on start/end/expert routines.

        1227667 – Guidelines for expert routine: Design rules
        1223532 – Design rules: Adding records to end routine
        1258089 – Design rule: Adding records to the start routine


      Leave a Reply