2007 Oct 17 4:48 PM
Before using delete duplicate to remove duplicate records at internal table, is it i have to sort by all fields?
Before using delete duplicate to remove duplicate records at internal table, is it i have to sort by all fields?
2007 Oct 17 4:49 PM
2007 Oct 17 4:50 PM
sort by fields which u r comparing while deleting adjacent duplicates.
ex. sort itab by field1 field2.
delete adjacnet duplicates from itab comparing field1 field2.
2007 Oct 17 4:50 PM
Yes,
you have to sort internal table. That is a prerequisite.
DELETE ADJACENT DUPLICATES FROM itab.
Extras:
... COMPARING f1 f2 ...
... COMPARING ALL FIELDS
Effect
Deletes adjacent duplicate entries from the internal table itab. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.
Two lines are regarded as duplicates if their keys are identical.
The Return code is set as follows:
SY-SUBRC = 0:
At least one duplicate was found, and at least one entry was deleted.
SY-SUBRC = 4:
No duplicates found, no entries deleted.
Addition 1
... COMPARING f1 f2 ...
Effect
Two lines of the internal table itab are regarded as duplicates if they have identical contents in the fields f1, f2, ...
ashish
2007 Oct 17 4:50 PM
Hi,
it is not required to sort by all field. Just sort the fields which ever you want to compare for deletion.
<b>Reward for helpful answers</b>
Cheers,
Satish
2007 Oct 18 11:05 AM
Hi
No need to sort by all fields. but if u sort it by ur primary key it will increase the performance.
sort itab by <key>
delete adjacent duplicates from table <itab>.
Reward points if useful.
2007 Oct 18 11:18 AM
Hi,
Yes, you can sort the fields. Check the following code:
data: begin of itab occurs 0,
fld1(4) type c,
fld2(20) type c,
end of itab.
itab-fld1 = '1234'.
itab-fld2 = 'Apple'.
append itab.
itab-fld1 = '2313'.
itab-fld2 = 'Orange'.
append itab.
itab-fld1 = '234'.
itab-fld2 = 'Banana'.
append itab.
itab-fld1 = '123'.
itab-fld2 = 'Mango'.
append itab.
itab-fld1 = '1234'.
itab-fld2 = 'Apple'.
append itab.
sort itab.
loop at itab.
write:/ itab-fld1, itab-fld2.
endloop.
DELETE ADJACENT DUPLICATES FROM itab.
write:/ 'After delete:'.
loop at itab.
write:/ itab-fld1, itab-fld2.
endloop.
Regards,
Bhaskar
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |