cancel
Showing results for 
Search instead for 
Did you mean: 

FOX - Inside FOREACH Loop

Former Member
0 Kudos
184

Guys,

I am trying to fix a FOX code. Below is the issue -

There are 2 key figures - YearToDate(YTD) and LifeToDate(LTD).

The formula is

{Current FISCYRPRD, LTD} = {Last FISCYRPRD of Previous Year , LTD} + {Current FISCYRPRD, YTD}

- The Fiscal Year / Period is open and this function has to run for all the Fiscal Year / Period.

________________________________________________________

ISSUE:-

EXPECTED -

FISCYRPRD / YTD / LTD

2009012 / 100 / 100

2010001 / 0 / 100

2010002 / 10 / 110

ACTUAL OUTPUT -

FISCYRPRD / YTD / LTD

2009012 / 100 / 100

2010001 / 0 / 0

2010002 / 10 / 110

________________________________________________________

The code is simple -

FOREACH FISCYRPRD.

{Current FISCYRPRD, LTD} = {Last FISCYRPRD of Previous Year , LTD} + {Current FISCYRPRD, YTD}

ENDFOR.

When there is 0 for YTD the value does not get posted for LTD. This is because of the FOREACH loop. But I cannot force a condition in a DO loop because this function is to run for all FISCYRPRD.

Any help in this would be highly appreciated!

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

How you are populating last fiscal year period of previous year,Is it hard code in parameters .Code you are using may not be reading a block of last year values...If you can share sample code we may be able to help.

As at times foreach also looks for fiscal year along with period for complete loop over.

Answers (2)

Answers (2)

Former Member
0 Kudos

There is a ABAP code that derives the previous year FSCYRPRD

FOREACH FISCYRPRD.

ABAP code calculating "Last FISCYRPRD of Previous Year " from FISCYRPRD.

{Current FISCYRPRD, LTD} = {Last FISCYRPRD of Previous Year , LTD} + {Current FISCYRPRD, YTD}

ENDFOR.

This is the algorithm of the total FOX code, there is no other derivation. And this has to run for all periods (open). There is no Year in the Package. I cannot change the way Planning Package is derived because there are atleast 20 functions running on this live system.

former_member5472
Active Contributor
0 Kudos

Hi,


When there is 0 for YTD the value does not get posted for LTD. This is because of the FOREACH loop. But I cannot force a condition in a DO loop because this function is to run for all FISCYRPRD.

As Indu said, the error may be because the way you are reading last fiscal Year period value; It mayn't be because of 0 value of YTD..

If you want to perform a Do loop , you can do that.

Create a variable on fiscal year period and use tmvl function to get max loop values.

then you can use your do.. enddo loop for looping.

Thanks

Pratyush