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 internal table by text

Former Member
0 Likes
891

in my inetrnal table there is a field bwart(valuation type) in that there is four types

1)bought_out

2)inhouse 3)inter.plt 4)subcount

i want to sort like this -

1)inhouse

2)bought_out

3)inter.plt

4)subcount

please help....

1 ACCEPTED SOLUTION
Read only

ArthurParisius
Contributor
806

Another option is to add an extra field to your internal table that you fill according to the bwart field and use that to sort instead.

3 REPLIES 3
Read only

SimoneMilesi
Active Contributor
806

You have to develop your own logic to obtain it, since there is not built-in function you can use: sorting works alphanumeric.

A rough approach

set_sort( USING it_origin = your_internal_table
i_value   = 'inhouse'
  changing out_tab = final_table ).

set_sort( USING it_origin = your_internal_table
i_value   = 'bought_out'
  changing out_tab = final_table ).
set_sort( USING it_origin = your_internal_table
i_value   = 'inter.plt'
  changing out_tab = final_table ).
set_sort( USING it_origin = your_internal_table
i_value   = 'subcount'
  changing out_tab = final_table ). 
your_internal_table = final_table. "you can avoid it if you use final_Table
.....
.....

METHOD set_sort.
LOOP AT it_origin INTO DATA(orign) WHERE bwart = i_value.
APPEND origin TO out_tab.
ENDLOOP.
ENDMETHOD.
Read only

ArthurParisius
Contributor
807

Another option is to add an extra field to your internal table that you fill according to the bwart field and use that to sort instead.

Read only

matt
Active Contributor
0 Likes
806

Arthur's is the easiest, but if you're a dedicated masochist, you could just implement the QuickSort algorithm - widely available on the internet.