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: 

How to delete duplicate entries from internal table.

Former Member
0 Kudos

hi,

Please tell me how to delete the duplicate values/records from the internal table.

Code will be very helpfull.

Thanks,

Sriram.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

SORT ITAB.

DELETE ADJACENT DUPLICATES FROM ITAB.

( Above will take the key of table as all the character fields in it and delete the rows which have duplicates comparing all the character fields ) .

Cheers.

9 REPLIES 9

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Sriram!

First sort your table by the relevant key:

e.g.

SORT itab_marc by matnr werks.

Then use

delete adjacent duplicates from itab_marc comparing matnr werks.

If you don't sort your table in beforehand, deleting won't work correct. First entry of a sequence will be left in the table.

Regards,

Christian

Former Member
0 Kudos

SORT ITAB.

DELETE ADJACENT DUPLICATES FROM ITAB.

( Above will take the key of table as all the character fields in it and delete the rows which have duplicates comparing all the character fields ) .

Cheers.

0 Kudos

If want to delete duplicate rows based on duplicate values in only certain fields, then sort itab by those fields and then use COMPARING field1 field2 etc.

SORT itab BY field1 fiel2.

DELETE ADJACENT DUPLICATES FROM itab COMPARING field1 field2.

Srinivas

0 Kudos

Please award points for helpful answers and close if answered completely, Thanks.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi sriram,

check this link for further details....

http://help.sap.com/saphelp_erp2004/helpdata/en/06/aafd54fc4011d195280000e8353423/frameset.htm

regards,

venu.

0 Kudos

I need to delete duplicate entries, but not, if the compared field is initial.

Any ideas?

Best regards

Norbert

0 Kudos

Hi,

change your field , which is initial.

loop at itab where f1 = space.
 add 1 to counter.
 *enumerate
 move counter to itab-f1.
 modify ...

after delete:

loop at itab where f1 between 1 and counter.
 clear itab-f1.
...

Andreas

0 Kudos

Thanks Andreas!

In the meantime I got the idea to split the table into two, delete the duplicates in the table without initials and merge them after the deletion.

I'm not sure what has better performance.

Any other ideas or knowledge about performance in this case?

Best regards

Norbert

0 Kudos

... regarding performance, the use of field-symbols is a must!

You may use <fs> type any. <fs> type (your table structure) is even faster:

field-symbols:

<fs> type line of itab.

loop at itab assigning <fs>.

where xfield is initial. "if desired

<fs>-xfield = count.

add 1 to count.

endloop." at itab assigning <fs>.

...

something like this...

C.