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 duplicate entry with the lowes value

Former Member
0 Likes
641

I'm trying to delete any duplicates from my itab with the lowest value by sorting it. But it always deletes the highest value.

How do I do that?

Ex.

fld1 fld2

540-002

0110

|551-100|0085 | >>>> delete this

|551-100|0145 | >>>> not this

551-422

0140

1 ACCEPTED SOLUTION
Read only

aris_hidalgo
Contributor
0 Likes
604

Hi,

You could do it this way:

sort itab by field1 descending field2 descending.

delete adjacent duplicates from itab comparing field1 field2.

What the above statement would do is that it sorts first your itab in descending order and then deletes the duplicate adjacent record.

Here is an example:

report ztest_001.

DATA: BEGIN OF itab OCCURS 0,

f1(10) TYPE c,

f2(20) TYPE c,

f3 TYPE i,

END OF itab.

itab-f1 = 'Adrian'.

itab-f2 = 'Checa'.

itab-f3 = '100'.

APPEND itab.

itab-f1 = 'Adrian'.

itab-f2 = 'Checa'.

itab-f3 = '200'.

APPEND itab.

CLEAR itab.

SORT itab BY f1 DESCENDING f2 DESCENDING f3 DESCENDING.

DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f2.

LOOP AT itab.

WRITE: / itab-f1,

itab-f2,

itab-f3.

ENDLOOP.

Regards!

P.S. Please award points for useful answers.

Message was edited by: viraylab

4 REPLIES 4
Read only

Former Member
0 Likes
604

Hi

sort it by DESCENDING or ASCENDING ORDER.

Delete the last row.

Read only

0 Likes
604

The itab contains many entries and duplicates. And for all the duplicates I need to remove the one that contains the lowest value.

Read only

aris_hidalgo
Contributor
0 Likes
605

Hi,

You could do it this way:

sort itab by field1 descending field2 descending.

delete adjacent duplicates from itab comparing field1 field2.

What the above statement would do is that it sorts first your itab in descending order and then deletes the duplicate adjacent record.

Here is an example:

report ztest_001.

DATA: BEGIN OF itab OCCURS 0,

f1(10) TYPE c,

f2(20) TYPE c,

f3 TYPE i,

END OF itab.

itab-f1 = 'Adrian'.

itab-f2 = 'Checa'.

itab-f3 = '100'.

APPEND itab.

itab-f1 = 'Adrian'.

itab-f2 = 'Checa'.

itab-f3 = '200'.

APPEND itab.

CLEAR itab.

SORT itab BY f1 DESCENDING f2 DESCENDING f3 DESCENDING.

DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f2.

LOOP AT itab.

WRITE: / itab-f1,

itab-f2,

itab-f3.

ENDLOOP.

Regards!

P.S. Please award points for useful answers.

Message was edited by: viraylab

Read only

0 Likes
604

Thanks viraylab

I just need to add another descending statement for each field in the sort command.