cancel
Showing results for 
Search instead for 
Did you mean: 

Grouping a column on display in ALV

Former Member
0 Kudos

Hi All,

Could some one help me on how to group similar values in an alv column when it is displayed for the first time itself, i know we can set/reset this functionality on sort by using the ~set_grouping_allowed method of the interface if_salv_wd_sort but i would like to group on first display itself.

I Apologise if the question was already posted.

Thanks In Advance,

Chaitanya.

Accepted Solutions (1)

Accepted Solutions (1)

arjun_thakur
Active Contributor
0 Kudos

Hi Chaitanya,

Please refer the following code:


 DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.
  l_ref_cmp_usage =   wd_this->wd_cpuse_alv_first( ). " alv_first is the name of my alv component
  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.

 DATA l_salv_wd_table TYPE REF TO iwci_salv_wd_table.
  l_salv_wd_table = wd_this->wd_cpifc_alv_first( ).
  DATA: lr_field TYPE REF TO cl_salv_wd_field.
  DATA lo_config_model TYPE REF TO cl_salv_wd_config_table.
  lo_config_model = l_salv_wd_table->get_model( ).

  lo_config_model->if_salv_wd_table_settings~set_multi_column_sort( value = abap_true ).

  lr_field = lo_config_model->if_salv_wd_field_settings~get_field( 'CONNID' ).
  lr_field->if_salv_wd_sort~create_sort_rule( sort_order = if_salv_wd_c_sort=>sort_order_descending ).

  lr_field->if_salv_wd_sort~set_grouping_allowed( value = abap_true ).

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

Hi Arjun,

Thanks a lot for your quick reply, your code works fine the only problem is say i am trying to group data in the column 'matnr' because i am using the statement:

l_if_field->if_salv_wd_sort~create_sort_rule( sort_order = if_salv_wd_c_sort=>sort_order_descending )

the display order of the matnr's gets changed , is there a way i can retain the order given to me by the function module and still have the column sorted.

Thanks A Lot,

Chaitanya.

arjun_thakur
Active Contributor
0 Kudos

Hi Chaitanya,

For grouping to happen, we have to sort the column and for that we have to create the sort rule. Even if we don't pass the sort _order in the code, the column will get sorted in ascending order by default.

Regards

Arjun

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

By using the below class properties you can do what ever action you require.

cl_salv_table

http://help.sap.com/saphelp_nw04/helpdata/en/10/e4eb40c4f8712ae10000000a155106/content.htm

Best Regards

Ravi