04-07-2009 1:02 PM
hi
i hav loop over ekko.and for 1 record in ekko there are 2 records in mseg i.e 2 movement types bwart....
how to read those two records in the loop ao that i can fill two different fields based on the field bwart...
can anyone please help me
04-07-2009 1:04 PM
Hi,
LOOP AT ekko.
read table it_mseg with key mblnr = ekko-ebeln
bwart = '101'.
read table it_mseg with key mblnr = ekko-ebeln
bwart = '102'.
endloop.
Hope it helps!!
Regards,
Pavan
04-07-2009 1:07 PM
You will have to loop inside loop upto 2 rows and your specified condition....
Or
You can use parallel cursor technique as follows
l_tabix type sy-tabix.
sort itab1 by <key field>
sort itab2 by <key field>
loop at itab1.
loop at itab2 index l_tabix.
if (your condition).
l_tabix = sy-tabix.
* your code here for the conditon.
else.
exit.
endif.
endloop.
endloop.
The concept of parallel cursor is to reduce the execution time of the second loop.
This is achieved by starting the second loop from the index for which the last condition is satisfied.
The prerequisite for this is that the tables should be sorted in same order.
Also the condition should be set proper in the loop so that all data is populated.
Regards,
Lalit Mohan Gupta.
04-07-2009 1:12 PM
Hi,
Loop at itab_ekko.
READ table itab_mseg with key BWART = x.
if sy-subrc eq 0.
statements to modify the itab_mseg
Endif.
READ table itab_mseg with key BWART = y.
if sy-subrc eq 0.
statements to modify the itab_mseg
Endif.
Endloop.
using loop inside a loop will cause performance issue at times, so better use Read statement
Edited by: jeevitha krishnaraj on Apr 7, 2009 2:16 PM
04-07-2009 1:18 PM
Hi,
You can also add a where clause to your second loop, so an if statement is not needed.
Loop at itab intow wa where field1 = ' 1'.
do stuff
Endloop.
It's better to use read statements though this a faster way of working.
Best regards,
Guido Koopmann
Edited by: G. Koopmann on Apr 7, 2009 2:18 PM
04-07-2009 1:59 PM
Hi dear,
you can use loop into loop with specific condion.
e.g.
Loop at ekko into wa_ekko.
loop at mseg into wa_mseg where mblnr = wa_ekko-ebeln.
if wa_mseg-bwart = '101'.
move table.
elseif wa_mseg-bwart = '102'
move table.
endloop.
append internal table.
clear : wa_ekko, wa_mseg.
endloop.
Hope this is usefull for you.
Regards,
Vijay
04-08-2009 7:59 AM
hi,
i hav used the code as below
LOOP AT it_ekKo ASSIGNING <fs_ekKo>.
READ TABLE it_mseg ASSIGNING <fs_mseg>
WITH KEY bwart = c_101
matnr = <fs_ekko>-matnr
werks = <fs_ekko>-werks
ebeln = <fs_ekko>-ebeln
ebelp = <fs_ekko>-ebelp
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-migo_qty = <fs_mseg>-menge.
ENDIF.
READ TABLE it_mseg ASSIGNING <fs_mseg>
WITH KEY bwart = c_101
matnr = <fs_ekko>-matnr
werks = <fs_ekko>-werks
ebeln = <fs_ekko>-ebeln
ebelp = <fs_ekko>-ebelp
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-isu_qty = <fs_mseg>-menge.
ENDIF.
but the first read it is doing whereas the control is not going to 2nd read.........