Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
Showing results for 
Search instead for 
Did you mean: 


Former Member
0 Kudos


I have requirement where the user can select columns on ALV-display and then clicks a custom button,now i need to capture which columns were selected by the user and using this info i display another ALV in another screen.Till here its fine.

(I am capturing the columns user using method "GET_SELECTED_COLUMNS".)

But now when i am hitting back button on the 2nd ALV display screen and going back to initial when i selecet some other combination of columns...and hit the custom button..this time the method is not giving the selected colums.The method is failing the second time.I have to litreally run the whole program again from the TCODE for it to strt working again.

I need help this is urgent.

Thanks and Regards,



Active Contributor
0 Kudos


Please find a link.

please look into Rich's reply,


Former Member
0 Kudos

u try this

First thing is that you need a local class as your event handler, copy and paste this code. Here we are using the name ALV_GRID for your alv object

data: alv_grid type ref to cl_gui_alv_grid.


  • CLASS lcl_event_receiver DEFINITION


class lcl_event_receiver definition.

public section.

methods handle_user_command

for event before_user_command of cl_gui_alv_grid

importing e_ucomm.

private section.





class lcl_event_receiver implementation.

method handle_user_command.

data: icols type lvc_t_col,

xcols like line of icols.

  • Get the currently selected column

call method alv_grid->get_selected_columns


et_index_columns = icols.

read table icols into xcols index 1.

  • If the selected column is not one that should be sorted

check xcols-fieldname = 'MATNR'. "<-- Whatever columns that you don't want to allow sorting on.

  • Now check the function code, if sort ascending or descending, then give message

check e_ucomm = cl_gui_alv_grid=>mc_fc_sort_asc

or e_ucomm = cl_gui_alv_grid=>mc_fc_sort_dsc.

message i001(00) with 'Can not sort on this column'.

  • Now set the UCOMM as if the user didn't click anything.

call method alv_grid->set_user_command( space ).



data: event_receiver type ref to lcl_event_receiver.

Also, you will need to set the event hanlder after calling the SET_TABLE_FOR_FIRST_DISPLAY.

call method alv_grid->set_table_for_first_display


it_outtab = i_alv[]

it_fieldcatalog = ifc[].

  • Set the handler for ALV grid

create object event_receiver.

set handler event_receiver->handle_user_command for alv_grid.