‎2008 May 15 1:17 PM
Hi,
Pls suggest a way to avoid the nested loops of this kind.
itab1 and itab2 are internal tables with header line.
loop at itab1.
loop at itab2 where fld1 = itab1-fld1.
<a few statements here>
endloop.
endloop.
Useful help would be rewarded.
‎2008 May 15 1:21 PM
hi,
you can replace with the read statement, provided you need only one matching record from the internal table.
loop at itab1.
read table itab2 with key fld1 = itab1-fld1.
endloop.
if you have more than one matchin record, then use parallel cursor method. see the sample code [here|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap%2bcode%2bfor%2bparallel%2bcursor%2b-%2bloop%2bprocessing]
regards,
madhumitha
‎2008 May 15 1:21 PM
Hi,
If it is a one - one relation with itab1 then use Read statement and do your logic
If its like item header relation
loop item table and read header table.
Regards,
Siva chalasani.
‎2008 May 15 1:23 PM
Hi Siva and Madhumita,
Thanks a lot for your input, but its not a one-one relationship, so i cant use a READ statement.
‎2008 May 15 1:25 PM
then use parallel cursor method:(sample code in the below link)
regards,
madhu
‎2008 May 15 1:23 PM
Try using a single LOOP, with a READ TABLE inside!
Like this:
LOOP AT itab1.
READ TABLE itab2 WITH KEY fld1 = itab-fld1
BINARY SEARCH.
<statements>
ENDLOOP.
‎2008 May 15 1:24 PM
Hi,
loop at itab1.
loop at itab2 where fld1 = itab1-fld1.
<a few statements here>
endloop.
endloop.
Instead of above code try with this code.
read table itab2 .
if itab-fld1 = itab2-fld1.
<statement>
Endif.
Endloop.
Reward if useful.
Regards,
Narasimha
‎2008 May 15 1:26 PM
Hi,
loop at itab1.
loop at itab2 where fld1 = itab1-fld1.
<a few statements here>
endloop.
endloop.
Instead of above code try with this code.
loop at itab1.
read table itab2 .
if itab-fld1 = itab2-fld1.
<statement>
Endif.
Endloop.
Reward if useful.
Regards,
Narasimha
‎2008 May 15 2:04 PM