Skip to Content

Convert Microsoft Scipt logic to ABAP BADIs – Part 1

Your client has BPC Microsoft Version and there are multiple script logics written in the system. Now they want to move to BPC 7.5 version and convert the script logics to ABAP BADIs.

Script logics might consist of multiple commit blocks. At the end of each commit block data is written to the database. And in the new commit block data is read again from the database. Remember that this functionality is not available in the BADIs. In a BADI data is read from the database only once and its written only once at the end when the BADI ends.

Script logic statements are tricky sometimes and hence you need to be careful while implementing the same functionality in ABAP. Few lines of script logic might need multiple lines of ABAP functionality to implement the same logic.

So Lets start by understanding script logic statements in more detail.

We will talk here about the script logic in Microsoft version. There might be some changes to it in the Netweaver version. You will find that some statements are no longer now valid in Netweaver.

h2. BPC Script Logic Microsoft Version

 The below script logic is implemented on the Finance Application. This application consists of dimensions like Account, Datasrc, Func_Area, Category, Report_Unit, Rptcurrency, Time, Bev_prod and Profit_center.


SELECT(%Forecast%,”[ID]”,”TIME”,”[FORECAST]=’Y’ AND =’FORECAST'”)  </p><p> </p><p>XDIM_MEMBERSET ACCOUNT=A1, A2, A3








      *DIM VAR1:ACCOUNT=”A4″



WHEN LOOKUP(VAR1)</p><p>IS 1,2,3


    *IS “A1”

      *WHEN GET(Account=”A2 “,Datasrc=”INPUT”)


          REC (Account=”A5″,Datasrc=”FSP_SOURCE”,Expression=ROUND(%VALUE%/GET(Account=”A2″,Datasrc=”INPUT”)5.678,2))

          REC (Account=”A6 “,Datasrc=”OUTPUT”,Expression=ROUND(%VALUE%/GET(Account=”A2″,Datasrc=”INPUT”)5.678*GET(Account=”A3″,Datasrc=”INPUT”),2))


          *REC (Account=”A5″,Datasrc=”OUTPUT”,Expression=0)

          REC (Account=”A6″,Datasrc=”OUTPUT”,Expression=ROUND(%VALUE%/GET(Account=”A2″,Datasrc=”INPUT”)5.678*GET(Account=”A3″,Datasrc=”INPUT”),2))






Now lets try to understand the above mentioned script logic. A script logic consists of three main parts.

  • Processing : In this part you can use the data that you have scoped and create new records that will be stored in the database. Usually this will consist of statements like *WHEN, *REC

Commit : All the new records that are created during the processing get committed to the database with the COMMIT statement. </li></ol><p> </p><p>XDIM_MEMBERSET is the key word which is used to scope your data. So for each and every dimension of your InfoCube you can scope the data using this key word. If some dimension is not mentioned then it means that all dimension members are to be considered for it.

There are two variables used here. %CATEGORY_SET% is the variable that will be input through the data manager package. This is a single value variable over here and you can define this when you define your data manager package. Any variables from data manager are used with the SUFFIX “_SET”.

While %Forecast% is the variable which is defined using the select statement.

*SELECT(%Forecast%,”[ID]”,”TIME”,”[FORECAST]=’Y’ AND =’FORECAST'”)

This select statement implies -> Select the property ID from TIME DIMENSION where the property FORECAST = Y and DATASTATUS = FORECAST.


The statement XDIM_MAXMEMBERS = 25 means that for every 25 profit centers the script logic will be called. This statement can be used to improve performance since calling the script logic for all profit centers might be time consuming. However it can also decrease the performance at times since it will involve reading data from the database again and again.</p><p> </p><p>XDIM_NOSCAN : Whatever member is specified in the XDIM_NOSCAN is not passed through the when Block . Eg. Here we have *XDIM_NOSCAN DATASRC = INPUT. So this means that all the records that have DATASRC value as INPUT will not be passed through the WHEN block later on. So it is similar to writing, WHEN DATASRC <> INPUT. You need to be careful about this statement while implementing it in ABAP. The datasrc INPUT is kept in the scope only because its used in the GET Statements. You can only do a GET Statement on the data that is in scope.


LOOKUP : The lookup statement is generally used to lookup data from any application. Here our scipt logic is based on the Finance Application. And again we are doing a lookup on the finance application. Also the variable defined here with lookup is VAR1 which corresponds to Account A4 and DATASRC INPUT. So all other dimensions for this lookup will be similar to what is been defined in the scoping statements. So instead of doing a lookup you can also add account A4 to the scope and then refer to it using a GET Statement. That would mean exactly similar thing.


 Now lets understand the WHEN Statement. Each when statement is like a loop and it scans all the records that are in scope one by one. For eg. When Account = A1. This statement will only be true for any record where account = A1.

Now when you say WHEN GET(Account=”A2 “,Datasrc=”INPUT”)</p><p>IS<>0

Get statement reads a record from all the records that are in scope. So here the get statement will read a record where Account = A2 and Datasrc = INPUT, while all other dimensions of that record will be similar to the record currently in scope which is record with Account = A1(that corresponds to the WHEN Statement before it. )

Remember that Get statement can only read records from the data that is in scope. You cant read any data directly from the Cube using a Get Statement.
So when the signed data value of the record returned from the get statement is not equal to 0, the next statement is processed.


REC (Account=”A5″,Datasrc=”OUTPUT”,Expression=ROUND(%VALUE%/GET(Account=”A2″,Datasrc=”INPUT”)5.678,2))

Each *REC Statement generates a record. The above REC Statement will generate a record with Account = A5 and Datasrc = OUTPUT. All other dimensions of the record created will be equal to the dimension of the record in scope. %VALUE% here means the signeddata value of the record in scope.

Remember that the *REC Statement overwrites the value in the cube. So if you are creating a record with dimension values that already exist in the cube then that signed data value is overwritten with the new value that you create and not added.You need to be careful about this when you are writing ABAP Code. We will discuss this in the later sections.


h2. Logic File


We will create an LGF File and write the below mentioned statements in that file. So here we scope the data first and then call the BADI. You can also directly call the BADI but that’s not a good option since it would call the BADI with all the data in the Cube. Incase if you have multiple commit blocks in your script file then you the scoping has to be the union of all the scopes in the multiple blocks.


SELECT(%Forecast%,”[ID]”,”TIME”,”[FORECAST]=’Y’ AND =’FORECAST'”)  </p><p> </p><p>XDIM_MEMBERSET ACCOUNT=A1, A2, A3, A4





START_BADI CALC_PERFORM</p><p>QUERY = ON</p><p>WRITE = ON</p><p>END_BADI ***<br /><br />create data lt_fs like ct_data.<br />assign lt_fs-> to 

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