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. 
  

2 comments:

  1. so i have 2 select-options inputs :like bellow
    so_matnr --------(mara)(optional)
    so_werks---------(marc)(must)

    whenever using "for all entries" make sure driver table where condition(optional time)should not be empty.if it is empty then all records will fetch into that itab(mara) table so for this itab(mara)
    2nd select stm itab(marc)where cond will got all matching records.......

    this is not correct oupt..
    so actually for this input werks i want that matching records only.....from mara.....
    but it get all records...
    for this i did put loop for less table(marc) and append these to so_matnr then
    delete it_mara where matnr not in so_matnr.

    so is there any other way to get correct ouput.....bcz this one may performance issue....

    so can we do this by usiing delete adjecent dublicate from itab comparing ...



    ReplyDelete
  2. so i have 2 select-options inputs :like bellow
    so_matnr --------(mara)(optional)
    so_werks---------(marc)(must)

    whenever using "for all entries" make sure driver table where condition(optional time)should not be empty.if it is empty then all records will fetch into that itab(mara) table so for this itab(mara)
    2nd select stm itab(marc)where cond will got all matching records.......

    this is not correct oupt..
    so actually for this input werks i want that matching records only.....from mara.....
    but it get all records...
    for this i did put loop for less table(marc) and append these to so_matnr then
    delete it_mara where matnr not in so_matnr.

    so is there any other way to get correct ouput.....bcz this one may performance issue....

    so can we do this by usiing delete adjecent dublicate from itab comparing ...



    ReplyDelete