cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting by Multiple attributes

Former Member
0 Kudos

Hello

I would like to sort a BSP Collection first by one attribute and then by another. The first sorting should not be lost. Does anyone know a way to do this?

Regards,

Sowmiya

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello

This does not work. The earlier sort order is lost.

Regards,

Sowmiya

arne_husemann
Explorer
0 Kudos

Hello,

in my testcase the first sorting criterion is preserved. The setted stable flag should guarantee that two entities ordered A,B before sorting are still ordered A,B if they are equal in terms of the applied criterion.

This directly effects the order in which sorting criteria should be applied. The sorting should start with the weakest criterion ending with the strongest.

Regards, Arne

arunprakash_karuppanan
Active Contributor
0 Kudos

Hi,

You can try doing this in a round-about way. Make note of the structure used by your collection. I'm using 'CRMST_ADMINH_BTIL' for example.


Data: lt_init_tab type standard table of crmst_adminh_btil,
         lt_sort_tab type standard table of crmst_adminh_btil,
         ls_adminh type crmst_adminh_btil,
         lr_bo type ref to if_bol_bo_property_access.

*lr_col - initial
*lr_sorted_col - final sorted col

lr_bo = lr_col->get_first( ).
while lr_bo is bound.
lr_bo->get_properties( importing es_attributes = ls_adminh ).
append ls_adminh to lt_init_tab.
lr_bo = lr_col->get_next( ).
endwhile.

lt_sort_tab[] =  lt_init_tab[].
sort lt_sort_tab stable by object_id descending created_by descending.

loop at lt_sort_tab into ls_adminh.
read table lt_init_tab with key guid = ls_adminh-guid.
if sy-subrc eq 0.
lr_bo = lr_col->find( iv_index = sy-tabix ).
lr_sorted_col->add( iv_bo = lr_bo ).
endif.
endloop.

Regards,

Arun Prakash

Answers (1)

Answers (1)

Former Member
0 Kudos

Sowmiya,

You have an importing parameter IV_STABLE in the class METHOD IF_BOL_BO_COL~SORT. Sort first using attribute 1 and later sort on second attribute marking the parameter IV_STABLE.

Regards,

Masood Imrani S.