2007 May 18 5:48 AM
Hi Friends,
I have one query regarding delete adjacent duplicates statement.
Suppose I have table itab having fields f1, f2 & f3.
f1 f2 f3
a b c
d e f
g h i
a b c
Now I would like to delete the fourth entry means a, b, c because it is duplicate entry.
I have used " Delete adjacent duplicates from itab."
But the above statement will not delete the duplicate entries.
Anybody will pls tell me what I need to do?/
2007 May 18 5:50 AM
Hi,
sort the internal table first and then run the command
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f 2> ...
|ALL FIELDS].
The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are duplicate if they fulfill one of the following compare criteria:
Without the COMPARING addition, the contents of the key fields of the table must be identical in both lines.
If you use the addition COMPARING <f1> <f 2> ... the contents of the specified fields <f 1 > <f 2 > ... must be identical in both lines. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines must be identical.
You can use this statement to delete all duplicate entries from an internal table if the table is sorted by the specified compare criterion.
i think it solve your problems'
Rgds
Deepak.
2007 May 18 6:03 AM
use this way -
sort Itab by f1 f2 f3.
Delete adjacent duplicates from itab comparing f1 f2 f3.
amit
2007 May 18 5:51 AM
Hi
use
sort Itab by f1 f2 f3. then
write
Delete adjacent duplicates from itab comparing f1 f2 f3.
Reward points if useful
Regards
Anji
Message was edited by:
Anji Reddy Vangala
2007 May 18 6:03 AM
Hi,
Suppose I don't want to sort the table.
So is there any way other than this.
2007 May 18 6:07 AM
Hi
Sorting is not necessary in this case....
you can directly write like..
Delete adjacent duplicates from itab comparing f1 f2 f3.
This will work..
Reward all helpfull answers..........
2007 May 18 6:09 AM
if u don want to sort the table then u can write a piece of code to do this but that will be highly inefficient -
code -
itab1[] = itab[].
loop at itab1.
loop at itab where f1 = itab1-f1 and f2 = itab1-f2 and f3 = itab1-f3.
if sy-tabix GT '1'.
delete itab index sy-tabix.
endif.
endloop.
endloop.
now print itab.
2007 May 18 6:12 AM
Hi,
If u wont sort internal table , then u cannot use "delet adjacent dupliactes" as this statement will delete only records which are adjacent (i,e one next to another).
or else do the follwing.without using Sort:
loop the table into workarea.
and then read each recor of the table with key.
if this stament is sucees for 2 times (i.e more than 1 record)
get the sy-index of that record
and delete the same record.
i.e
copy to another internal table.
itab2 [] = itab1[]
count type i value 0.
loop at itab1 into wa1.
read table itab2 into wa2 with key f1 = wa1-f1 f2 = wa1-f2 f3 = wa3-f3.
if sy-subrc = 0.
count = count +1 .
if count >= 2 " i.e more than 1 record.
delete from itab2 index sy-tabix.
endif.
endloop.
revert back if any issues.
Reward with points if helpful.
Regards,
Naveen
2007 May 18 6:06 AM
Hi Neha,
Use this statement:
DELETE ADJACENT DUPLICATES FROM ITAB
COMPARING K.
OR
READ TABLE ITAB INDEX 1 INTO PREV_LINE.
LOOP AT ITAB FROM 2 INTO WA.
IF WA = PREV_LINE.
DELETE ITAB.
ELSE.
PREV_LINE = WA.
ENDIF.
ENDLOOP.
Reward points if helpful.
Regards,
Hemant
2007 May 18 6:39 AM
Hi,
Sort itab by f1 f2 f3.
delete adjecent duplicates comparing all. " if only three flds are there.
It will delete last entry
Jogdand M B