Application Development 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: 

Re:Reg Delete

Former Member
0 Kudos

Hi,

what is the difference between

delete adjacent duplicates from itab comparing all fields

delete adjacent duplicates from itab comparing field1 field2

6 REPLIES 6

0 Kudos

Hi,

In the first case all the FIelds of the Internal table are compared.

In the second case only field1 and field2 values are compared while deleting duplicates.

Suppose your itab fields are

fld1 fld2 fld3 fld4 fld5.

in the first case all these fields values will be compared for duplicate values before deletion.

in the second case fld1 fld2 are compared for duplicate values before deletion.

Hope this is clear now.

Regards,

Sesh

Former Member
0 Kudos

Hi,

In first case duplicate records are deleted by comparing whole record. Where as in second case records are deleted by comparing only with field1 and field2.

Regards,

Sankar

Former Member
0 Kudos

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.

If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.

reward if useful

Former Member
0 Kudos

HI,

<b>DELETE ADJACENT</b>

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.

regards,

pritha.

Former Member
0 Kudos

Hi

1. ... COMPARING f1 f2 ...

2. ... COMPARING ALL FIELDS

Effect

Deletes neighboring, duplicate entries from the internal table itab . If there are n duplicate entries, the first entry is retained and the other n - 1 entries are deleted.

Two lines are considered to be duplicated if their default keys match.

The return code value is set as follows:

SY-SUBRC = 0 At least one duplicate exists, at least one entry deleted.

SY_SUBRC = 4 No duplicates exist, no entry deleted.

Addition 1

... COMPARING f1 f2 ...

Effect

Two lines of the internal table itab are considered to be duplicates if the specified fields f1 , f2 , .... match.

Addition 2

... COMPARING ALL FIELDS

Effect

Two lines are considered to be duplicates if all fields of the table entries match.

<b>imp:

The DELETE ADJACENT DUPLICATES statement is especially useful if the internal table itab is sorted by fields (whether in ascending or descending order) which were compared during duplicate determination. In this case, the deletion of neighbouring duplicates is the same as the deletion of all duplicates.

If a comparison criterion is only known at runtime, it can be specified dynamically as the content of a field name by using COMPARING ... (name) ... . If name is blank at runtime, the comparison criterion is ignored. If name contains an invalid component name, a runtime error occurs.

Comparison criteria - statistically or dynamically specified - can be further restriced by specifying the offset and/or length.</b>

Former Member
0 Kudos

Hi

if u have data like this

100--200300-400

100--200400--300

100-200300--400

for ur first case it deletes 1st and 3rd record

for 2nd case it deletes all records

reward points to all helpful answers

kiran.M