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 an internal table by date.

Former Member
0 Likes
1,424

SORT it_stpo BY andat stpoz DESCENDING.

before sort

DATUV ANDAT STLKN STPOZ

1. 20020118|20020118|00000002|00000004|

2. 20060711|20060811|00000004|00000008|

3. 20060801|20060811|00000005|00000011

4. 20020515|20020515|00000003|00000006

AFTER SORT..

DATUV ANDAT STLKN STPOZ

1. 20020118|20020118|00000002|00000004

2. 20020515|20020515|00000003|00000006|

3. 20060801|20060811|00000005|00000011

4. 20060711|20060811|00000004|00000008|

what I expected was to see Record # 3 as my first record after the sort ?

Any ideas?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,069

You either need to explicitly state "descending" after each filed in the sort statement or one time before all fields. Your statement actually translates to sort it_stpo by andat ascending stpoz descending.

SORT it_stpo BY andat stpoz DESCENDING.

before sort

DATUV ANDAT STLKN STPOZ

1. 20020118|20020118|00000002|00000004|

2. 20060711|20060811|00000004|00000008|

3. 20060801|20060811|00000005|00000011

4. 20020515|20020515|00000003|00000006

AFTER SORT..

DATUV ANDAT STLKN STPOZ

1. 20020118|20020118|00000002|00000004

2. 20020515|20020515|00000003|00000006|

3. 20060801|20060811|00000005|00000011

4. 20060711|20060811|00000004|00000008|

what I expected was to see Record # 3 as my first record after the sort ?

Any ideas?

7 REPLIES 7
Read only

suresh_datti
Active Contributor
0 Likes
1,069

Are you sure DATUV & ANDAT are of type DATS?

~Suresh

Read only

0 Likes
1,069

typed as follows:

BEGIN OF it_stpo OCCURS 10,

datuv TYPE stpo-datuv,

andat TYPE stpo-andat,

stlkn TYPE stpo-stlkn,

stpoz TYPE stpo-stpoz,

ltxsp TYPE stpo-ltxsp,

potx1 TYPE stpo-potx1,

END OF it_stpo.

Read only

Former Member
0 Likes
1,070

You either need to explicitly state "descending" after each filed in the sort statement or one time before all fields. Your statement actually translates to sort it_stpo by andat ascending stpoz descending.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,069

Can you please try this statement instead.



sort it_stpo descending by andat stpoz .

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,069

SORT it_stpo BY andat DESCENDING stpoz DESCENDING.

Read only

Former Member
0 Likes
1,069

Hi,

Please try this.

SORT it_stpo BY andat DESCENDING
                      stpoz DESCENDING.

Regards,

Ferry Lianto

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,069

Hello J.J

The explicit version of your SORT statement is:

SORT it_stpo BY andat ASCENDING
                stpoz DESCENDING.

Because ASCENDING is the default sorting direction.

If you want to sort all fields of your itab in descending order your statement must look like:

SORT it_stpo DESCENDING BY andat
                           stpoz.

Regards

Uwe