11-27-2007 7:39 AM
hello friends,
i am using the class cl_salv_table to display my ALV. now on my selection screen i have 3 radio buttons,according to the radiobutton selected my output should appear sorted.
which class can help me sort my internal fields according to the radio button on the selection screen and pls tell me how to do this.
11-27-2007 2:40 PM
Hi Amit,
You must use the methods GET_SORTS and ADD_SORT of class CL_SALV_SORTS.
You can get more explanation on <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5dc3e690-0201-0010-1ebf-b85b3bed962d">SAP List Viewer Document</a>.
Here is an example, i hope it useful for you.
REPORT zsalv_sort_mar NO STANDARD PAGE HEADING.
*----------------------------------------------------------------------*
* CLASS lcl_alv DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_alv DEFINITION.
PUBLIC SECTION.
METHODS select_alv IMPORTING amount TYPE i.
METHODS display_alv IMPORTING columnname TYPE lvc_fname.
PROTECTED SECTION.
DATA: o_table TYPE REF TO cl_salv_table,
" We Must create an object of cl_salv_sorts to sort table
o_sorts TYPE REF TO cl_salv_sorts,
o_columns TYPE REF TO cl_salv_columns_table.
DATA t_alv TYPE STANDARD TABLE OF alv_tab.
ENDCLASS. "lcl_alv DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_alv IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_alv IMPLEMENTATION.
METHOD select_alv.
SELECT *
FROM alv_tab
INTO CORRESPONDING FIELDS OF TABLE t_alv
UP TO amount ROWS.
ENDMETHOD. "SELECT_ALV
METHOD display_alv.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_table
CHANGING
t_table = t_alv ).
CATCH cx_salv_msg.
ENDTRY.
o_columns = o_table->get_columns( ).
o_columns->set_optimize( abap_true ).
"Here we're getting all sortable field
o_sorts = o_table->get_sorts( ).
"COLUMNNAME contais 'CARRNAME' that will be used to the sort Table
o_sorts->add_sort( COLUMNNAME ).
o_table->display( ).
ENDMETHOD. "display_alv
ENDCLASS. "lcl_alv IMPLEMENTATION
DATA o_alv TYPE REF TO lcl_alv.
START-OF-SELECTION.
CREATE OBJECT o_alv.
o_alv->select_alv( 30 ).
"Displaye alv Sorting by field 'CARRNAME' that will be passed to
"method add_sort of class cl_salv_sorts
o_alv->display_alv( 'CARRNAME' ).
Regards.
Marcelo Ramos