shrgrl
shrgrl

Reputation: 87

How do I sort the column from large to small numerically?

I get a variable number of data from the user with the parameter. I want to sort (descending ascending) them among themselves. I tried using order by, but I don't know how to solve it.

My data is separated as follows:

SPLIT sayilar AT '-' INTO TABLE it_char.

I tried these. I guess I can't find what I want. Below is the block of code I tried to sort. I'm doing something wrong, but I don't know what happened.

SORT it_char DESCENDING.
LOOP AT it_char INTO wa_char.
  WRITE :/ wa_char.
ENDLOOP.

skip 2.

SORT it_char ASCENDING.
LOOP AT it_char INTO wa_char.
  WRITE :/ wa_char.
ENDLOOP.

I set the variable type to c but it doesn't work correctly in double digit numbers.

my parameters screen:

my parameters screen

my report screen:

my report screen

Upvotes: 0

Views: 2992

Answers (1)

Philipp
Philipp

Reputation: 69703

In order to sort an internal table, use the SORT keyword.

To sort a table of strings or type C alphabetically, use:

SORT it_char ASCENDING AS TEXT.

When the line type of the table is numerical and you want to sort from large to small:

SORT it_char DESCENDING.

More information can also be found in this help article.

Upvotes: 2

Related Questions