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

SORT INTERNAL TABLE USING NON KEY OF THE INTERNAL TABLE

Former Member
0 Likes
1,171

HI,

i have one query for the cdpos table of abap.

What i am looking is i want the latest CHANENR of the cdpos for that

objectid and tabname and fname in my internal table.

what i thought of doing was to sort my internal table with objectid changnr tabname fname in descending order

and than use delete adjacent duplicates command

BUt that is not sorting based on all field , its sorting on changnr only

please let me know what can i do

7 REPLIES 7
Read only

Former Member
0 Likes
947

hi,

instead of using delete adjacent duplicates..read the first line since you are sorting descendig by using read from itam index 1.u will get the value

Read only

Former Member
0 Likes
947

try this..

sort itab by changnr descending.
delete adjacent duplicates from itab.

Read only

Former Member
0 Likes
947

I think better sort it on objectid tabname fname changenr descending.

Regards

Anurag

Read only

Former Member
0 Likes
947

no, that is not what i am looking at,

I am saying say i have internal table cdpos

OBJECTCLAS OBJECTID CHANGENR TABNAME FNAME

RECN_RECN |0100TEST1 0000384409| VICN01 |RECNEND

RECN_RECN 0100TEST1 0000383462 VICN01 RECNLIFNR

RECN_RECN 0100TEST1 0000360190 VICN01 RECNEND

RECN_RECN 0100TEST1 0000340630 VICN01 RECNEND

this is my debug output after sorting on objectid changenr tabname fname in descending

i wanted line 2nd to be at last so when i use delete adjacent command i can get 2 line item i.e 1st and 2nd line ...

Read only

Former Member
0 Likes
947

HI ANURAG,

THANKS ITS WORKING

I HAVE ONE QUERY ON SORT COMMAND

IS IT THAT SORT HAPPENS ONLY ON KEY FIELD. THE WAY U DEFINE WHILE

DECLARING THE INTERNAL TABLE

Read only

0 Likes
947

The entries in the internal table are sorted in ascending order using the key from the table definition (DATA, TYPES).

Read only

0 Likes
947

It is nice to understand the soln works..if so please assign points to all helpful answers.

As for your query, if you just use SORT it would do it on the key fields but it is possible to define your sort using nonkey fields even.

Regards

Anurag