Wednesday, July 30, 2014

Difference between 1st and 2nd global declarations in BW routines

Savvy BW developer may notice that there are two areas when it comes to global data declaration in transformation’s routines. Start/end (and also Expert) routines are quite heavily used within the transformation. The routines are generated as per templates. While coding in ABAP we following areas reserved for us:

1st area for ABAP code:
*$*$ begin of global - insert your declaration only below this line  *-*
... "insert your code here
*$*$ end of global - insert your declaration only before this line   *-*

2nd area ABAP code:
*$*$ begin of 2nd part global - insert your code only below this line  *
... "insert your code here
*$*$ end of 2nd part global - insert your code only before this line   *

3rd area for ABAP code:

*$*$ begin of routine - insert your code only below this line        *-*
... "insert your code here
*--  fill table "MONITOR" with values of structure "MONITOR_REC"
*-   to make monitor entries
... "to cancel the update process
*    raise exception type CX_RSROUT_ABORT.

*$*$ end of routine - insert your code only before this line         *-*

While purpose of 3rd area is clear – it serves for real code which encapsulated the business logic of routines in case of other areas it is not that clear. The 3rd one is actually where the routine begins. It is either end_routine, start_routine or expert_routine METHOD begins. Why they are two areas for data declaration? If we have a look into SAP documentation available here or here we can found out:

This would suggest that: if data is declared in the 1st area then the data is available across all datapackage. If the same is declared in the 2nd area then the data is only available for the actual package. But this may not be really true.

Let’s see what else we can say about first two. One of theories to solve this can be that 1st area is used for data declaration according ABAP OO paradigm. 2nd one would be used for data declaration of pre-OO (or non OO) ABAP standards. But this again may not be true.
According SCN post in forum available here there was someone who got back to SAP with regards this mystery. If we can trust this post here’s what SAP said:

In the first global part you can write your declaration or code you want to be able to reach globally in the transformation.
The 2nd global part will be used for those transformations which are migrated from an update or transfer rule. Routines used there will be automatically generated into the 2nd global part.


Cyril Raffin said...

Thank you very much for this very interesting post !!

Cyril Raffin said...

Thank you very much ofr this very interesting explanation.

Best Regards.