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 adjacent duplicates and Sort!

Former Member
0 Likes
8,892

Hello all,

Just a basic one, but I need to confirm from you guys. I believe whenever we use the statement 'DELETE ADJACENT DUPLICATES FROM ITAB......' we should sort itab before that on the field we are comparing. If not the delete adjacent duplicates statement will not work correctly. Am I right?

Thanks,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,736

Yes you are right.

The logic is simple, the statement DELETE ADJACENT DUPLICATES. So unless the data next to each other it cannot delete the duplicates.

Regards,

Ravi

Note - Please mark all the helpful answers

7 REPLIES 7
Read only

Former Member
0 Likes
3,737

Yes you are right.

The logic is simple, the statement DELETE ADJACENT DUPLICATES. So unless the data next to each other it cannot delete the duplicates.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
3,735

Yes, absolutely, otherwise, the duplicates would not be adjacent, right?

Regards,

Rich Heilman

Read only

surya_gupta3
Explorer
0 Likes
3,735

Yes Buddy.

Always do a SORT on Itab before applying DELETE ADJASCENT DUPLICATE.

Regards,

Surya

Read only

Former Member
0 Likes
3,735

Hi Somen,

You are right...

Keep cursor on Key DELETE in Se38.

Do F1 on.. Read details from SAP documentation.

Will learn more about the Options and limitations.

DELETE ADJACENT DUPLICATES FROM itab.

Extras:

1. ... COMPARING f1 f2 ...

2. ... 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, ...

Addition 2

... COMPARING ALL FIELDS

Effect

Two lines of the internal table are regarded as duplicates if all of their field contents are identical.

Notes

The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.

If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.

You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.

Note

Performance:

When you delete a line of an internal table, index maintenance costs are incurred. These depend on the index of the table. The runtime is independent of the width of the table line.

Deleting a line from the middle of an internal table with 200 entries usually requires around 10 msn (standardized microseconds).

When you delete a set of entries using "DELETE itab FROM idx1 TO idx2." or "DELETE itab WHERE ...", index maintenance costs are only incurred once. This means that it is considerably more efficient than deleting entries in a LOOP.

If you want to delete adjacent duplicate entries from an internal table, use the variant " DELETE ADJACENT DUPLICATES FROM itab." instead of a LOOP construction.

Hope This helps in future.

Manish

Message was edited by:

Manish Kumar

Read only

Former Member
0 Likes
3,735

From F1:

Notes

The DELETE ADJACENT DUPLICATES statement works particularly well if you

have sorted the internal table itab according to the fields that you want to compare

when looking for duplicates. In this case, deleting adjacent duplicates is the same

as deleting all duplicates. The direction of the sort is irrelevant.

Rob

Read only

0 Likes
3,735

Yes you need to Sort the itab before you use delete adjacent duplicates.

Madhu.

Read only

0 Likes
3,735

Thanks for the replies.....Points awarded.