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 text internale table

Former Member
0 Kudos
226

hi guys,

now i have an internal table with a field of 10 character type length, i need to sort by this field descending and its value could be numeric or character.

this is order i want ‘TR’‘10’‘9’, for example,

this the order i got now ‘TR’‘9’‘10’, 'cause by byte compare 9 is greater that 1.

so how to sort this kind of table, is there any FM?

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos
111

Hi Derek,

Can you use a conversion exit before population your internal table like below:

DATA : BEGIN OF tab OCCURS 10,

field TYPE char10,

END OF tab.

CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD '9'

ID 'OUTPUT' FIELD tab-field.

APPEND tab.

CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD 'TR'

ID 'OUTPUT' FIELD tab-field.

APPEND tab.

CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD '10'

ID 'OUTPUT' FIELD tab-field.

APPEND tab.

SORT tab DESCENDING.

LOOP AT tab.

WRITE:/ tab-field.

ENDLOOP.

Regards,

Chester

5 REPLIES 5

Former Member
0 Kudos
111

CATT_SORT_TABLE

use this FM...may it help u

0 Kudos
111

too complicated FM,hehe~~~

Former Member
0 Kudos
112

Hi Derek,

Can you use a conversion exit before population your internal table like below:

DATA : BEGIN OF tab OCCURS 10,

field TYPE char10,

END OF tab.

CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD '9'

ID 'OUTPUT' FIELD tab-field.

APPEND tab.

CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD 'TR'

ID 'OUTPUT' FIELD tab-field.

APPEND tab.

CALL 'CONVERSION_EXIT_ALPHA_INPUT' ID 'INPUT' FIELD '10'

ID 'OUTPUT' FIELD tab-field.

APPEND tab.

SORT tab DESCENDING.

LOOP AT tab.

WRITE:/ tab-field.

ENDLOOP.

Regards,

Chester

0 Kudos
111

Chester Drawers

thanks, gave u the points

as text is not working~~~

varma_narayana
Active Contributor
0 Kudos
111

Hi

Try this..

SORT ITAB BY <FIELD> AS TEXT.

<b>reward if Helpful</b>