Application Development and Automation 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: 
Read only

Nested Loop Performance

Former Member
0 Likes
828

Hello Experts, I Have to Tune a report But the problem Aries in this Nested loop.

it taking appox 10 min to exec,Bec of itab1 has 4000 rec and itab2 has 16000 records,

Is there Any Solution To Perform This.........

loop at itab1.

loop at itab2.

if itab1-matnr eq itab2-matnr .

itab2-kbetr = itab1-kbetr .

itab2-konwa = itab1-konwa .

endif.

modify itab2 .

endloop.

endloop.

*

Thanks.............................

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
714

now yolu should be able to answer your last question by yourself:

Most important you fast access in all operations inside a loop !!!

+ use the workaround with READ BINARY SEARCH ... LOOP as explained above

+ or better use a SORTED TABLE !!!

(the 10 points answer is wrong!)

Additionally use the ASSIGNING plus replace the MODIFY by a direct change of the field-symbol.

All explained, solves also your new problem ... and hoopefully also your future problems with internal tables!

6 REPLIES 6
Read only

HermannGahm
Product and Topic Expert
Product and Topic Expert
0 Likes
714

Hi,

try like this:

field_symbols: <fs_itab2> like itab2.

loop at itab1.

loop at itab2 where matnr = itab1-matnr assigning <fs_itab2>.

<fs_itab2>-kbetr = itab1-kbetr .

<ifs_tab2>-konwa = itab1-konwa .

endloop.

endloop.

make sure itab2 is a SORTED table with key matnr.

use field symbols to avoid the modify.

hth,

Hermann

Read only

p604431
Active Participant
0 Likes
714

Hi,

try like this

Loop at itab2.
read table itab1 with key matnr = itab2-matnr.
if sy-subrc = 0.
  itab2-kbetr = itab1-kbetr.
  itab2-konwa = itab1-konwa.
 modify itab2.
endif.
endloop.

Read only

Former Member
0 Likes
714

Thanks Alot Experts.

Issue Has Been Resolved

Edited by: HEMANT_A1 on Feb 8, 2010 11:27 AM

Read only

Former Member
0 Likes
714

Hi,

Another way which doesn't use sorted tables is the following :


FIELD-SYMBOLS : <fs_itab2> LIKE itab2.


SORT itab2 BY matnr.

LOOP AT itab1.
" Search the first matching entry
  READ TABLE itab2 TRANSPORTING NO FIELDS
    WHERE matnr = itab1-matnr
    BINARY SEARCH.
    IF sy-subrc = 0.
" Loop at all following entries
      LOOP AT itab2 ASSIGNING <fs_itab2>
        FROM sy-tabix.

" If entries does not match any more, exit
        IF <fs_itab2>-matnr NE itab1-matnr.
         EXIT.
        ENDIF.

        <fs_itab2>-kbetr = itab1-kbetr.
        <fs_itab2>-konwa = itab1-konwa.
      ENDLOOP.  " AT itab2
   ENDIF.
ENDLOOP.  " AT itab1

There are 2 important rules : use field-symbols to modify internal tables and read only useful entries...

Best regards,

Samuel

Read only

Former Member
0 Likes
715

now yolu should be able to answer your last question by yourself:

Most important you fast access in all operations inside a loop !!!

+ use the workaround with READ BINARY SEARCH ... LOOP as explained above

+ or better use a SORTED TABLE !!!

(the 10 points answer is wrong!)

Additionally use the ASSIGNING plus replace the MODIFY by a direct change of the field-symbol.

All explained, solves also your new problem ... and hoopefully also your future problems with internal tables!

Read only

0 Likes
714

Thanks: Boes .