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 DUPLCATES

Former Member
0 Likes
821

Hi Experts,

I wonder why delete adjacent duplicate sometimes

doesn't work and sometimes doesn't. Any idea?

Thanks in advance.

Regards,

Rose

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
737

hi

chk this

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.

<b>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.</b>

hi

chk this

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.

<b>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.</b>

4 REPLIES 4
Read only

suresh_datti
Active Contributor
0 Likes
737

You have to SORT the itab before using the DELETE ADJACENT DUPLCATES statement.. you can also use the option COMPARING to be more specific.

Regards,

Suresh Datti

Read only

Former Member
0 Likes
738

hi

chk this

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.

<b>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.</b>

Read only

Former Member
0 Likes
737
  SORT IT_SALES_DATA BY  VBELN POSNR.

  DELETE ADJACENT DUPLICATES FROM IT_SALES_DATA COMPARING  VBELN POSNR.

you need to sort before using delete adjacent duplicates.

Regards

vijay

Read only

0 Likes
737

Hi Suresh Datti and vijay,

Thanks for your replies. I have figured it out myself.

But I am still giving you points for your very very

prompt reply. I got very busy though afterwards and

was unable to reply soon.

Best Regrds,

Rose