Skip to Content
After spending some time answering questions about script issues I’ve found the following:

In more than 60% of cases in order to give a useful answer I have to ask many additional questions to understand the issue!

I decided to summarize some generic rules to speed up the process:

1. Always provide BPC version and SP level of core BPC system (scripts work differently in 7.5 and 10 and even with different SP level). SP of BW component is also useful. This info is located in SAP GUI: Menu -> System -> Status…: SAP Data – Sap System Data – Product Version – Button Component information:

or for BW 750+ – only BW version:

2. For BPC NW 10 provide the K2 calculation engine used: ABAP or JAVASCRIPT (also difference in script execution). To test engine you can validate simple script in UJKT:

*WHEN ACCOUNT // or any dimension
*IS *
  *REC(EXPRESSION=Math.round(%VALUE%))
*ENDWHEN

If current engine is ABAP you will get error: “UJK_VALIDATION_EXCEPTION:Field “MATH” is unknown. It is neither in one of the specified tables nor defined by a “DATA” statement. “DATA” statement.

3. Please describe models/applications: full list of dimensions and some members examples relevant to the script discussed. For Account dimension members provide ACCTYPE property.

4. Clearly identify the purpose of the script: to run as default.lgf or to be launched by DM package (different calculation logic!). Please, ALWAYS answer this question!!!! If you want to write default.lgf script, please read: How-To: Write default.lgf

5. Describe the calculation logic using some pseudo formulas like: Amount=Price*Quantity etc. Add some description in words about calculation logic. Explain the business logic behind this script. In most cases it’s better to show sample data before script run and after.

6. Provide FULL script that is not working (showing only part of the script without some previous scope changes can lead to misunderstanding). It’s better to use “CODE” button to format the code text. Don’t use screenshot of the script!

7. For DM scripts define what user will select/enter for DM prompts. For default.lgf – explain the data sent by user in the input schedule.

8. The best option is to provide script tests in UJKT, including original script, Data Region content, PARAM content and log result with generated LGX. The information about UJKT usage can be found here: Testing Logic Script UJKT

9. Show report data before and after script run if the script is working, but generating incorrect results. Report data have to contain member names for better understanding. Don’t show the cube records in RSA1 – hard to analyze. In the most cases it’s better to show the report screenshot (inline, not as a separate attachment). At least using Firefox browser it’s easy to simply paste any picture in the message edit window (not working currently with latest versions of FireFox).

10. If there are questions about advanced DM scripts – full text of the advanced script have to be provided. Add also list of dimensions and text of script logic script.

Example:


Question name: Script write multiple of correct value

BPC NW 10 SP 11, Engine ABAP.

In the model SOMEMODEL we have the following dimensions: ACCOUNT (A), TIME (T), CATEGORY (C), ENTITY (E), CURRENCY (R), PRODUCT (User Def)

In the ACCOUNT dimension there are members PRICE (EXP),QUANTITY (EXP), DISCOUNT (EXP) and AMOUNT (EXP)

We want to calculate in default.lgf AMOUNT=QUANTITY*PRICE*(1-DISCOUNT). When user enter or change any or all members PRICE, QUANTITY and DISCOUNT in the input schedule and save data the AMOUNT have to be calculated.

The script:

*WHEN ACCOUNT
*IS PRICE
  *REC(EXPRESSION=[ACCOUNT].[QUANTITY]*%VALUE%*(1-[ACCOUNT].[DISCOUNT]), ACCOUNT= "AMOUNT")
*IS QUANTITY
  *REC(EXPRESSION=%VALUE%*[ACCOUNT].[PRICE]*(1-[ACCOUNT].[DISCOUNT]), ACCOUNT= "AMOUNT")
*IS DISCOUNT
  *REC(EXPRESSION=[ACCOUNT].[QUANTITY]*[ACCOUNT].[PRICE]*(1-%VALUE%), ACCOUNT= "AMOUNT")
*ENDWHEN

In UJKT we test this script with Data Region:

TIME=2013.09
CATEGORY=Actual
ENTITY=US
CURRENCY=LC
PRODUCT=Prod1

The values for ACCOUNTs in the report are:

PRICE: 100
DISCOUNT: 0.5
QUANTITY: 4

Expected result: 200=100*4*(1-0.5)

Result in UJKT:

