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

Sort by char

Former Member
0 Likes
934

Hello,

my first post..

I'am beginner ABAP, so I'am stil learning..

I have a char that it's supose to be a number en be sorted!

data: tmp_line-tdline TYPE tline-tdline,

tmp_line-tdline = 1.079

tmp_line-tdline = 10.400

tmp_line-tdline = 7.028

tmp_line-tdline = 10.700

tmp_line-tdline = 10.800

tmp_line-tdline = 10.700

it_table-tdline = tmp_line-tdline.

enz..

when I sort my it_table by tdline:

I get this in my output:

1.000

10.400

10.700

10.700

10.800

7.028

I should be:

1.000

7.028

10.400

10.700

10.700

10.800

Can someone help me?

Adibo..

Hello,

my first post..

I'am beginner ABAP, so I'am stil learning..

I have a char that it's supose to be a number en be sorted!

data: tmp_line-tdline TYPE tline-tdline,

tmp_line-tdline = 1.079

tmp_line-tdline = 10.400

tmp_line-tdline = 7.028

tmp_line-tdline = 10.700

tmp_line-tdline = 10.800

tmp_line-tdline = 10.700

it_table-tdline = tmp_line-tdline.

enz..

when I sort my it_table by tdline:

I get this in my output:

1.000

10.400

10.700

10.700

10.800

7.028

I should be:

1.000

7.028

10.400

10.700

10.700

10.800

Can someone help me?

Adibo..

7 REPLIES 7
Read only

Former Member
0 Likes
899

If you declare that as a CHAR that is the problem.

If you can declare it as P or F then it should be sorting fine.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

Former Member
0 Likes
899

HI,

MOve the contents into a type p variable and then sort it.

data: tmp_line-tdline1(20) TYPE p decimals 3,

tmp_line-tdline1 = 1.079

tmp_line-tdline1 = 10.400

tmp_line-tdline1 = 7.028

tmp_line-tdline1 = 10.700

tmp_line-tdline1 = 10.800

tmp_line-tdline1 = 10.700

Regards,

ravi

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
899

Then you need to pad the lesser amounts with leading zeros.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
899

data dictionary: tline-tdline is declared as char..

this is some text, something like this: (transaction me59n)

10.345 raised floor YES

or

3 raised floor NO

or

7.647 raised floor YES

or

1.079 raised floor YES

so they want to se only the number en to be sorted by that number..

Read only

Former Member
0 Likes
899
chk out this
 
after sorting again u can remove leading zeroes
 
REPORT  YCHATEST                                .
 
data : begin of itab occurs 0,
           houseno(10),
       end of itab.
 
itab-houseno = '24'.
append itab.
clear itab.
 
itab-houseno = '4'.
append itab.
clear itab.
 
itab-houseno = '454'.
append itab.
clear itab.
 
 
 
loop at itab.
   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
     EXPORTING
       input         = itab-houseno
    IMPORTING
      OUTPUT        = itab-houseno
             .
 modify itab index sy-tabix.
endloop.
 
sort itab by houseno.
 
loop at itab.
   write : / itab-houseno.
endloop.
 
loop at itab.
   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
     EXPORTING
       input         = itab-houseno
    IMPORTING
      OUTPUT        = itab-houseno
             .
 modify itab index sy-tabix.
endloop.
 
loop at itab.
   write : / itab-houseno.
endloop.
Read only

0 Likes
899

Doesn't work, some number have a dot (.)..

Maybe I can split on dot (.)

10.345

should be:

10

.

345

Then i put these number in an it_table and then sort by first col..?

but this doesn work:

it_output-tdline = 10.345

SEARCH '.' FOR it_output-tdline.

IF sy-subrc = 0.

SPLIT line-tdline AT '.' INTO tmp_line-tdline tmp_line-tdline1.

it_output-tdline =tmp_line-tdline

it_output-tddot = '.'

it_output-tdline1 =tmp_line-tdline1

ENDIF.

sy-subrc is always 4 ??

Adibo.

Read only

Former Member
0 Likes
899

solved