09-20-2007 10:41 AM
Hi experts,
I have two internal tables , ITAB1 and ITAB2 (same structure), i like to delete the records from ITAB1 which are in ITAB2 without looping .How it can be done?
regards,
Kannan
09-20-2007 10:48 AM
It relies on the size of your itabs. I will assume you want not to loop the first one (because is the biggest).
LOOP AT itab2 INTO wa.
DELETE TABLE itab1 FROM wa.
ENDLOOP.
If your itab2 doesn't contain zillion rows, it will be fast enough to not be painful.
09-20-2007 10:45 AM
Kannan,
As both the tables are having the same strcuture take one more internal table itab3 and move the data in itab1 and itab2 to itab3.
Now itab3 will have the data from both the itab1 and itab2.
Now delete the adjacent duplicates from itab3.
K.Kiran.
09-20-2007 10:55 AM
Kiran, if you do what you say:
itab3 = itab1 + itab2.
delete adjacents.
You will get a table which contains all rows from itab1 and all rows from itab2 that are not in itab1... remember DELETE ADJACENT DUPLICATES doesn't delete all rows duplicated, just all them but one
09-20-2007 10:59 AM
09-20-2007 11:16 AM
Lozan,
What if I sort the itab3(which is having the contents of itab1 and itab2) and then delete using delete adjacent duplicates from itab3.?
Thanks,
K.Kiran.
09-20-2007 11:29 AM
You will get the same result... itab3 is the sum of itab1 and itab2. To delete adjacent duplicates you MUST sort it first, or the delete sentence will have no sense.
And DELETE ADJACENT DUPLICATES ever leave one of the duplicated rows in the table, as far as I know in 4.7 and older versions.
09-20-2007 11:40 AM
Lozan,
itab1 is having 1,2,3,4.
itab2 is having 1,2,5,6,7.
Now I move the contents in itab1 and itab2 to itab3.
itab3 is having now 1,2,3,4,1,2,5,6,7.
Now I will sort this itab3,thus itab3 is now having
1,1,2,,2,3,4,5,6,7.
<b>Now,if I use delete adjacent duplicates from itab3,will it won't result in
1,2,3,4,5,6,7 in itab3?</b>
K.Kiran.
Message was edited by:
Kiran K
Message was edited by:
Kiran K
09-20-2007 12:06 PM
09-21-2007 5:07 AM
Lozan,
So,I missed Sorting concept while answering that question.Thanks alot Buddy.
Thanks,
K.Kiran.
09-20-2007 10:46 AM
hi Kannan,
why without LOOPing? I guess you have to LOOP at least on one of the internal tables.
ec
09-20-2007 10:49 AM
Its going to handle huge number of records , i am worrying about performance issue
09-20-2007 10:53 AM
As Eric has said, I worry you will need to LOOP at least the smallest table. There are nothing like nested selects in the DELETE sentence
Just be sure both your tables are SORTED or HASHED ones, and use the appropiate indexes/keys to make the deletions.
09-20-2007 10:54 AM
Kannan,
Provided you had taken care to use only primary keys or index fields in where statements of every select query,you can be cool irrespective of how many loops you are using or how many records an internal table contains.If you haven't used primary keys or index fields in your where clauses of select statements then it is the area you need to concentrate to improve performance and not on how many loops.
K.Kiran.
09-20-2007 11:19 AM
Don't worry about that... loop is faster than other instructions.
09-20-2007 10:48 AM
It relies on the size of your itabs. I will assume you want not to loop the first one (because is the biggest).
LOOP AT itab2 INTO wa.
DELETE TABLE itab1 FROM wa.
ENDLOOP.
If your itab2 doesn't contain zillion rows, it will be fast enough to not be painful.
09-20-2007 10:52 AM
Hi,
U have to go for loop..some cases we can't avoid it..so loop at least one table..
Regards,
Nagaraj
09-20-2007 11:06 AM
Well if ur ready to loop on one table then i give u method as
loop at itab1 .
read table itab2 with key matnr = itab1-matnr .
if sy-subrc eq 0 .
delete itab1 .
endif .
endloop.