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: 

internal table

Former Member
0 Kudos

Hi All,

I have a internal table itab.

Is there any fuction module or any other way by which i check out all the duplicate entries in my itab and remove it.

regards,

Raman

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Sort it by the key, and then use the DELETE ADJACENT DUPLICATES statement.

sort itab ascending by keyfield.
delete adjacent duplicates from itab comparing keyfield.

Regards,

Rich Heilman

6 REPLIES 6

Former Member
0 Kudos

Hi Raman...

There is a way to achieve this.

use the statement:

<b>sort itab by field1 field2.

delete adjacent duplicates from itab comparing field1 field2 .

</b>

here itab is the internal table and field1 and field2 are the fields if internal table itab.

see the following link :

<b>http://help.sap.com/saphelp_nw04/helpdata/en/06/aafd54fc4011d195280000e8353423/frameset.htm</b>

Hope it helps you...

Let me know if u have any more doubt...

Reward points if useful......

Suresh.......

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Sort it by the key, and then use the DELETE ADJACENT DUPLICATES statement.

sort itab ascending by keyfield.
delete adjacent duplicates from itab comparing keyfield.

Regards,

Rich Heilman

0 Kudos

Thanks a lot for all your replies.

I got the soluition.

Just one more question related to the reply from Rich.

how can i define primary key from my internal table

regards,

Raman

0 Kudos

No need to define it, simply sort the internal table by the columns that you want to compare for duplicates. So if the duplicates are based on two fields, then sort by those two fields and have both in the COMPARING list.

Regards,

Rich Heilman

0 Kudos

check something like this

DATA:  z_itab1 TYPE TABLE OF z_index WITH NON-UNIQUE KEY field1.

Former Member
0 Kudos

Hi Raman,

There is no function module which will deletes duplicate entries in an internal table.

But SAP provides you a OPEN SQL statement DELETE statement which will do for your requirement.

Syntax:

<b>DELETE ADJACENT DUPLICATES FROM itab.</b>

Check this link to know about DELETE statement

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/delete_i.htm

Thanks,

Vinay