0

I am making a report by using cl_salv_table, and I want to make a button on toolbar of the ALV grid which will show a predefined popup.

I was able to make a button on the toolbar and set the "Functional code" as details, and I saw in the debug mode that on clicking the button the "sy-ucomm" is set to details but it is not going the case loop.

Any help or suggestion would be appreciated.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Ankit Chaurasia
  • 163
  • 2
  • 5
  • 14

2 Answers2

1

Please look at the program SALV_DEMO_TABLE_SELECTIONS how to implement event handlers correctly, basically method on_user_command in the class lcl_handle_events is what your looking for.

1

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.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90