Skip to Content
0
Former Member
Nov 25, 2009 at 07:42 PM

Problem is Sorting Numeric with Decimals

114 Views

Hi leads,

I am getting problem in sorting when I sort on numeric values with decimals.

Here I am giving my code.

TYPES : BEGIN OF ty_sort,
         val1 TYPE char10,
         val2 TYPE char10,
        END OF ty_sort.

DATA : it  TYPE STANDARD TABLE OF ty_sort,
       it2 TYPE STANDARD TABLE OF ty_sort,
       wa TYPE ty_sort.

wa-val1 = '0.05'.
wa-val2 =  '0.00'.
APPEND wa TO it.
CLEAR wa.

wa-val1 = '0.03'.
wa-val2 =  '0.02'.
APPEND wa TO it.
CLEAR wa.

wa-val1 = '0.00'.
wa-val2 =  '0.06'.
APPEND wa TO it.
CLEAR wa.

SORT it BY val1 DESCENDING val2 DESCENDING.

LOOP AT it2 INTO wa.
  WRITE : / wa-val1,  20 wa-val2.
  CLEAR wa.
ENDLOOP.

O/P : ( I am getting this output, which is not expected )

0.05 0.00

0.03 0.02

0.00 0.06

Expected O/P :

0.05 0.06

0.03 0.02

0.00 0.00

Thanks,

Sandeep

Moderator message - Please use code tags around your code

Edited by: Rob Burbank on Nov 25, 2009 3:17 PM