LGX:
*WHEN ACCOUNT
*IS PRICE
*REC(EXPRESSION=[ACCOUNT].[QUANTITY]*%VALUE%*(1-[ACCOUNT].[DISCOUNT]), ACCOUNT= AMOUNT)
*IS QUANTITY
*REC(EXPRESSION=%VALUE%*[ACCOUNT].[PRICE]*(1-[ACCOUNT].[DISCOUNT]), ACCOUNT= AMOUNT)
*IS DISCOUNT
*REC(EXPRESSION=[ACCOUNT].[QUANTITY]*[ACCOUNT].[PRICE]*(1-%VALUE%), ACCOUNT= AMOUNT)
*ENDWHEN
-------------------------------------------------------------------------------------------------------------------------------------
LOG:
LOG ENTITYGIN TIME:2014-01-31 16:18:24
FILE:\ROOT\WEBFOLDERS\SOMEENV \ADMINAPP\SOMEMODEL\TEST.LGF
USER:V.KALININ
APPSET:SOMEENV
APPLICATION:SOMEMODEL
[INFO] GET_DIM_LIST(): I_APPL_ID="SOMEMODEL", #dimensions=7
ACCOUNT,ENTITY,MEASURES,TIME,CATEGORY,CURRENCY,PRODUCT
#dim_memberrset=4
TIME:2013.09,1 in total.
CATEGORY:Actual,1 in total.
PRODUCT:Prod1,1 in total.
ENTITY:US,1 in total.
CURRENCY:LC,1 in total.
REC :[ACCOUNT].[QUANTITY]*%VALUE%*(1-[ACCOUNT].[DISCOUNT])
CALCULATION ENTITYGIN:
QUERY PROCESSING DATA
QUERY TIME : 0.00 ms. 1  RECORDS QUERIED OUT.
QUERY REFERENCE DATA
QUERY TIME : 1.00 ms. 3  RECORDS QUERIED OUT.
CALCULATION TIME IN TOTAL :0.00 ms.
1  RECORDS ARE GENERATED.
CALCULATION END.
#dim_memberrset=4
TIME:2013.09,1 in total.
CATEGORY:Actual,1 in total.
PRODUCT:Prod1,1 in total.
ENTITY:US,1 in total.
CURRENCY:LC,1 in total.
REC :%VALUE%*[ACCOUNT].[PRICE]*(1-[ACCOUNT].[DISCOUNT])
CALCULATION ENTITYGIN:
QUERY PROCESSING DATA
QUERY TIME : 0.00 ms. 1  RECORDS QUERIED OUT.
QUERY REFERENCE DATA
QUERY TIME : 0.00 ms. 3  RECORDS QUERIED OUT.
CALCULATION TIME IN TOTAL :0.00 ms.
1  RECORDS ARE GENERATED.
CALCULATION END.
#dim_memberrset=4
TIME:2013.09,1 in total.
CATEGORY:Actual,1 in total.
PRODUCT:Prod1,1 in total.
ENTITY:US,1 in total.
CURRENCY:LC,1 in total.
REC :[ACCOUNT].[QUANTITY]*[ACCOUNT].[PRICE]*(1-%VALUE%)
CALCULATION ENTITYGIN:
QUERY PROCESSING DATA
QUERY TIME : 1.00 ms. 1  RECORDS QUERIED OUT.
QUERY REFERENCE DATA
QUERY TIME : 0.00 ms. 3  RECORDS QUERIED OUT.
CALCULATION TIME IN TOTAL :0.00 ms.
1  RECORDS ARE GENERATED.
CALCULATION END.
ENDWHEN ACCUMULATION: 1  RECORDS ARE GENERATED.
DATA TO WRITE BACK:
ACCOUNT    ENTITY    TIME    CATEGORY    PRODUCT    SIGNEDDATA
AMOUNT    US    2013.09    Actual    Prod1    600.00
1  RECORDS HAVE BEEN WRITTEN BACK.
WRITING TIME :6.00  ms.
SCRIPT RUNNING TIME IN TOTAL:8.00 s.
LOG END TIME:2014-01-31 16:18:32

And the report for:

ACCOUNT=AMOUNT
TIME=2013.09
CATEGORY=Actual
ENTITY=US
CURRENCY=LC
PRODUCT=Prod1

Shows the value for AMOUNT: 600 – 3 times more than expected.

What is the reason?


Example End

Best Regards,
Vadim

Updated on 2015.07.23, 2016.12.09

To report this post you need to login first.

15 Comments

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

        1. ALEXANDRE BOURCET

          Well actually I have tested and it works.. but your article was about BPC 10 NW and also note 1691570 mentions:

          “Till Planning and Consolidation NW 10.0 Support Package 6, Script Logic engine still uses Javascript engine to do the calculation.”

          So I was wondering maybe the ABAP calculation engine have been improved since then..

          (0) 
          1. Vadim Kalinin Post author

            “Well actually I have tested and it works” you mean that Math.round is validating? Then your current calculation engine is JavaScript! You can switch to ABAP using Inline ROUNDING in REC expression

            But you have to test all scripts, in some cases the behavior will be different…

            P.S. In some cases the complex scripts with a lot of formulas in single WHEN/ENDWHEN can’t be processed by ABAP engine due to some ABAP limitations…

            (0) 
            1. ALEXANDRE BOURCET

              Yes it is validating, I had imagined that maybe the ABAP have been improved since BPC 10 to support the Math.round() function…

              So the Javascript engine is still the default one in BPC 10.1. I will change to ABAP and test my logics.

              Thanks for your prompt answers.

              (0) 
              1. Vadim Kalinin Post author

                Math.round – is 100% JavaScript function with JavaScript syntax… No reason to translate it to ABAP 🙂 You can also test code with “toFixed” – will also validate with JavaScript engine.

                (0) 
  1. Shane Lloyd

    Hi Vadim,

    Do you have an e-mail address pls as I’d like to ask you a question regarding Script logics and need some of your help.

    Thx,

    Shane

    [email address removed by moderator, please ask questions in the SCN forum and provide the URL here]

    (0) 
  2. Ekaterina Bondarenko

    When preparing a post according to this guide one will understand where and how to look for a solution or even solve him/herself in 95% cases. 😆

    Was it the original idea?

    (0) 
  3. kumar m

    Hi Vidim,

     

    i have small requirement,

    i have 5 company’s(com-1, com-2, com-3, com-4, com-5.

    i wants to copy data com-1 to com-1 and monthly wise like source in last month destination in current month. i dont want to see company in selection

    i have to create 5 packages  like com-2 to com-2 weekly, like all packages.
    *XDIM_MEMBERSET TIME = %TIME_SET%
    *XDIM_MEMBERSET AUDIT = INPUT
    *XDIM_MEMBERSET CAT = VALUE
    *WHEN COM
    *IS COM_1
    *REC(EXPRESSION = %VALUE%,COM = COM_1)
    *ENDWHEN

     

    If i am wrong plz correct me the code.

     

    regards,

    kumar

     

     

     

     

     

     

     

    (0) 

Leave a Reply