cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

LOOP in BPC script to check for previous month data

0 Likes
1,145

Hi,

Can someone provide some insight on using For Loop (in script logic) to check data for the current month...If the current month is zero, to copy data from previous month.

Month selection will be triggered from user selection from DM package.

Many thanks!

Accepted Solutions (1)

Accepted Solutions (1)

former_member186338
Active Contributor
0 Likes

Also you can try the following:

//%TIME_SET%=2019.04(current period -single period selection)
*XDIM_MEMBERSET TIME=TMVL(-1,%TIME_SET%) //scope previous month 2019.03
*WHEN TIME.MONTHNUM
*IS <> 12 //Not if current period - JAN
*REC(EXPRESSION=([TIME].[%TIME_SET%]>0 || [TIME].[%TIME_SET%]<0) ? [TIME].[%TIME_SET%] : %VALUE%,TIME=%TIME_SET%)
*ENDWHEN

"||" - OR operator: https://launchpad.support.sap.com/#/notes/0002228643

0 Likes
There is no error in the simulation. I will validate the data.

Thanks Vadim!

former_member186338
Active Contributor
0 Likes

joan.sy

OK, looks like that with ABAP calculation engine both "==" and "<>" operators are not supported!

But logical operators "||" - OR and "&&" - AND are supported!

[TIME].[%TIME_SET%]>0 || [TIME].[%TIME_SET%]<0

is logical equivalent of unsupported:

[TIME].[%TIME_SET%]<>0
former_member186338
Active Contributor
0 Likes
joan.sy

P.S. And please accept the correct answer.

Answers (7)

Answers (7)

0 Likes

Hi Vadim,

Apology for that. Please find below the info

1. BPC NW version: 10.1 BW 7.5, SP level 5
2. JAVA script since the error is on ABAP calc engine
3. List of dimensions to be used (refer to point 6 below)
4. Intended to incorporate as part of the consolidation run (before the consolidation script). Hence, it is triggered by the DM package (using EPM consolidation run)
5. Calculation logic:
a) User will input the Group Currency value for a specific flow. Eg: User will enter value $100 in Period 3. If current period is period 4, the custom script will copy data from period 3 to period 4 (as the user will not want to enter the same value in period 4). The system will perform the check that if current period (i.e period 4) is blank, it will copy the data from previous period.
b) Back-track to period 1 and 2, if I am at period 1, it will be blank (always). If I am period 2, if period 1 is blank, it will copy blank to period 2. However, if user had written some value into period 2 and run again the package, period 2 data will not be overwritten as there is data in period 2 (I,e overwriten will only take place if current period is blank).

6. Script:

*XDIM_MEMBERSET TIME = 2020.04
*XDIM_MEMBERSET TIME=TMVL(-1,2020.04)
*XDIM_MEMBERSET AUDITTRAIL = INPUT
*XDIM_MEMBERSET CATEGORY = ACTUAL
*XDIM_MEMBERSET ENTITY = KN45
*XDIM_MEMBERSET GROUPS = G_NONE
*XDIM_MEMBERSET MOVEMENT = F500
*XDIM_MEMBERSET RPTCURRENCY = USD
*XDIM_MEMBERSET ACCOUNT = 244000


*WHEN TIME.MONTHNUM
*IS <> 12
*REC(EXPRESSION=([TIME].[2020.04]==0) ? %VALUE% : [TIME].[2020.04],TIME=2020.04)
*ENDWHEN----
Error message:

REC :([TIME].[2020.04]==0) ? %VALUE% : [TIME].[2020.04]

7. Issue:
a) Error 1:

REC :([TIME].[2020.04]==0) ? %VALUE% : [TIME].[2020.04]
------------ ABAP Code Generation Error:4 -------------
MESSAGEG27Relational operator "==" is not supported.

----> How to convert to java script?

