‎2006 Jun 28 3:43 AM
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 |
‎2006 Jun 28 4:02 AM
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
‎2006 Jun 28 3:55 AM
Hi
sort it by DESCENDING or ASCENDING ORDER.
Delete the last row.
‎2006 Jun 28 4:00 AM
The itab contains many entries and duplicates. And for all the duplicates I need to remove the one that contains the lowest value.
‎2006 Jun 28 4:02 AM
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
‎2006 Jun 28 4:10 AM
Thanks viraylab
I just need to add another descending statement for each field in the sort command.