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

I have to make loop inside a loop ı am looking fastest way to do

my internal tables likes these (not exactly 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 much more better way to do

Moderator message: duplicate post.

Message was edited by: Thomas Zloch

1 REPLY 1

Former Member
0 Kudos

Hi Oldun,

In the second example you are doing double work, once reading (search in table itabex) and then loop (new search in the same table), so it's better the first solution you gave with only one loop.

On the other hand if in the table itabex you are looking for only one register you could only do reading search with no loop necessary.

Regards,