cancel
Showing results for 
Search instead for 
Did you mean: 

sort alv column

Former Member
0 Kudos

I have an alv table.

This is sorted ascending by the first column called "first" . I want to sort it descending by first colum.

How can I do that?

Thanks for help!!

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Ezachiael,

You need to use the create_sort_rule method of if_salv_wd_sort for achieving this sorting functionality. Refer to the code snippet below which am using inside the WDDOINIT method to sort the SEATSOCC field by descending order.

Regards,

Uday

METHOD wddoinit .
* Create component usage for alv component
  DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.

  l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.

* Get config model
  DATA: l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table .
  l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).

  DATA: l_value TYPE REF TO cl_salv_wd_config_table.

  l_value = l_ref_interfacecontroller->get_model( ).

* set visible row count
  l_value->if_salv_wd_table_settings~set_visible_row_count( '5' ).

* Sort rows by seatsocc descending
  DATA: lr_field  TYPE REF TO cl_salv_wd_field.

  lr_field = l_value->if_salv_wd_field_settings~get_field( 'SEATSOCC' ).
  lr_field->if_salv_wd_sort~create_sort_rule( sort_order =
  if_salv_wd_c_sort=>sort_order_descending ).
ENDMETHOD.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi check out this link

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/63a47dd9-0b01-0010-3d8e-de27242b...

go to pg no 233 u'll find sorting methods

thanks and regards

Reeha

arjun_thakur
Active Contributor
0 Kudos