Application Development and Automation 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: 
Read only

delete duplicate

Former Member
0 Likes
797

Before using delete duplicate to remove duplicate records at internal table, is it i have to sort by all fields?

6 REPLIES 6
Read only

Former Member
0 Likes
779

Hi,

yes the table need to be sorted.

Regards,

Atish

Read only

Former Member
0 Likes
779

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.

Read only

Former Member
0 Likes
779

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

Read only

Former Member
0 Likes
779

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

Read only

radhushankar
Participant
0 Likes
779

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.

Read only

Former Member
0 Likes
779

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