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

Doubt on Delete Duplicate Adjacent

Former Member
0 Likes
986

Hi,

Suppose my internal table ITAB has 4 fields F1 F2 F3 F4 with the following data:

F1 F2 F3 F4

1 1 1 2

2 1 1 3

3 1 1 2

1 1 1 2

then how many records are left after DELETE ADJACENT DUPLICATES FROM ITAB.

how many records are left after DELETE ADJACENT DUPLICATES FROM ITAB COMPARING F4.

is is mandatory to sort before using above statements...

Thanks

Tarun Brijwani.

6 REPLIES 6
Read only

Former Member
0 Likes
721

Hi,

To delete all duplicate entries from a sorted internal table (e.g. just after SORT), you can use the

DELETE ADJACENT DUPLICATES FROM itab

statement.

You can use the COMPARING adition to limit the fields that are used to test for duplicate entries e.g.

SORT i_tab by matnr werks logort.

DELETE ADJACENT DUPLICATES FROM itab COMPARING matnr werks.

All duplicates withe same combination of matnr and werks will be deleted.

Regards

Krishna

Read only

Former Member
0 Likes
721

This is pretty basic. Why don't you simply try it??

Rob

Read only

Former Member
0 Likes
721

This message was moderated.

Read only

0 Likes
721

>

> Sort is must before you use the Delete Adjacent Duplicate statement. With out sort you will not get the appropriate results.

Incorrect - it depends on the requirements whether and how you sort.

Rob

Read only

Former Member
0 Likes
721

Hi YOu have to sort it first based on F4 and then apply delete adjacent duplicates. It will delete two records with the value f4 = 2 and 2 records will remain. Delete adjacenet duplicates will not work properly if you do not sort it first.

Read only

Former Member
0 Likes
721

F1 F2 F3 F4

1 1 1 2

2 1 1 3

3 1 1 2

1 1 1 2

when you do

delete adjacent duplicates comparing F4.

this will delete the last entry.

output:

F1 F2 F3 F4

1 1 1 2

2 1 1 3

3 1 1 2

how delete adjacent duplicate works is:

it checks the entry and compares with the next entry comparing the field mentioned,

when it finds the field as same it deletes the next entry.

when it finds the entry same and deletes , it again checks the same with the next line and then continues.

If you sort your table before delete adjacent duplicates all the entries with the field mentioned as same will be deleted.

When you do sort on F4 and then delete adjacenct duplicates.

output would be as follows:

F1 F2 F3 F4

1 1 1 2

2 1 1 3

Regards,

Lalit Mohan Gupta.