Application Development 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: 

Sorting table combine with Assending n DESCENDING value

Former Member
0 Kudos

Dear All ...

i want to sort by table with some field. which some of the field in assending n some in desending.

example: this my table itab .

1.1.09 a H

1.1.09 c H

1.1.09 c S

1.1.09 a S

after sort become

1.1.09 a S

1.1.09 a H

1.1.09 c S

1.1.09 c H

from above sample ....... 1st n 2nd value is sort in assending , but 3th sort in desending ....

any idea ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

You can use following code

Sort table itab <first field> <second field> <third field> descending

Hope it helps

8 REPLIES 8

Former Member
0 Kudos

HI.

Give three field while doing stor your internal tanle.I hope so u didnt added your 3rd field .

Eg:

SORT <itab> BY <f1> <f2> <f3>.

Regards,

jay

former_member209705
Participant
0 Kudos

Hi,

My humble feeling is that its not possible in single sort statement.

Regards,

Ravi shankar

Former Member
0 Kudos

Hi,

Just sort the itab as given below, you will get the desired output.


sort itab by field4 descending. 
sort itab by field1 field2 field3 ascending.

Regards,

Vik

Former Member
0 Kudos

HI,

You can use following code

Sort table itab <first field> <second field> <third field> descending

Hope it helps

Former Member
0 Kudos

Hi,

Try this,



DATA: BEGIN OF itab OCCURS 0,
        f1(15) TYPE c,
        f2(15) TYPE c,
        f3(15) TYPE c,
      END OF itab.

itab-f1 = 1.
itab-f2 = 'a'.
itab-f3 = 'H'.
APPEND itab.

itab-f1 = 1.
itab-f2 = 'c'.
itab-f3 = 'H'.
APPEND itab.

itab-f1 = 1.
itab-f2 = 'c'.
itab-f3 = 'S'.
APPEND itab.

itab-f1 = 1.
itab-f2 = 'a'.
itab-f3 = 'S'.
APPEND itab.

SORT itab by f1 f2 f3 DESCENDING.

LOOP AT itab.
  WRITE:/ itab-f1, itab-f2, itab-f3.
ENDLOOP.

Former Member
0 Kudos

ya .... but how i going to make the 3th value in descending ? once i sort the 1st n 2nd, 3rd will change the sequence also ..

0 Kudos

Hi,

This can be done in a single sort statement as below


sort itab descending by f1 f2 f3 ascending f4.

Regards,

Vik

Edited by: vikred on Aug 3, 2009 11:36 AM

Former Member
0 Kudos

HI

use the following code

SORT ITAB BY FIELD ASCENDING.

SORT ITAB BY FIELD1 FIELD2 FIELD3 DESCENDING.

~linganna