‎2009 Aug 13 11:44 AM
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
‎2009 Aug 13 11:47 AM
HI
sort itab2 by pernr.
Loop at Itab1.
delete itab2 where pernr = itab1-pernr.
enloop.
Kiran
‎2009 Aug 13 11:47 AM
HI
sort itab2 by pernr.
Loop at Itab1.
delete itab2 where pernr = itab1-pernr.
enloop.
Kiran
‎2009 Aug 13 11:48 AM
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
‎2009 Aug 13 11:49 AM
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
‎2009 Aug 13 11:50 AM
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.
‎2009 Aug 13 11:51 AM
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.
‎2009 Aug 13 11:53 AM
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
‎2009 Aug 13 4:20 PM
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