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: 

How to sort an Internal table Based on a One Char Trans type in the rec?

Former Member
0 Kudos

Meaning, ascending descending will not work, lets say itab_A has the order O-H-W-G-I-A, and I want it to write it to itab_B to the correct order, G-H-O-I-A-W.

I know I can do loop at itab_A where for each one and write it, but is their a better way?

Thank-You

1 ACCEPTED SOLUTION

former_member156446
Active Contributor
0 Kudos

if you know the correct order play with index in the itab_A and append to itab_B


loop at itab_A index X.
blah.. blah..
endloop.

or


itab_temp [] =  itab_A[].
delete itab_temp where index <> 'X'.
append itab_temp to itab_B.
refresh itab_temp[].

itab_temp [] =  itab_A[].
delete itab_temp where index <> 'Y'.
append lines of  itab_temp to itab_B.
refresh itab_temp[].

4 REPLIES 4

rainer_hbenthal
Active Contributor
0 Kudos

From what is the "correct" sort order derived?

Former Member
0 Kudos

You could add a separate field to the internal table and fill it with the sort order according to your requirements and sort on that.

Rob

former_member156446
Active Contributor
0 Kudos

if you know the correct order play with index in the itab_A and append to itab_B


loop at itab_A index X.
blah.. blah..
endloop.

or


itab_temp [] =  itab_A[].
delete itab_temp where index <> 'X'.
append itab_temp to itab_B.
refresh itab_temp[].

itab_temp [] =  itab_A[].
delete itab_temp where index <> 'Y'.
append lines of  itab_temp to itab_B.
refresh itab_temp[].

Former Member
0 Kudos

The SET LOCALE command can affect sort order if it's language related but I don't think that's the case here.

You could use loops and translate.

Loop at itab_A.

translate itab_A-field using 'OGHHWOGIIAAW'.

Endloop.

sort itab_A.

Loop at itab_A.

translate itab_A-field using 'GOHHOWIGAIWA'.

Endloop.

itab_b[] = itab_a[].