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.
cancel
Showing results for 
Search instead for 
Did you mean: 

Reg : GET_SELECTED_COLUMNS

Former Member
0 Kudos

Friends,

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 display.here 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,

Venkat.

2 REPLIES 2

former_member194669
Active Contributor
0 Kudos

Hi,

Please find a link.

please look into Rich's reply,

aRs

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.

endclass.

***********************************************************************

  • CLASS lCL_EVENT_RECEIVER IMPLEMENTATION

***********************************************************************

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

importing

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 ).

endmethod.

endclass.

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

changing

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.