cancel
Showing results for 
Search instead for 
Did you mean: 

Several For each using

Former Member
0 Kudos

Hi,

I have a multi area where i need to affect data from a line to several other line.

Line A Contract C value 10% from Area 1

Line B1 Contract C from area 2 value --> should be 10%

Line B2 Contract C from area 2 value --> should be 10%

Line B3 Contract C from area 2 value --> should be 10%

i have two for each but it doesn't work.

hiw can i manage it ?

Thank you

Cyril

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ignacio,

Thanks for help it's now better but not yet OK.

I change my code to :

VAR_TARGET = 'ZSPA2002'.

VAR_SOURCE = 'ZSPA2001'.

FOREACH VAR_CONT, VAR_TYE_LIG IN REFDATA.

IF VAR_TYE_LIG = '#'.

VAR_RDT = {ZZRDTOBJ,VAR_CONT,VAR_TYE_LIG,VAR_SOURCE}.

VAR_EXCL = {ZINCL_CT,VAR_CONT,VAR_TYE_LIG,VAR_SOURCE}.

VAR_CONT2 = VAR_CONT.

ENDIF.

FOREACH VAR_CONT2, VAR_TYE_LIG2.

IF VAR_TYE_LIG2 <> '' AND VAR_CONT2 = VAR_CONT.

MESSAGE I003(/SEM/003) WITH VAR_CONT VAR_RDT VAR_EXCL.

{ZZRDTOBJ,VAR_CONT,'CT',VAR_TARGET} = VAR_RDT.

ENDIF.

ENDFOR.

ENDFOR.

The problem is th IF in bold. i would like to do the second for each only for line with VAR_TYE_LIG initial.

In one case : if i put the IF like in the code the first FOREACH is executed twice for a VAR_CONT (first line of the area 1 and line of the area2 so the last line is area two so values of VAR_RDT and VAR_EXCL are empty

in the second case if i put my IF, ENDIF. as gloabl filter for the second foreach , the second foreach is not executed.

How can i debug except by displying message ?

Thanks

Cyril

0 Kudos

Hi,

to debug you have to type BREAK-POINT in your code and execute the function in debug mode(right click on the parameter group).

related to your code, if you add the line var_cont2 = var_cont , you dont need var_cont2 in the second foreach (actually i think you dont need it at all, you can use var_cont directly).

Additionally, your if in bold, i would put it like this IF VAR_TYE_LIG = ' '. placing the endif at the end.

anyway, try to debug the code...

Cheers,

Ignacio

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Ignacio,

I found the solution. in the second foreach i set up :

FOREACH VAR_CONT IN SELECTION

and it works.

Thanks for your help/

CYril

Former Member
0 Kudos

Many thanks Ignacio, for this code :

FOREACH VAR_CONT, VAR_TYE_LIG IN REFDATA.

IF VAR_TYE_LIG = ''.

VAR_RDT = {ZZRDTOBJ,VAR_CONT,VAR_TYE_LIG,VAR_SOURCE}.

VAR_EXCL = {ZINCL_CT,VAR_CONT,VAR_TYE_LIG,VAR_SOURCE}.

FOREACH VAR_CONT, VAR_TYE_LIG.

IF VAR_TYE_LIG <> ''.

{ZZRDTOBJ,VAR_CONT,'CT',VAR_TARGET} = VAR_RDT.

ENDIF.

ENDFOR.

ENDIF.

ENDFOR.

The second FOREACH the table LT_CUR_00002 is empty.

if i change the ENDIF before the second FOREACH the LT_CUR_00002 is not empty but the problem is that the first foreach is executed twice and the second time value of VAR_RDT and VAR_EXCL are re-initialized (even if there is the IF statement)

Any Idea

Cyril

Former Member
0 Kudos

Hi Ignacio,

Thanks for your reply.

I wrote yoiur answer and i restrict my level with AREA2.

i create the FOREACH In REFDATA. and i can read the line1

But it does not execute the second FOREACH.

i pur a message to see result and it does not execute anything in the FOREACH.

See my code :

VAR_TARGET = 'ZSPA2002'.

VAR_SOURCE = 'ZSPA2001'.

FOREACH VAR_CONT, VAR_PROVIDER1, VAR_TYE_LIG IN REFDATA.

IF VAR_TYE_LIG = ''.

VAR_RDT = {ZZRDTOBJ,VAR_CONT,'',VAR_SOURCE}.

VAR_EXCL = {ZINCL_CT,VAR_CONT,'',VAR_SOURCE}.

FOREACH VAR_CONT, VAR_TYE_LIG2.

IF VAR_TYE_LIG2 <> ''.

{ZZRDTOBJ,VAR_CONT,'CT',VAR_TARGET} = VAR_RDT.

ENDIF.

ENDFOR.

ENDIF.

ENDFOR.

Any idea

Thank you

Cyril

0 Kudos

Hi,

first of all, be sure you restricted the your planning level with area2.

in your first foreach i wouldn't use the var_provider1, it's not needed as you don't use it in the code afterwards.

have you debugged the code? it could be that it is not reaching the second foreach because of that statement IF VAR_TYE_LIG = ''.

try that out. Hope it helps...

Ignacio

0 Kudos

Hi Cyril,

you can try the following:

-restrict your level with only AREA2 data.

-apply this fox code (avoid comments):

foreach line1, contract in refdata. "this loops over AREA1 data

foreach line2. "loops over data restricted in the level(so, AREA2)

{value,line2,contract, area2}={value,line1,contract, area1}.

endfor.

endfor.

Hope it helps.

Ignacio