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

LOOP and Performance

Former Member
0 Likes
711

Hi All,

I have 2 Internal Tables..

itab1 containgi 2000 employees numbers.

itab2 containing 5000 employees numbers.

The requirement is to delete the employees from itab2 if the itab2-pernr = itab1-pernr.

I have used the following logic...

loop at itab1.

loop at itab2.

if itab1-pernr = itab2-pernr.

delete itab2.

endif.

endloop.

endloop.

But the performance of the report is becoming issue with this logic.

Any other logic where the processing will become faster than the current one?

Please help me....

Regards

Pavan

Moderator message - Moved to the correct forum

Edited by: Rob Burbank on Aug 13, 2009 9:21 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
679

HI

sort itab2 by pernr.

Loop at Itab1.

delete itab2 where pernr = itab1-pernr.

enloop.

Kiran

7 REPLIES 7
Read only

Former Member
0 Likes
680

HI

sort itab2 by pernr.

Loop at Itab1.

delete itab2 where pernr = itab1-pernr.

enloop.

Kiran

Read only

Former Member
0 Likes
679

Hi,

Use following logic.

loop at itab2.

read itab1 into wa_tab1 where pernr = itab2-pernr.

if sy-subrc is initial.

delete itab2.

endif.

endloop.

Regards

Milan

Read only

Former Member
0 Likes
679

Hi

Why don't use a where condition?

loop at itab1.
  loop at itab2 where pernr = itab1-pernr-.
     delete itab2..
   endloop.
endloop.

or

loop at itab1.
  delete itab2 where pernr = itab1-pernr.
endloop.

This should improve the performamce, if you don't use a WHERE condition the system LOOP all record of ITAB2 for every record of ITAB1.

Max

Read only

Former Member
0 Likes
679

loop at itab2 into wa_tab2.

read table itab1 into wa_itab1 with key pernr = wa_itab2-pernr.

if sy-subrc = 0.

delete from itab2 acc to ur req.

endif.

endloop.

or use a where coditon at the LOOP statement.

Read only

Former Member
0 Likes
679

Define one more field in itab2 say flag. do not use delete in loop; set flag instead as below.

loop at itab1.

loop at itab2.

if itab1-pernr = itab2-pernr.

set flag = 'x' .

endif.

endloop.

endloop.

delete itab2 out side loop as below:

delete itab2 where flag is 'X'.

Delete in the loop cause performance issue bcoz every time record is deleted, system has to assign new index to all entries.

Read only

former_member209217
Active Contributor
0 Likes
679

loop at itab1 into wa1----


>use Work area

(loop at itab2) -


>use read statement READ itab2 into wa2 where itab2-pernr = wa1-pernr

check this link once.

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3aef358411d1829f0000e829fbfe/frameset.htm

Read only

Former Member
0 Likes
679

No, no, and no

This question is NOT answered!

Only the sorted table works optgimized with DELETE WHERE.

The standard table needs sorting but also BINARY SEARCH, LOOP FROM and CHECK!!!!!

see

Measurements on internal tables: Reads and Loops:

/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables

But

I would always recommend the opposite logic


LOOP AT itab2  ASSIGNING <fs>.
   READ TABLE itab1 TRANSPORTING NO FIELDS
             WITH KEY..:
* sort table, hash table or standard with binary search
   IF ( sy-subrc = 0 ).
   ELSE.
     APPEND <fs>  TO itab3.
   ENDIF.
ENDLOOP.

REFRESH itab2.
itab2[] = itab3[].

This is much safer and also fast.

Siegfried