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: 

loop in loop performance

Former Member
0 Kudos
255

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

1 ACCEPTED SOLUTION

ravi_lanjewar
Contributor
0 Kudos
201

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"

10 REPLIES 10

Former Member
0 Kudos
201

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?

Former Member
0 Kudos
201

Please dont post duplicate threads.

http://scn.sap.com/thread/3283423

0 Kudos
201

hi sory for double posting ı forgot

thanks by the way

ThomasZloch
Active Contributor
0 Kudos
201

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

0 Kudos
201

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.

0 Kudos
201

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

ravi_lanjewar
Contributor
0 Kudos
202

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"

0 Kudos
201

okey thanks ı have a great deal of data ı will test both technique I think it will show me the differance

Former Member
0 Kudos
201

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

0 Kudos
201

sorted table is the fastest method ı tried it

thanks folks