2012 Dec 20 2:59 PM
I have to make loop inside a loop ı am looking fastest way to do
my internal tables likes these (not excatly but similiar)
data begin of itabex
matnr like mara-matnr
lgort like mspr-lgort
charg like mspr-charg
data end of itabex
data begin of itabin
matnr like mara-matnr
lgort like mspr-lgort
charg like mspr-charg
data end of itabin
loop at itabex
loop at itabin where matnr eq itabex-matnr
and lgort eq itabex-lgort
endloop
endloop.
or
sort itabin by matnr lgort.
loop at itabex.
read table itabin with key matnr = itabex-matnr
lgort = itabex-lgort binary search.
if sy-subrc eq 0.
lv_tabix = sy-tabix.
loop at itabin from lv_tabix.
if itabin-matnr ne itabex-matnr or
itabin-lgort ne itabex-lgort.
exit.
endif.
endloop
endif.
endloop
or better way to do
2012 Dec 21 7:24 PM
User the sorted table for inner loop.
Change the defination of internal table as
Data: itabin type sorted table of ty_itabin with non-unique key matnr lgort.
below given logic will give the better performance over the parallel cursor method. Parallel cursor method is old and obsolate way of handling the loop within loop.
You can also used the fields symbol insted of work area.
loop at itabin where matnr eq itabex-matnr
and lgort eq itabex-lgort
endloop
endloop.
For more details plz search on scn for key word "Sorted table"
2012 Dec 20 5:38 PM
Yes, you already have an answer. Second method is better.
It is called parallel cursor method. You can search forum for more details.
What is your question exactly?
2012 Dec 20 5:39 PM
2012 Dec 21 7:07 AM
hi sory for double posting ı forgot
thanks by the way
2012 Dec 21 1:56 PM
Parallel cursor method is largely obsolete since you can declare your internal tables as SORTED.
In your similar but not exact example, you should declare ITABIN TYPE SORTED TABLE OF ... WITH ... KEY MATNR LGORT.
Read ABAP documentation for more details.
Thomas
2012 Dec 22 3:32 AM
Parallel cursor method is obsolete? Are you comparing 4.7 and ECC6? I had used it in 4.7 and it worked.
I had more than 1000 entries in both tables and parallel cursor method was the only thing that worked.
Has this issue been addressed in ECC6? I doubt. I had faced the same issue while working on ECC6 as well.
Yes for table entries ranging from 100 to 500, it does not improve performance.
Also, you are sorting on the key fields I guess. I think it works in case you have more fields in table structure and a where clause on non-key fields.
2012 Dec 22 3:13 PM
It's obsolete in a sense that it is unnecessarily complex, by using sorted tables (declared as TYPE SORTED) for the inner loop you achieve similar performance but have more straightforward code. KISS principle. From 702 you can even declare secondary keys for internal tables, in case several access paths are required.
Thomas
2012 Dec 21 7:24 PM
User the sorted table for inner loop.
Change the defination of internal table as
Data: itabin type sorted table of ty_itabin with non-unique key matnr lgort.
below given logic will give the better performance over the parallel cursor method. Parallel cursor method is old and obsolate way of handling the loop within loop.
You can also used the fields symbol insted of work area.
loop at itabin where matnr eq itabex-matnr
and lgort eq itabex-lgort
endloop
endloop.
For more details plz search on scn for key word "Sorted table"
2012 Dec 22 8:30 AM
okey thanks ı have a great deal of data ı will test both technique I think it will show me the differance
2012 Dec 27 10:53 AM
Hello,
Instead of using Loop inside loop .
You can use join query to get data from two different table and create single internal table.
This will get executed fast as compare to loop inside loop.
this is what i think.
Regards,
RK
2012 Dec 27 11:29 AM
sorted table is the fastest method ı tried it
thanks folks