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

Extract - Delete Adjacent Duplicates

ramesh_kajuru
Explorer
0 Likes
684

Hi Experts,

As in internal tables is it possible to delete adjacent duplicate records from an extract ?

Thanks in advance.

Ramesh.

5 REPLIES 5
Read only

former_member386202
Active Contributor
0 Likes
612

Hi,

Yes , Refer this

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.

Regards,

pRashant

Read only

0 Likes
612

Hi Prshant & All,

Thanks for the response, My question is not about an internal table but about an EXTRACT. i.e Field-Group.

Thanks in adcance

Ramesh.

Edited by: Ramesh Kajuru on Dec 20, 2007 12:53 AM

Read only

former_member156446
Active Contributor
0 Likes
612

yes

delete adjacent duplicated from table itab comparing f1 f2 f3

f1 and f2 and f3 are the fields u want to compare

Read only

Former Member
0 Likes
612

Hi Ramesh,

I think it is possible to delete adjacent duplicates in an internal table.

After uploading datas in to ur internal table jus use the foll..

Delete adjacent duplicates from <Internal_table>.

You can also delete duplicates comparing certain fields...

For eg

Delete adjacent duplicates from <Internal_table> comparing <field1> <field1>. "as u require.

Regards

Naveen

Read only

Former Member
0 Likes
612

Hi,

Deleting Adjacent Duplicate Entries

To delete adjacent duplicate entries use the following statement:

DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>

[COMPARING <f1> <f2> ...

|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> <f2> ... the contents of the specified fields <f1> <f2> ... must be identical in both lines. You can also specify a field <fi> dynamically as

the contents of a field <ni> in the form (<ni>). If <ni> 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.

Ex.

DATA OFF TYPE I.

DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE C,

END OF LINE.

DATA ITAB LIKE STANDARD TABLE OF LINE

WITH NON-UNIQUE KEY COL2.

LINE-COL1 = 1. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

LINE-COL1 = 1. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

LINE-COL1 = 1. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 2. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 3. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 4. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 5. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

OFF = 0. PERFORM LIST.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

OFF = 14. PERFORM LIST.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING COL1.

OFF = 28. PERFORM LIST.

DELETE ADJACENT DUPLICATES FROM ITAB.

OFF = 42. PERFORM LIST.

FORM LIST.

SKIP TO LINE 3.

LOOP AT ITAB INTO LINE.

WRITE: AT /OFF LINE-COL1, LINE-COL2.

ENDLOOP.

ENDFORM.

Regards,

Bhaskar