Hello all,
I have a code in Script Logic that must calculate product costs with an Inflation percentage.
The Inflation percentage is in a Premisse model and the product costs and profits are in Revenues. The script is inside Premisse model because when the inflation percent is updated, the products in Revenues must be updated too.
So, I used the script below combining the *LOOKUP and *DESTINATION_APP sentences to read and write data. So, I needed to use nested loops to write data in the correct products in destination using two *FOR in the *LOOKUP sentence to navigate through Products and Currencies.
The loops inside the Revenues lookup are not working properly, when data is recorded, only ProductA values are Writen for all products in destination. In my tests the variables for ProductB and ProductC are being filled with ProductA value.
Could someone help please? Is something wrong or a limitation in my code?
Thanks!!!
*XDIM_MEMBERSET CATEGORY = Plan
*XDIM_MEMBERSET ACCOUNT = PERC_INFLATION
//Retrieve all months of the current scope year
*SELECT(%YEAR%,YEAR,TIME,[ID] = %TIME_SET%)
*SELECT(%TIME_ID%,ID,TIME,YEAR = %YEAR% AND CALC = N)
*XDIM_MEMBERSET TIME = BAS(%TIME_ID%)
//Var for the loops
*SELECT(%CURRENCY%,[ID],INPUTCURRENCY,ID = USD,BRL)
*SELECT(%PRODUCT%,[ID],PRODUCT,CALC = N)
//Lookup in SALE_REVENUES to retrieve Revenues and Costs
*LOOKUP SALE_REVENUES
*DIM TIME = TIME.ID
*DIM CATEGORY = CATEGORY.ID
*DIM ENTITY = ENTITY.ID
*FOR %CUR2% = %CURRENCY%
*DIM INPUTCURRENCY = %CUR2%
*FOR %PRD% = %PRODUCT%
*DIM PRODUCT = %PRD%
*DIM V_UNIT_COST_%PRD%_%CUR2%: ACCOUNT = UNIT_COST
*DIM V_UNIT_PRICE_%PRD%_%CUR2%: ACCOUNT = UNIT_PRICE
*DIM V_QUANTITY_%PRD%_%CUR2%: ACCOUNT = QUANTITY
*NEXT
*NEXT
*ENDLOOKUP
//Lookup to retrieve Inflation percentage
*LOOKUP PREMISSE
*DIM INFLATION:ACCOUNT = PERC_INFLATION
*DIM CATEGORY = CATEGORY.ID
*DIM ENTITY = ENTITY.ID
*DIM TIME = TIME.ID
*DIM MEASURES = YTD
*ENDLOOKUP
//Record calcs
*FOR %LOOP_CUR% = %CURRENCY%
*FOR %LOOP_PRD% = %PRODUCT%
*DESTINATION_APP = SALE_REVENUES
*ADD_DIM INPUTCURRENCY = %LOOP_CUR%
*ADD_DIM PRODUCT = %LOOP_PRD%
*WHEN_REF_DATA = MASTER_DATA
*WHEN ACCOUNT
*IS PERC_INFLATION
*REC(EXPRESSION = LOOKUP(V_UNIT_PRICE_%LOOP_PRD%_%LOOP_CUR%)* LOOKUP(V_QUANTITY_%LOOP_PRD%_%LOOP_CUR%)*(1 + LOOKUP(INFLATION)) ,ACCOUNT = REVENUE)
*ENDWHEN
*NEXT
*NEXT
*COMMIT