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: 

reg deleting entries from internal table

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

VXLozano
Active Contributor
0 Kudos

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.

16 REPLIES 16

kiran_k8
Active Contributor
0 Kudos

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.

VXLozano
Active Contributor
0 Kudos

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

kiran_k8
Active Contributor
0 Kudos

Lozan,

Thanks.

K.Kiran.

kiran_k8
Active Contributor
0 Kudos

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.

VXLozano
Active Contributor
0 Kudos

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.

kiran_k8
Active Contributor
0 Kudos

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

VXLozano
Active Contributor
0 Kudos

Yes, you will get 1234567

kiran_k8
Active Contributor
0 Kudos

Lozan,

So,I missed Sorting concept while answering that question.Thanks alot Buddy.

Thanks,

K.Kiran.

JozsefSzikszai
Active Contributor
0 Kudos

hi Kannan,

why without LOOPing? I guess you have to LOOP at least on one of the internal tables.

ec

0 Kudos

Its going to handle huge number of records , i am worrying about performance issue

0 Kudos

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.

0 Kudos

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.

0 Kudos

Don't worry about that... loop is faster than other instructions.

VXLozano
Active Contributor
0 Kudos

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.

former_member404244
Active Contributor
0 Kudos

Hi,

U have to go for loop..some cases we can't avoid it..so loop at least one table..

Regards,

Nagaraj

Former Member
0 Kudos

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.