b) Error 2 (

REC :([TIME].[2020.04]=0) ? %VALUE% : [TIME].[2020.04]
------------ ABAP Code Generation Error:4 -------------
MESSAGEG27Relational operator ")" is not supported.

-----> not sure if it is link to Error 1

Thanks!

former_member186338
Active Contributor
0 Likes

I have no system with ABAP calc engine to test. But try my answers:

With "<>"

With ">" "||" "<"

former_member186338
Active Contributor
0 Likes

P.S.

"JAVA script since the error is on ABAP calc engine" - incorrect, according to your log you have ABAP calc engine

former_member186338
Active Contributor
0 Likes

With JavaScript calculation engine my code will work correctly.

For ABAP try this:

//%TIME_SET%=2019.04 (current period - single period selection)
*XDIM_MEMBERSET TIME=TMVL(-1,%TIME_SET%) //scope previous month 2019.03
*WHEN TIME.MONTHNUM
*IS <> 12 //Not if current period - JAN
*REC(EXPRESSION=([TIME].[%TIME_SET%]<>0) ? [TIME].[%TIME_SET%] : %VALUE%,TIME=%TIME_SET%)
*ENDWHEN

Instead of "==" try "<>"

0 Likes

Couldn't work:

REC :([TIME].[2020.04]<>0) ? [TIME].[2020.04] : %VALUE% 1
([TIME].[2020.04]<>0) ? [TIME].[2020.04] : %VALUE%
var $2$=4.1972426137439489E-01;var $1$=6.6735165584877876E-01;($1{replace1}lt;>0) ? $1$ : 0;

UJK_VALIDATION_EXCEPTION:LINE 15 syntax error: " syntax error"

0 Likes

Hi Vadim,

Info: SAP BW 7.5, SP level 5

Prior to this, I was having another error:

SCRIPT in UJKT:

*XDIM_MEMBERSET TIME = 2020.04
*XDIM_MEMBERSET TIME=TMVL(-1,2020.04)
*XDIM_MEMBERSET AUDITTRAIL = INPUT
*XDIM_MEMBERSET CATEGORY = ACTUAL
*XDIM_MEMBERSET ENTITY = KN45
*XDIM_MEMBERSET GROUPS = G_NONE
*XDIM_MEMBERSET MOVEMENT = F500
*XDIM_MEMBERSET RPTCURRENCY = USD
*XDIM_MEMBERSET ACCOUNT = 244000


*WHEN TIME.MONTHNUM
*IS <> 12
*REC(EXPRESSION=([TIME].[2020.04]==0) ? %VALUE% : [TIME].[2020.04],TIME=2020.04)
*ENDWHEN----
Error message:

REC :([TIME].[2020.04]==0) ? %VALUE% : [TIME].[2020.04]
------------ ABAP Code Generation Error:4 -------------
MESSAGEG27Relational operator "==" is not supported.
Line13 Word==
-------- Code ---------
program.
class main definition.
public section.
methods METH1 importing
P1 type decfloat34
P2 type decfloat34
exporting RET type decfloat34
raising CX_SY_ZERODIVIDE.
endclass.
class main implementation.
method METH1.
"([TIME].[2020.04]==0) ? %VALUE% : [TIME].[2020.04]
if ( P1 == 0 ) .
RET = P2.
else.
RET = P1.
endif.
endmethod.
endclass.
-------- Input formulas ---------
([TIME].[2020.04]==0) ? %VALUE% : [TIME].[2020.04]
------------ ABAP Code Generation Error Ends ------------

former_member186338
Active Contributor
0 Likes

Sorry, but this is the reason why I am asking to read https://blogs.sap.com/2014/01/31/how-to-ask-questions-about-script-logic-issues/

And to provide required info! You use ABAP calculation engine!

0 Likes

Full UJKT result:

----------- ABAP Code Generation Error:4 -------------
MESSAGEG27Relational operator ")" is not supported.
Line13 Word)
-------- Code ---------
program.
class main definition.
public section.
methods METH1 importing
P1 type decfloat34
P2 type decfloat34
exporting RET type decfloat34
raising CX_SY_ZERODIVIDE.
endclass.
class main implementation.
method METH1.
"([TIME].[2020.04]=0) ? %VALUE% : [TIME].[2020.04]
if 0 ) .
RET = P2.
else.
RET = P1.
endif.
endmethod.
endclass.

0 Likes

Hi Vadim,

I have gotten this error in validation. What should I amend? Thanks

REC :([TIME].[2020.04]=0) ? %VALUE% : [TIME].[2020.04]
------------ ABAP Code Generation Error:4 -------------
MESSAGEG27Relational operator ")" is not supported.

former_member186338
Active Contributor
0 Likes

The script will be:

//%TIME_SET%=2019.04 (current period - single period selection)
*XDIM_MEMBERSET TIME=TMVL(-1,%TIME_SET%) //scope previous month 2019.03
*WHEN TIME.MONTHNUM
*IS <> 12 //Not if current period - JAN
*REC(EXPRESSION=([TIME].[%TIME_SET%]==0) ? %VALUE% : [TIME].[%TIME_SET%],TIME=%TIME_SET%)
*ENDWHEN
0 Likes

Hi Vadim,

Thank you for the reply. The scenario will be like this:

1. User will input the Group Currency value for a specific flow. Eg: User will enter value $100 in Period 3. If current period is period 4, the custom script will copy data from period 3 to period 4 (as the user will not want to enter the same value in period 4). The system will perform the check that if current period (i.e period 4) is blank, it will copy the data from previous period

2. Back-track to period 1 and 2, if I am at period 1, it will be blank (always). If I am period 2, if period 1 is blank, it will copy blank to period 2. However, if user had written some value into period 2 and run again the package, period 2 data will not be overwritten as there is data in period 2 (I,e overwriten will only take place if current period is blank).

Hope the above is clear.

Thanks for your time.

former_member186338
Active Contributor
0 Likes

Sorry, but looks like you didn't read my blog. Full info is still not provided...