cancel
Showing results for 
Search instead for 
Did you mean: 

Script Logic calling a badi with conditions

sap_user62
Active Participant
0 Kudos

Hello Friends,

Env 10.1

We have a requirement to call a badi from script logic, but depending on the parameters we pass to the DM package the Time memberset get updated.

%TIME_PERIOD_ACTUAL% and %TIME_PERIOD_PLAN% get updated from the flags in the time dimension. Script calls a select statement to populate these variables.

This is one part of the script, we have multiple categories and with additional conditions

eg,

*when category

*is actual

*XDIM_MEMBERSET TIME = %TIME_PERIOD_ACTUAL%

*START_BADI XXXX

QUERY = ON

WRITE = ON

DESTINATION = %RPTCURRENCY_SET%

*END_BADI

*IS PLAN

*XDIM_MEMBERSET TIME = %TIME_PERIOD_PLAN%

*START_BADI XXXX

QUERY = ON

WRITE = ON

DESTINATION = %RPTCURRENCY_SET%

*END_BADI

*ENDWHEN

Question - This script does not validate, I am not sure if we can call a Badi from a *when *endwhen. The name of the badi is same for both the conditions, but I don't want to write outside of *endwhen, as the scoping of time dimension would go off.

If there is any other conditional operator which I can use, that would be great. I dont need any *rec statements in my current script

Thanks for your time

Ed.

Accepted Solutions (1)

Accepted Solutions (1)

former_member186338
Active Contributor
0 Kudos

A property to be created in CATEGORY dimension: IDPROP and filled with the member ID. Then:

*SELECT(%PL%,[ID],CATEGORY,ID=%CATEGORY_SET% AND IDPROP=PLAN)

Same for actual with variable %AC%:

*SELECT(%AC%,[ID],CATEGORY,ID=%CATEGORY_SET% AND IDPROP=ACTUAL)

Then you will scope:

*FOR %A%=%AC% // if actual was selected by user

*XDIM_MEMBERSET TIME = %TIME_PERIOD_ACTUAL%

*START_BADI...

*NEXT

*FOR %P%=%PL% // if plan was selected by user

*XDIM_MEMBERSET TIME = %TIME_PERIOD_PLAN%

*START_BADI...

*NEXT

P.S. Code corrected, property creation is required!

Full script:

*SELECT(%TIME_PERIOD_ACTUAL%,"[ID]",TIME,"ACTUAL_PERIOD = 'Y'")
*SELECT(%TIME_PERIOD_PLAN%,"[ID]",TIME,"PLAN_PERIOD = 'Y'")
*SELECT(%PL%,[ID],CATEGORY,ID=%CATEGORY_SET% AND IDPROP=PLAN)
*SELECT(%AC%,[ID],CATEGORY,ID=%CATEGORY_SET% AND IDPROP=ACTUAL)

*FOR %A%=%AC% // if actual was selected by user

*XDIM_MEMBERSET CATEGORY = ACTUAL
*XDIM_MEMBERSET TIME = %TIME_PERIOD_ACTUAL%
*START_BADI XXXXXXXX
QUERY = ON
WRITE = ON
DESTINATION = %RPTCURRENCY_SET%
*END_BADI

*NEXT

*FOR %P%=%PL% // if plan was selected by user

*XDIM_MEMBERSET CATEGORY = PLAN
*XDIM_MEMBERSET TIME = %TIME_PERIOD_PLAN%
*START_BADI XXXXXXXX
QUERY = ON
WRITE = ON
DESTINATION = %RPTCURRENCY_SET%
*END_BADI

*NEXT

Answers (6)

Answers (6)

former_member200327
Active Contributor
0 Kudos

Hi Vadim,

Yes, such approach is possible, but I'd consider it a workaround. SKIPNULLCHECK is designed specifically for that purpose and should improve readability of the script if not performance.

Gersh

former_member186338
Active Contributor

In general FOR with empty variable and SKIPNULLCHECK with XDIM_MEMBERSET xxx = empty variable will do exactly same things - skip code. No performance benefits (both will happen during LGX generation). With SKIPNULLCHECK the COMMIT is required resulting in scope reset. And FOR with empty variable method was available before the note 2146749.

former_member200327
Active Contributor
0 Kudos

Hi Ed,

You can write conditional statements in BPC Script logic by using keyword *XDIM_SKIPPNULLCHECK - OSS Note 2146749.

Regards,

Gersh

former_member186338
Active Contributor
0 Kudos

Hi Gersh,

In my answer I am talking about the same approach but using for with variable that can have some value or nothing. In case of nothing the code inside for next is not executed.

sap_user62
Active Participant
0 Kudos

Thanks Vadim for your reply

//ACTUAL SCRIPT

*SELECT(%TIME_PERIOD_ACTUAL%,"[ID]",TIME,"ACTUAL_PERIOD = 'Y'")

*XDIM_MEMBERSET CATEGORY = ACTUAL //%CATEGORY_SET%

*XDIM_MEMBERSET TIME = %TIME_PERIOD_ACTUAL%

*START_BADI XXXXXXXX

QUERY = ON

WRITE = ON

DESTINATION = %RPTCURRENCY_SET%

*END_BADI

//PLAN SCRIPT

*SELECT(%TIME_PERIOD_PLAN%,"[ID]",TIME,"PLAN_PERIOD = 'Y'")

*XDIM_MEMBERSET CATEGORY = PLAN //%CATEGORY_SET%

*XDIM_MEMBERSET TIME = %TIME_PERIOD_PLAN%

*START_BADI XXXXXXXX

QUERY = ON

WRITE = ON

DESTINATION = %RPTCURRENCY_SET%

*END_BADI

former_member186338
Active Contributor
0 Kudos

Can you post the 2 different scripts for 2 different categories then I will explain you how to combine. I general you need to generate scope for time dimension depending on category.

sap_user62
Active Participant
0 Kudos

Thanks Vadim for your reply.

My requirement is to pass different time period to the BADI, depending on the category selected in the DM package.

example, if category ACTUAL is passed though the DM package then the script should scope time for the actual period.

if the category PLAN is passed though the DM package then the script should scope time for the plan periods, which would be multiple periods based on the flag.

I could write separate script for each category and hard code that scope for the time dimension(based on the flags in the time dimensions), but it would lead to separate DM packages and separate scripts for each category, which make maintenance difficult.

I understand from your post, that we cannot use *when *endwhen while calling a badi.

what is the best alternative, I am looking for a functionality like using a IF condition to determine the scoping. Not sure if its possible in script logic.

I cannot provide logs as the earlier script does not validate.

Thanks for your time.

Ed.

former_member186338
Active Contributor
0 Kudos

Badi call can't be inside WHEN/ENDWHEN loop, only REC.

Please describe your requirements in line with:

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