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

Sorting and deleting

Former Member
0 Likes
1,711

Hi,

I have an internal table

itab

a b

40 44

40 55

I want to delete the duplicates of column A

I need row 2 because it is having hghest value in column B

F1 is a good tool to start with.

Plus You already have the keywords with you.

pk

5 REPLIES 5
Read only

Former Member
0 Likes
891

F1 is a good tool to start with.

Plus You already have the keywords with you.

pk

Read only

0 Likes
891

No it is a internal table of diffrent table fields.

Read only

Former Member
0 Likes
891

Hi

SORT ITAB BY A ASCENDING B DESCENDING.

In this way the firt row as soon as the value of A is changed is the row you need:

LOOP AT ITAB.
  IF ITAB-A = OLD_A.
    DELETE ITAB.
  ENDIF.
  OLD_A = ITAB-A.
ENDLOOP.

Max

Read only

Former Member
0 Likes
891

Alternatively you can also

Use

SORT itab by A ascending B descending

DELETE adjacent duplicates comparing A.

This will help.

Regards,

Prashant

Read only

raviprakash
Product and Topic Expert
Product and Topic Expert
0 Likes
891

>

> Hi,

>

>

> I have an internal table

>

> itab

>

> a b

> 40 44

> 40 55

>

> I want to delete the duplicates of column A

> I need row 2 because it is having hghest value in column B

Hi Shilpa,

Lets analyse the problem first. You need to delete the duplicate entries from an internal table provided that the entry which remains, is the entry with highest value for field B.

Thus we can use the ABAP keyword SORT. You can sort the table in descending order and the use the ABAP ststement DELETE DUPLICATE. Here is the code:-

* The below code sorts the table in such a way that the table looks like follows:-
* A    B
*40   55
*40   44
SORT itab by a b descending.

*Next delete duplicates
DELETE ADJACENT DUPLICATES FROM itab COMPARING A .

Regards,

Ravi.