# Script Logic on Agrregrate Values

Dear Experts,

We are having BPC 7.5 NW

We are having a requirement where, we need to write a  script logic which contained in different flows containing different material.

Example :

Opening value for inventory GL say  2001010 is 10000  with  NA as a material class and F_100 (opening flow )

Now user will plan for various materials classes for its consumption and minimum stock balance  under this same GL , example

F_130    F_410

CS-EM     500          20

CS-ED     500          20

with F_130  (deduction flow)

F_410   (minimum stock balance flow)

Now , I want to calculate closing for same GL with calculation as below :

First I will transfer the opening to a new flow with condition that only opening values which are above 0 should be transfer:

F_INV  >=  F_100

For this we have developed a script logic as below :

*XDIM_MEMBERSET CATEGORY=PLAN,ESTIMATED

*XDIM_MEMBERSET P_DATASRC=MANUAL

*XDIM_MEMBERSET P_ACCT = BAS(1010300000)

//*XDIM_MEMBERSET P_MATERIAL=BAS(All_MAT)

*XDIM_MEMBERSET P_EMP_TYPE=NA

*XDIM_MEMBERSET P_PROJECT=NA

*XDIM_MEMBERSET P_SERVICES=NA

//*XDIM_MEMBERSET P_CC=BAS(ABCD)

*XDIM_MEMBERSET P_ASSET=NA

*XDIM_MEMBERSET FLOW = F_100

//Inverse Flow calculation

*FOR %M1% = %TIME_SET%

*WHEN FLOW

*IS F_100

*REC(EXPRESSION = %VALUE% > 0 ? %VALUE%:0,FLOW = F_INV )

*ENDWHEN

*NEXT

*COMMIT

This transfer all the openings to F_INV flow with NA material class.

So in our case , since opening value is 10000, which is greater than  0 , F_INV will have 10000.

Now for closing the calculation is :

Closing = IF ( (Deduction + minimum stock balance - F_INV )  >   0 , Value , 0)

that means , logic should calculate as below

10000 - ((500+500)+(20+20)) = 8060

Now since this is above zero (0) , it should hit the  closing flow.

We have developed below script logic  :

*XDIM_MEMBERSET CATEGORY=PLAN,ESTIMATED

*XDIM_MEMBERSET P_DATASRC=MANUAL

*XDIM_MEMBERSET P_ACCT = BAS(1010300000)

*XDIM_MEMBERSET P_MATERIAL=BAS(All_MAT)

*XDIM_MEMBERSET P_EMP_TYPE=NA

*XDIM_MEMBERSET P_PROJECT=NA

*XDIM_MEMBERSET P_SERVICES=NA

*XDIM_MEMBERSET P_CC=BAS(ABCD)

*XDIM_MEMBERSET P_ASSET=NA

*XDIM_MEMBERSET TIME =%TIME_SET%

*WHEN P_MATERIAL

*IS BAS(ALL_MAT)

*WHEN FLOW

*IS F_130

*REC(EXPRESSION = %VALUE%+[FLOW].[F_410]-[FLOW].[F_INV] > 0 ? %VALUE%+[FLOW].[F_410]-[FLOW].[F_INV]:0,FLOW = F_120)

*IS F_410

*REC(EXPRESSION = %VALUE%+[FLOW].[F_130]-[FLOW].[F_INV] > 0 ? %VALUE%+[FLOW].[F_130]-[FLOW].[F_INV]:0,FLOW = F_120)

*IS F_INV

*REC(EXPRESSION = [FLOW].[F_130]+[FLOW].[F_410]-%VALUE% > 0 ? [FLOW].[F_130]+[FLOW].[F_410]-%VALUE%:0,FLOW = F_120)

*ENDWHEN

*ENDWHEN

But the logic is calculating the closing  considering the F_INV flow as zero for all the material classes since it is zero.

How can we achieve this. 