Former Member
Oct 15, 2013 at 01:10 PM

Default Script Logic Issue with looping WHEN

42 Views

Hello dear friends,

I hope you are all doing fine. I have come across an issue with BPC Logic Scripts for the version 10 NW when trying to run a certain code in the default.lgf file.

Imagine the following scenario:

You have the following accounts: Acc1, Acc2 and Acc3.

You need to maintain a certain formula in Script Logic that does the following calculation:

Acc3 = Acc1 + Acc2

So the script logic would be something like that:

*WHEN ACCOUNT

*IS Acc1, Acc2

*REC(EXPRESSION = %VALUE%, ACCOUNT = Acc3)

*ENDWHEN

(Looping through accounts 1 and 2 and summing them as Account3)

When I put this in the default.lgf file I get the following behavior:

• If I put Acc1 = 100 and Acc2 = 100 and I save, I get Acc3 = 200 which is correct.
• If I then change Acc1 = 150 and leave Acc2 as is, because the execution scope is only limited to the changed rows, I am getting Acc3 = 150. It's not reading a value for Acc2, therefore not doing the sum properly. This is a problem.

I try to solve the issue by doing the following:

*WHEN ACCOUNT

*IS Acc1, Acc2

*REC(EXPRESSION = [Acc1] + [Acc2], ACCOUNT = Acc3)

*ENDWHEN

I get the following behavior:

• If I put Acc1 = 100 and Acc2 = 100 and I save, I get Acc3 = 400 which is incorrect. The reason is because the loop is doing twice 100+100.
• If I put Acc1 = 150 and I keep Acc2 = 100 and I save, I get Acc3 = 250 which is correct.

After further refining I was able to solve the situation with this code:

*WHEN ACCOUNT

*IS Acc1

*REC(EXPRESSION = [Acc1] + [Acc2], ACCOUNT = Acc3)

*IS Acc2

*REC(EXPRESSION = [Acc1] + [Acc2], ACCOUNT = Acc3)

*ENDWHEN

I get the correct results in both cases, but the code is nasty! I mean it is not clean and the calculation itself is being done twice in case I have put values to the Acc1 and Acc2.

Can you suggest a better solution to my problem?

If this code was running outside the default, then I would have had no problem because the accounts would have been summed using the first scenario. Now because I have to adapt to data modification possibilities then my code is getting nasty. And this is just an example I gave you. I have formulas with more than 6 operands 😊 Imagine the code and the slowness...

I really appreciate it if someone can help 😊