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: 

sort

Former Member
0 Kudos
146

hi experts

i have done sorting as follows, but its not working properly.

sort ipos by kda pos udate UTIME descending.

loop at it_final.

read table ipos with key kda = it_final-kdauf pos = it_final-kdpos.

if sy-subrc = 0.

it_final-budat = ipos-udate.

55002964 10 20070907 124549

55002964 20 20070907 124519

55002964 20 20070907 112943

what could be the reason, how to solve this issue.

Thanks in advance.

Regards

Rajaram

1 ACCEPTED SOLUTION

Former Member
0 Kudos
120

hi rajaram,

as per ur coding it is getting sorted by the utime descending.

If u want to do sorting descending.

Then u can use this kind of coding.

<b>sort ipos descending by kda pos udate.</b>

Regards...

Arun.

Reward points if useful.

7 REPLIES 7

Former Member
0 Kudos
120

Hi,

sometimes the sequense of your fields are relevant.

Take a look to your definition IPOS and set at first the field KDA.

It should work.

Regards

Nicole

varma_narayana
Active Contributor
0 Kudos
120

Hi Rajaram..

Do this way...

sort ipos by kda pos <b>Ascending </b> UDATE UTIME descending.

loop at it_final.

read table ipos with key kda = it_final-kdauf pos = it_final-kdpos <b>binary search.</b>

if sy-subrc = 0.

it_final-budat = ipos-udate.

<b>REWARD IF HELPFUL.</b>

0 Kudos
120

sort ipos by udate UTIME descending.

loop at it_final.

read table ipos with key kda = it_final-kdauf pos = it_final-kdpos binary search.

if sy-subrc = 0.

it_final-budat = ipos-udate.

i tried this way also, but the descending is not working properly yar.

0 Kudos
120

Hi,

If this is the result you are getting when you execute the statement

sort ipos by udate UTIME descending

      udate     utime 

55002964 10 20070907 124549

55002964 20 20070907 124519

55002964 20 20070907 112943

<b>then it is correct.</b>

Time is sorted correctly 12:45:49> 12:45:19> 11:29:43.

Regards,

Sesh

Former Member
0 Kudos
120

What is the structure or field sequence of your table ipos?

When sorting a table, be sure that the fields are listed as first, second, third.... index in your table.

In your example your ipos should be contain:


data: begin of ipos occurs 0,
        kda like ...,
        pos like ...,
        udate  like ...,
        UTIME like ...,
        fieldxxx like ...,
        fieldxxx like ...,
        fieldxxx like ...,
end of ipos.

Former Member
0 Kudos
121

hi rajaram,

as per ur coding it is getting sorted by the utime descending.

If u want to do sorting descending.

Then u can use this kind of coding.

<b>sort ipos descending by kda pos udate.</b>

Regards...

Arun.

Reward points if useful.

former_member194613
Active Contributor
0 Kudos
120

why don't you look into the documentation ...

sort ipos {ascending| descending} by ....

has an effect on ALL fields

sort ipos by field1 field2 descending

works only on field2, acending is default.

=> Everything is fine!

Any you should use binary search for the read, then you must sort ipos by kda and pos, and you sort it acending.

=> from my side your program would be o.k., if you add binary search to the read.

Siegfried