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

internal table

Former Member
0 Likes
624

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
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
600

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
Read only

Former Member
0 Likes
600

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.......

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
601

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

Read only

0 Likes
600

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

Read only

0 Likes
600

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

Read only

0 Likes
600

check something like this

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

Read only

Former Member
0 Likes
600

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