Wednesday, June 5, 2013

Delete duplicate from internal table

Duplicated rows in internal table can be easily deleted using standard code "DELETE ADJACENT DUPLICATES"

for example :

DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.


This code will compare all the fields in the internal table and only delete the the rows if all the fields are duplicated with previous rows.





DELETE ADJACENT DUPLICATES FROM itab COMPARING col1.

This code will compare a particular field(s) in the internal table and only delete the the rows if these field(s) is/are duplicated with previous rows.

Make sure that your internal table is sorted by the fields you want to be checked for duplicates BEFORE deleting the duplicates.

for example: 

SORT itab BY col1.
DELETE ADJACENT DUPLICATES FROM itab COMPARING col1.