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 Problem

Former Member
0 Likes
1,321

Hi Experts,

I have this requirement:

Current Scenario: I have data like this now.

Service Centre State Code LOB Days Aged

03 19 A 91-100

03 19 A 31-60

03 19 A 61-90

01 15 F 61-90

01 15 F 91-100

01 15 F 31-60

After sorting in Ascending Order:

Service Centre State Code LOB Days Aged

01 15 F 31-60

01 15 F 61-90

01 15 F 91-100

03 19 A 31-60

03 19 A 61-90

03 19 A 91-100

Now, I need column Days Aged to be sorted in Descending Order, like this

Service Centre State Code LOB Days Aged

01 15 F 91-100

01 15 F 61-90

01 15 F 31-60

03 19 A 91-100

03 19 A 61-90

03 19 A 31-60

Please provide solution for this. Please look through the example carefully. I need only one column in descending order finally.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,020

Hi,

sort itab by : ServiceCentre ascending

StateCode ascending

LOB ascending

DaysAged descending.

This works.

8 REPLIES 8
Read only

Former Member
0 Likes
1,020

hi

sort the table with days aged descending

SORT itab by days aged descending
                              service center ascending
                              state code ascending.

this will solve the problem

thanks

sarves

Read only

Former Member
0 Likes
1,020

HI,

Sort ITAB by Service_Centre State_Code LOB Days_Aged descending.

U need to add addition descending for field days_aged.

Regards,

Dwaraka.S

Read only

faisalatsap
Active Contributor
0 Likes
1,020

Hi,

Have you tried like following hope will solve out your problem,

SORT itab by a ASCENDING b DESCENDING c ASCENDING.

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,020

Hi Experts,

I have this requirement:

Current Scenario: I have data like this now.

Service Centre       State Code        LOB          Days Aged
     03                19               A               91-100
     03                19               A               31-60
     03                19               A               61-90
     01                15               F               61-90
     01                15               F               91-100
     01                15               F               31-60

After sorting in Ascending Order:

*Service Centre       State Code        LOB          Days Aged*
     01                  15               F           31-60 
     01                  15               F           61-90 
     01                  15               F           91-100
     03                  19               A           31-60
     03                  19               A           61-90
     03                  19               A           91-100

Now, I need column Days Aged to be sorted in Descending Order, like this

*Service Centre       State Code        LOB          Days Aged*
     01                  15                F             91-100
     01                  15                F             61-90
     01                  15                F             31-60
     03                  19                A             91-100
     03                  19                A             61-90
     03                  19                A             31-60

Please provide solution for this. Please look through the example carefully. I need only one column in descending order finally.

Read only

0 Likes
1,020

Have you tried ORDER BY clause in Select statement.

i.e.

SELECT *

from DBTAB into ITAB

ORDER BY URFIELD descending.

Hope it helps.

Vikas

Read only

0 Likes
1,020

hi,

Run this code, this gives an output required in your format.

DATA:
  BEGIN OF t_tab OCCURS 0,
  var TYPE c,
  int TYPE i,
  END OF t_tab.

t_tab-var = 'A'.
t_tab-int = 1.
APPEND t_tab.
t_tab-var = 'B'.
t_tab-int = 1.
APPEND t_tab.
t_tab-var = 'C'.
t_tab-int = 1.
APPEND t_tab.
t_tab-var = 'A'.
t_tab-int = 2.
APPEND t_tab.
t_tab-var = 'B'.
t_tab-int = 2.
APPEND t_tab.
t_tab-var = 'C'.
t_tab-int = 2.
APPEND t_tab.


SORT t_tab BY var ASCENDING int DESCENDING.

LOOP AT t_tab.
  WRITE:
    / t_tab-var, t_tab-int.
ENDLOOP.

Thanks and regards

Sharath

Read only

Former Member
0 Likes
1,021

Hi,

sort itab by : ServiceCentre ascending

StateCode ascending

LOB ascending

DaysAged descending.

This works.

Read only

Nawanandana
Active Contributor
0 Likes
1,020

hi

try this way....

Assume ur internal table itab

get another internal table itab2

1st sort itab by Service

itab[] = itab2[]

thn sort itab2 by Days Aged Descending Order

i = SY-TABIX.

loop at itab.

read itab2 index i.

itab-Days Aged = itab2-Days Aged

modify itab.

endloop.

regard

nawa