Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

About looping

Former Member
0 Kudos

Hello,

I have one internal table IT_MDEZ with certain fields and in second internal table i have some fields .

i have to read the IT_MDEZ where one field EXTRA lies in second internal table.

It is something like this.

LOOP AT it_mdez WHERE delkz = 'VC'

AND dat00 LT sy-datum

AND kunnr = it_temp1-kunnr.

  • AND extra(10) IN ( it_cview-vbeln ).

I need syntax for doing this 'AND extra(10) IN ( it_cview-vbeln )'.

extra(10) stores value of VBELN and have to run the loop no of times this value lies in the concerned internal table for each KUNNR.

Please help.

Rgds,

Anshu

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Inside the first loop when these are satisfied then read the second table using the key vbeln into a workarea

6 REPLIES 6

Former Member
0 Kudos

Inside the first loop when these are satisfied then read the second table using the key vbeln into a workarea

0 Kudos

You have to do a loop inside a loop to solve this.

Loop at it_cview.

LOOP AT it_mdez WHERE delkz = 'VC'

AND dat00 LT sy-datum

AND kunnr = it_temp1-kunnr.

AND extra(10) = it_cview-vbeln .

..

..

...

endloop.

endloop.

Regards

Farzan

0 Kudos

Hi,

I have already tried this, but the problem is in my internal table i have more than one vbeln for a particular MATNR & KUNNR.

When I do this, it takes first vbeln and put the data , then for second and so.....so they are repeating values....

My requirement is At new matnr.

For a particular KUNNR from first internal table and corresponding vbeln, check all the vbeln in second internal table and sum the corresponding field MNG01 just once....

This is my first internal table:-

Row WERKS MATNR VBELN KUNNR VKORG KDGRP MATKL

1 BP01 W48101 18 100003 BP01 W00010

2 BP01 W48101 1 C4101 BP01 W00010

3 BP01 W48101 13 C6100 BP01 W00010

4 BP01 W48101 12 C6100 BP01 W00010

5 BP01 W48101 11 C6100 BP01 W00010

6 BP01 W48101 10 C6100 BP01 W00010

7 BP01 W48101 9 C6100 BP01 W00010

8 BP01 W48101 8 C6100 BP01 W00010

9 BP01 W48101 7 C6100 BP01 W00010

10 BP01 W48101 6 C6100 BP01 W00010

11 BP01 W48101 2 C6100 BP01 W00010

12 BP01 W48101 3 C6100 BP01 W00010

13 BP01 W48101 4 C6100 BP01 W00010

14 BP01 W48101 5 C6100 BP01 W00010

15 BP01 W48101 19 C6113 BP01 W00010

Output required is :-

W00010 W48101

c6100 = sum of all mng01 from second internal table for corresponding vbeln.

Hope I am clear..

Regards,

Anshuman

0 Kudos

Change the structure of internal table as MATNR KUNNR VBELN .....

Then use the AT NEW VBELN statement in the first internal table loop. Inside that you loop on the second internal table and sum up the values of MNG01.

Regards

Farzan

0 Kudos

Hey Anshu,

Does something like this help you meet your requirement? Try using a loop and AT events.

Sort i_tab1 by vbeln.

Loop at i_tab1 into wa_tab1.

Move wa_tab1 to l_tab1.

At new vbeln.

clear p_mng01.

loop at i_Tab2 into wa_tab2 where vbeln = l_tab1-vbeln.

p_mng01 = p_mng01 + wa_tab2-mng01.

Endloop.

"Then move p_mng01 to wherever you need it

wa_tab2-totalmng = p_mng01.

Modify i_tab2 from wa_tab2 transporting totalmng

where vbeln = l_tab1-vbeln

and....... "whatever other key field(s) you may have in the table.

endat.

endloop.

Regards,

C

Former Member
0 Kudos

Hi,

My problem solved. Thanks.