6 Replies Latest reply: Dec 14, 2007 3:29 AM by SAP BPC

# FOX : loop to calculate total of KF value

Currently Being Moderated

Hi,

SCENARIOS AS FOLLOWS:

Before execution:

BusArea  Empno WBS  ZPALOCPLN ZHRTOT 0AMOUNT

BA1     123   WB1   40       4000

BA1     123   WB2   60       6000

After execu:(what is required)

BusArea  Empno WBS  ZPALOCPLN ZHRTOT 0AMOUNT

BA1     123   WB1   40       4000    10000

BA1     123   WB2   60       6000    10000

I have a requirement wherein I need to loop through and find the Total KF value and store it in another KF - 0AMOUNT. Im using FOREACH statement for this.

When the user changes the percentage of allocation (ZPALOCPLN), it should get multiplied by 0AMOUNT and posted to the same line.

Rgds

Shyam

• ###### Re: FOX : loop to calculate total of KF value
Currently Being Moderated

Hi Shyam

Here ur requirement is summation of ZHRTOT as in ur example..

Fo this u can use a formula in the report Sum(ZHRTOT).

Buti dint understand ur second step.

<b>When the user changes the percentage of allocation (ZPALOCPLN), it should get multiplied by 0AMOUNT and posted to the same line.</b>

Could u please give some more inputs..

Khaja

• ###### Re: FOX : loop to calculate total of KF value
Currently Being Moderated

Its like:

The first time the user opens the layout, he gets the distributed amount as 4000 and 6000 to wbs1 and wbs2 resp. The total ( 6000 + 4000 = 10000) is always fixed for that employee.

Now the user wants to change the percentage allocation to each WBS (ZPALOCPLN) say from 40,60  to 30,70  then the ZHRTOT should be changed accordingly by multiplying ZPALOCPLN with 0AMOUNT.

Before:

BusArea Empno WBS ZPALOCPLN ZHRTOT 0AMOUNT

BA1 123 WB1 40 4000 10000

BA1 123 WB2 60 6000 10000

After:

BusArea Empno WBS ZPALOCPLN ZHRTOT 0AMOUNT

BA1 123 WB1 30 3000 10000

BA1 123 WB2 70 7000 10000

Pls lemme know if u need more inputs.

Rgds

• ###### Re: FOX : loop to calculate total of KF value
Currently Being Moderated

Hi,

So the amount is fixed for 10000 and the user will change the ZPALOCPLN values.. How he is changing the values? is this value not in the cube?

Khaja

• ###### Re: FOX : loop to calculate total of KF value
Currently Being Moderated

Hi,

Do you have problem with FOREACH? In case of FOREACH, please note that it loops only for only those values of a characteristic, which are present in the data packet being processed... you need to be sure that all characteristic values which you want to loop on using FOREACH are part of the data being processed and not reference data. For eg, if you want to loop on WB1 and WB2, these should be included in filter (data outside filter can be read in function, but not changed; also FOREACH doesnt loop on values outside filter selection).

Does this help you? I am not sure what problem you are having. Please elaborate a little more in case something else is the issue.

• ###### Re: FOX : loop to calculate total of KF value
Currently Being Moderated

Hi,

Summary of req:

Before execution:

BusArea Empno WBS ZPALOCPLN ZHRTOT

BA1 123 WB1 40 4000

BA1 123 WB2 60 6000

BA1 456 WB1 30 6000

BA2 456 WB3 70 14000

User changes values of ZPALOCPLN as follows::

BusArea Empno WBS ZPALOCPLN ZHRTOT

BA1 123 WB1 20 4000

BA1 123 WB2 80 6000

BA1 456 WB1 50 6000

BA2 456 WB3 50 14000

Now, once user clicks on 'Calculate' planning func (FOX), the foll is expected: ie The field ZHRTOT should change accordingly.

PS :ZHRTOT = ZPALOCPLN * ( Sum of ZHRTOT for that employee across WBS ).

BusArea Empno WBS ZPALOCPLN ZHRTOT

BA1 123 WB1 20 2000

BA1 123 WB2 80 8000

BA1 456 WB1 50 10000

BA2 456 WB3 50 10000

Sample code:

DATA THR TYPE F.

DATA HR TYPE F.

DATA  EMPNO TYPE ZEMPNO.

DATA  WBS TYPE 0WBS_ELEMT.

THR = 0.0.

HR = 0.0.

FOREACH EMPNO.

FOREACH  WBS.

HR = {ZHRTOT,WBS, EMPNO }.

THR =   THR + HR.

ENDFOR.

FOREACH  WBS .

{ZHRTOT,WBS, EMPNO } = { ZPALOCPLN,WBS, EMPNO } * (THR *    0.01).

ENDFOR.

ENDFOR.

Any standard docs on how to use FOX ?

Thanks

Shyam

• ###### Re: FOX : loop to calculate total of KF value
Currently Being Moderated

Solved... problem was not with the logic..

Its because, once there is a code change in FOX, it wasn't reflected until n unless I close the analyzer n open again..

Message was edited by:

Syam K