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 duplicate

Former Member
0 Likes
3,789

hi

i need tohave full detail and use of delted adjacent duplicate statement,

where touse it and where not to use it as some confusion is there realted to it.

i need to have all pros and cons of it and also the use and varous options available in it?

pls eloborate more clearly and menwhile ia m also serching for more info on it.

regards

Nishant

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,460

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.

Refer

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/delete_i.htm

Regards,

Santosh

Message was edited by:

Santosh Kumar Patha

8 REPLIES 8
Read only

Former Member
0 Likes
2,461

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.

Refer

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/delete_i.htm

Regards,

Santosh

Message was edited by:

Santosh Kumar Patha

Read only

anversha_s
Active Contributor
0 Likes
2,460

hi,

Example..

For DELETE ADJACENT DUPLICATES you have to sort first..

SORT ITAB BY MATNR.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATNR.

Just use that statement, omitting the COMPARING extension will simply mean that it will look at the entire line.

sort it_bsid ascending.

DELETE ADJACENT DUPLICATES FROM it_bsid.

Rgds

Anversha

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
2,460

Hi,

DELETE - duplicates

Syntax

... ADJACENT DUPLICATES FROM itab

[COMPARING { comp1 comp2 ...}|{ALL FIELDS}]... .

Addition:

... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

Effect

With these additions, the statement DELETE deletes all lines in certain groups of lines, except for the first line of the group. These are groups of lines that follow one another and have the same content in certain components. If the addition COMPARING is not specified, the groups are determined by the content of the key fields.

Lines are considered to be doubled if the content of neighboring lines is the same in the components examined. In the case of several double lines following one another, all the lines - except for the first - are deleted.

Addition

... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

Effect

If the addition COMPARING is specified, the groups are determined either by the content of the specified components comp1 comp2 ... or the content of all components ALL FIELDS. The specification of individual components comp is made as described in the section Specification of Components. Access to class attributes is possible through the object component selector only as of Release 6.10.

Example

Deleting all multiple-occurring lines in the internal table connection_tab. The result of this exanple corresponds to the one in the example for the position specification for INSERT.

DATA: BEGIN OF connection,

cityfrom TYPE spfli-cityfrom,

cityto TYPE spfli-cityto,

distid TYPE spfli-distid,

distance TYPE spfli-distance,

END OF connection.

DATA connection_tab LIKE SORTED TABLE OF connection

WITH NON-UNIQUE KEY cityfrom cityto

distid distance.

SELECT cityfrom cityto distid distance

FROM spfli

INTO TABLE connection_tab.

DELETE ADJACENT DUPLICATES FROM connection_tab.

Cheers,

Simha.

Read only

Former Member
0 Likes
2,460

hi,

As the name says, it deletes the adjacent duplicates of data in the internal table.

Note : Before deleting adjacent duplicates, you have to ensure that the internal table is sorted based on the fields which are used in delete adjacent duplicates statement.

ex:

sort itab by f1 f2 f3.

delete adjacent duplicates from itab comparing f1 f2.

We have list of Sales orders and sold-toparty corresponding to these sales orders.

Now, you require the details of sold-to-party, say name of sold-to-party.

There might be a case, where we have same sold-to-party for different sales orders.

select kunnr
          name1
   from kna1
  into table it_kna1
 where kunnr eq it_vbak-kunnr.

Instead of fetching name1 for every record of vbak, we can minimise our data retrieval by

deleting the duplicates..it_vbak is having 100 records with 10 sol-to-party. in previous select, we have to pass 100 records to fetch kunnr details.

Instead, we can do teh way specified below so that we get data for only 10 kunnrs.


if not it_vbak[] is initial.
  it_vbak_temp[] = it_vbak[].          

  sort it_vbak_temp by kunnr.
  delete adjacent duplicates from it_vbak_temp comparing kunnr.

 select kunnr
          name1
   from kna1
  into table it_kna1
  for all entries in it_vbak_temp
 where kunnr eq it_vbak_temp-kunnr.
  endif.

Hope it is clear...

Regards,

sailaja.

Read only

Former Member
0 Likes
2,460

got helpful anseres rest will explore

if anyone has still more link can mail

Read only

0 Likes
2,460

sometimes we get duplicates to internal table from table,and when you see the repeat same record is repeqting mutiple times,

then we adjacent duplicate condition.

if you use this condition it will delete duplicates value from internal table and also you can keep condition based field you can delete

Read only

Former Member
0 Likes
2,460

hi,

Variant 5

DELETE ADJACENT DUPLICATES FROM itab.

Additions

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.

Notes

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

<b>

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>