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 itab

Former Member
0 Likes
742

I need to do the following sort:

SORT it_header BY lifnr xblnr belnr ASCENDING.

Only I also want it sorted by CHECF descending. Basically, I need it to be ascending except I want all records, with a blank CHECF, last (within it's own vendor, lifnr, section).

Example:

LIFNR XBLNR BELNR CHECF

00001 001000 000100

00002 012000 000111

00002 012340 012300 000034

00001 001100 000110 000001

Would be, after all sorts:

LIFNR XBLNR BELNR CHECF

00001 001100 000100 000001

00001 001000 000100

00002 012340 012300 000034

00002 012000 000111 "If no CHECF then it should be the last entry for the vendor, no matter the other fields.

Is there a way to do this without looping through the table?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
716

Hi,

Try this way...


SORT it_header BY lifnr xblnr belnr ASCENDING
                                CHECF DESCENDING.

Hope this would solve your issue.

Regards

Narin Nandivada.

6 REPLIES 6
Read only

Former Member
0 Likes
717

Hi,

Try this way...


SORT it_header BY lifnr xblnr belnr ASCENDING
                                CHECF DESCENDING.

Hope this would solve your issue.

Regards

Narin Nandivada.

Read only

0 Likes
716

Oh wow, thanks! I had no idea that I could do two different sorts (Directions) in one sort.

Thanks a lot!

Davis

This is the piece of code I ended up using:

SORT it_header BY lifnr ASCENDING checf DESCENDING xblnr belnr ASCENDING.

Edited by: Davis on Jul 18, 2008 2:05 PM

Read only

0 Likes
716

Davis,

I have question .

i used as you suggested by your last reply. but i am thinking the output is not coming as per your first reply

Here is code


report zaRs.
data : begin of it_header occurs 0,
       field1(5) type c,
       field2(6) type c,
       field3(6) type c,
       field4(6) type c.
data : end of it_header.

move '00001001000000100' to it_header. append it_header.

move '00002012000000111' to it_header. append it_header.
move '00002012340012300000034' to it_header. append it_header.
move '00001001100000110000001' to it_header. append it_header.

sort it_header by field1 ascending field4 descending field2 field3 ascending.

loop at it_header.
  write :/ it_header.
endloop.

After running this report i got the output like the following


00001001100000110000001
00001001000000100
00002012340012300000034
00002012000000111

a®

Read only

0 Likes
716

Thanks for your diligence but it does exactly as I want.

Thanks,

Davis

Read only

0 Likes
716

Thanks

a®

Read only

naimesh_patel
Active Contributor
0 Likes
716

Try like:


SORT it_header BY lifnr  ASCENDING
xblnr ASCENDING
belnr ASCENDING
CHECF descending.

Regards,

Naimesh Patel