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: 

Sorting a internal table with different keys

0 Kudos

Hi,

I have a internal table called itab, which has to be sorted with different keys. The priorities of the keys is decided at the runtime.

Consider the below statement where industry, term, amt are fields of the itab:

<b>SORT itab BY industry DESCENDING term DESCENDING amt DESCENDING.</b>

Here the itab is sorted with highest priority as industry, followed by term, followed by amt.

But now the requirement is that this priority might change. I will have three variables deciding the priority. assuming tat p1, p2 and p3 are the priority variables, how can i use these variables to sort this itab at runtime ???

Thanks and Regards,

Ajit

5 REPLIES 5

Former Member
0 Kudos

if priority = 1.

SORT itab BY industry DESCENDING term DESCENDING amt DESCENDING.

elseif priority = 2.

SORT itab BY term DESCENDING amt DESCENDING industry DESCENDING .

else.

SORT itab BY term DESCENDING industry DESCENDING amt DESCENDING .

endif.

like that

regards

shiba dutta

0 Kudos

Hi...

Thanks for replying. There are 8 different possiblities rite ??

Regards,

Ajit

0 Kudos

Hi...

Thanks for replying. There are 8 different possiblities rite ??

Regards,

Ajit

0 Kudos

i dont know what your priority variable is containing and how you want to sort them but you have to do your combination as per your requirement.

regards

shiba dutta

0 Kudos

The priority variable is containing the field name.

Example-

p1 = 'industry'

p2 = 'term'

p3 = 'amt'

so it can contain 8 combinations of values......