cancel
Showing results for 
Search instead for 
Did you mean: 

Can we use IF condition for calling a logic script?

sameer_lonkar
Explorer
0 Kudos

We have a requirement, where we have to call business rules through logic script based on some condition. For example, if ACCOUNT VALUE > 0 then *INCLUDE ABC.LGF, else PQR.LGF.

Can we achieve this? Happy to elaborate further if required.

sameer_lonkar
Explorer
0 Kudos

Thanks for reply Vadim and Pratyush. We have tried to put a logic in logic script for below requirement. Can anybody check if it is correct w.r.t. syntax?

Requirement is -

If TECH_INT_TOTAL on C_ACCOUNT_ORIG - DEFAULT > 0 then

1) INT_04 = TECH_INT_04 + TECH_INT_16

2) INT_05 = TECH_INT_05 + TECH_INT_17

3) INT_06 = TECH_INT_06 + TECH_INT_18

4) INT_07 = TECH_INT_07 + TECH_INT_19

5) INT_16 = 0

6) INT_17 = 0

7) INT_18 = 0

😎 INT_19 = 0

If TECH_INT_TOTAL on C_ACCOUNT_ORIG - DEFAULT <= 0 then

1) INT_04 = 0

2) INT_05 = 0

3) INT_06 = 0

4) INT_07 = 0

5) INT_16 = TECH_INT_04 + TECH_INT_16

6) INT_17 = TECH_INT_05 + TECH_INT_17

7) INT_18 = TECH_INT_06 + TECH_INT_18

😎 INT_19 = TECH_INT_07 + TECH_INT_19

Logic script:

*WHEN C_ACCOUNT *IS TECH_INT_TOTAL

*REC(C_ACCOUNT=INT_04,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])>0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_04]+[C_ACCOUNT].[TECH_INT_16]):0)

*REC(C_ACCOUNT=INT_16,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])==0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_04]+[C_ACCOUNT].[TECH_INT_16]):EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])<0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_04]+[C_ACCOUNT].[TECH_INT_16]):0)

*REC(C_ACCOUNT=INT_05,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])>0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_05]+[C_ACCOUNT].[TECH_INT_17]):0)

*REC(C_ACCOUNT=INT_17,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])==0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_05]+[C_ACCOUNT].[TECH_INT_17]):EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])<0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_05]+[C_ACCOUNT].[TECH_INT_17]):0)

*REC(C_ACCOUNT=INT_06,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])>0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_06]+[C_ACCOUNT].[TECH_INT_18]):0)

*REC(C_ACCOUNT=INT_18,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])==0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_06]+[C_ACCOUNT].[TECH_INT_18]):EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])<0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_06]+[C_ACCOUNT].[TECH_INT_18]):0)

*REC(C_ACCOUNT=INT_07,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])>0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_07]+[C_ACCOUNT].[TECH_INT_19]):0)

*REC(C_ACCOUNT=INT_19,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])==0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_07]+[C_ACCOUNT].[TECH_INT_19]):EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])<0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_07]+[C_ACCOUNT].[TECH_INT_19]):0)

former_member186338
Active Contributor
0 Kudos

P.S. Please comment on the answer, not on the question!

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member186338
Active Contributor
0 Kudos

Sorry, but looks like you are not reading my answer!

"*REC(C_ACCOUNT=INT_04,EXPRESSION=(([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])>0)?EXPRESSION=([C_ACCOUNT].[TECH_INT_04]+[C_ACCOUNT].[TECH_INT_16]):0)" - incorrect syntax!

Syntax from my post:

*REC(EXPRESSION=%VALUE%>0 ? %VALUE% : 0, ACCOUNT=A2)

Your REC has to be:

*REC(EXPRESSION=([C_ACCOUNT].[TECH_INT_TOTAL],[C_ACCOUNT_ORIG].[DEFAULT])>0 ? [C_ACCOUNT].[TECH_INT_04]+[C_ACCOUNT].[TECH_INT_16] : 0, C_ACCOUNT=INT_04)

For the rest you have to explain the scoping logic...

sameer_lonkar
Explorer
0 Kudos

Thanks Vadim for reply.

We tried the suggested code, but even if TECH_INT_TOTAL is > 0, system is not considering [C_ACCOUNT].[TECH_INT_04]+[C_ACCOUNT].[TECH_INT_16], rather putting value as 0 for INT_04. That means, it is always considering the code after ":" i.e. "0". Is it?

Also, since we are already putting C_ACCOUNT=INT_04 in our expression, what should we put in

*When C_ACCOUNT

*IS ?????

Thanks.

former_member186338
Active Contributor
0 Kudos

Sorry, but you are not providing full info about your case - I am unable to help you!

Please read: https://blogs.sap.com/2014/01/31/how-to-ask-questions-about-script-logic-issues/

And provide required info and sample test case!

"system is not considering ..." scope may be incorrect!

"what should we put in

*When C_ACCOUNT

*IS ?????" - explain the data you have!

former_member5472
Active Contributor
0 Kudos

Hi Sameer,

I'm not sure which SP you are in but you can explore the keyword

*XDIM_SKIPNULLCHECK-

As Vadim suggested, script is not designed to put conditional statement on transaction data and the conditional statement is very native. You have to play around with 'When" condition or skipnull to achieve your desired results.

Expand further on the requirement and there can be a way around.

https://www.column5.com/blog/how-to-create-conditional-logic-in-sap-business-objects-planning-consol...

former_member186338
Active Contributor
0 Kudos

Sorry, but *XDIM_SKIPNULLCHECK has ABSOLUTELY no relation to conditions on transaction data values. It's related to master data checks and in most cases can be replaced by SELECT/FOR/NEXT.

"You have to play around with 'When" condition or skipnull to achieve your desired results." - incorrect!

former_member186338
Active Contributor
0 Kudos

No, we can't!

Script logic is not a real language and there is no IF THEN in it.

Even more you can't change the script execution based on transactional data value.

The only supported thing is ternary operator in WHEN/ENDWHEN loop:

*WHEN ACCOUNT

*IS A1

*REC(EXPRESSION=%VALUE%>0 ? %VALUE% : 0, ACCOUNT=A2)

*ENDWHEN

If you are able to use WHEN/REC/ENDWHEN instead of your rules you can do something!