First of all you should have SALV grid on a screen with container:
try.
cl_salv_table=>factory(
exporting
r_container = gr_container
container_name = 'CONTAINER'
importing
r_salv_table = gr_table
changing
t_table = gt_outtab ).
catch cx_salv_msg. "#EC NO_HANDLER
endtry.
Then all functions should be enabled:
lr_functions = gr_table->get_functions( ).
lr_functions->set_all( gc_true ).
Finally you add own function like this:
include <icon>.
try.
lr_functions->add_function(
name = 'MYFUNCTION'
icon = CONV string( icon_complete )
text = `My function`
tooltip = `My custom function`
position = if_salv_c_function_position=>right_of_salv_functions ).
catch cx_salv_existing cx_salv_wrong_call.
endtry.
The next significant step is to create on_user_command
event handler either in the same class or in separate handler class:
data: gr_events type ref to lcl_handle_events.
set handler gr_events->on_user_command for lr_events.
The final thing is the handler method implementation which will do actual function work
class lcl_handle_events implementation.
method on_user_command.
message |Function { e_salv_function } is fired| TYPE 'I'.
endmethod.
endclass.