cancel
Showing results for 
Search instead for 
Did you mean: 

sort result set with multiple fields

Former Member
0 Kudos

Hi, Can we sort a result set(table view) with multiple fields at a time.

In General we use a sort statement as:

Sort TTT table by f1 f2 f3.

but, in this table view i'm trying to sort a collection.

me->typed_context->resultnode->collection_wrapper->SORT( iv_attr_name = 'GROWER_NAME' ).

with the above sort, the result set is sorted w.r.t to one field.

Can we sort the collection with multiple fieds at a time.

I tried this, but coudnot get.

Pls provide some pointers on this.

Accepted Solutions (0)

Answers (2)

Answers (2)

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

Check this option.

1. Using 'get_propertiesu2019, get required fields information and store it into an internal table. Once all the entities data is stored to internal table, sort the internal table based on required sort order (sort order based on multiple fields). Now the internal table having the data in required sort order.

2. Store the 'collection_wrapper' data into temporary collection and clear the existing data , now loop through the internal table and read the collection using 'IF_BOL_BO_COLFIND' Method , find the object and add it to the collection using 'if_bol_bo_coladd'.

3. Now the data collection will be in required sort order.

Thanks

L Appana

former_member189678
Active Contributor
0 Kudos

I doubt whether the sort method offers such fucntionality.

You can try sth like this as a workaround, though it may not sound wise.

me->typed_context->resultnode->collection_wrapper->SORT( iv_attr_name = ATTR1 ).

Now the collection wrapper is sorted on ATTR1, use the sort method again though this time pass different attribute name.

Rg,

Harshit Kumar

Former Member
0 Kudos

Hi Harshit,

I have tried that method, but it sorts by the new field and the previous sort order is no more retained.

So, its coming to as a new sort order by the second field.

Former Member
0 Kudos

Hi,

it is possible to sort a result table based on multiple fields: To do so, an instance of IF_BOL_COL_SORTING can be provided by the caller of the SORT method. During the sort process the method IS_A_GREATER_B of the instance is called

whenever two values are compared. Implement this method and provide the interface to influence the sort order as needed.

Kind regards,

Carl

Former Member
0 Kudos

Hi Carl,

I'm not able to properly replicate what you have suggested.

Can you pls put in a sample code, so that i can try out.

Former Member
0 Kudos

Hi,

unfortunately I don't have any sample code I can provide you with. Try searching on this Interface and method if you can find any code implementations.

Kind regards,

Carl

arunprakash_karuppanan
Active Contributor
0 Kudos

Srikanth,

You need to sort it twice with the iv_stable parameter set to true, the second time. The behaviour is the same as normal ABAP sort statement with the "stable" addition.


sort itab by field1 field2

is the same as

sort itab by field2.
sort itab stable by field1.

Apply the same logic when you call the if_bol_bo_col~sort method.

Regards,

Arun Prakash