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: 

Behavior of ' SORT BY ' in ABAP

Former Member
0 Kudos

Hello All,

The  variable  field0_1, field0_2, field1_1, field1_2 are filled as per required.

An internal Table I_TAB with col1, col2.

SORT I_TAB BY  field0_1 asc field0_2 desc field1_1 asc field1_2 desc .

Case 1:  field0_1 is filled with col1. Rest all other variables are blank.

Behavior: After I_TAB is sorted by col1 , it gets inverted. [ Because of desc ]

How can I stop this behavior.

In actual scenario I have around 10 fields with which I need to sort based on priority,

Kindly give your inputs

Thanks & Regards,

Rohit

4 REPLIES 4

Former Member
0 Kudos

Try SORT ...STABLE keyword addition.

If it doesn't work, please post a more complete snippet so that we can run it at our end and observe the data.

0 Kudos

Hi Manish,

SORT STABLE is used if we have similar values in the sort column.

In my case, I have different values for the sort field.

lets say

use case: user wants to display the data of a table in a particular format.

Input: two things: column name and whether asc or desc.

If asc is selected field1_1 is filled with column name or else field1_2 is filled with column name.

sort sflight by field1_1 asc field1_2 desc.

here if  asc is used. the whole result is inverted, which is not expected.

Let me know if its not clear.

Thanks & Regards,

Rohit

0 Kudos

Could you post a working code sample demonstrating this unexpected behavior?

raymond_giuseppi
Active Contributor
0 Kudos

Can you post the actual code of your SORT statement, here you seems to use dynamic fields for the statement :


SORT I_TAB BY  (field0_1) ASCENDING (field0_2) DESCENDONG ?

Regards,

Raymond