Skip to Content
0
Former Member
Jan 18, 2008 at 08:22 AM

How can I create dynamic toolbar options in OO ALV Grid

1229 Views

Hi all

I currently have a Private method in an ALV handling class

method ON_TOOLBAR .
type-pools icon.
CLEAR ls_toolbar.
    MOVE 0 TO ls_toolbar-butn_type.
    MOVE 'EXIT' TO ls_toolbar-function.
    MOVE space TO ls_toolbar-disabled.
    MOVE icon_system_end TO ls_toolbar-icon.
    MOVE 'Click2Exit' TO ls_toolbar-quickinfo.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
    MOVE 'SAVE' TO ls_toolbar-function.
    MOVE space TO ls_toolbar-disabled.
    MOVE  icon_system_save TO ls_toolbar-icon.
    MOVE 'Save data' TO ls_toolbar-quickinfo.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
    MOVE 'SWITCH' TO ls_toolbar-function.
    MOVE  space TO ls_toolbar-disabled.
    MOVE  icon_toggle_display_change TO ls_toolbar-icon.
    MOVE 'Switch processing mode' TO ls_toolbar-quickinfo.
    MOVE  'SWITCH' TO ls_toolbar-text.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
    MOVE 'PROC' TO ls_toolbar-function.
    MOVE  space TO ls_toolbar-disabled.
    MOVE   icon_businav_process TO ls_toolbar-icon.
    MOVE 'Process.' TO ls_toolbar-quickinfo.
    MOVE  'PROC' TO ls_toolbar-text.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
    MOVE 'EXCEL' TO ls_toolbar-function.
    MOVE  space TO ls_toolbar-disabled.
    MOVE  icon_xxl TO ls_toolbar-icon.
    MOVE 'Excel' TO ls_toolbar-quickinfo.
    MOVE  'EXCEL' TO ls_toolbar-text.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
    MOVE 'REFR' TO ls_toolbar-function.
    MOVE  space TO ls_toolbar-disabled.
    MOVE  icon_refresh TO ls_toolbar-icon.
    MOVE  'Refresh' TO ls_toolbar-quickinfo.
    MOVE  'REFR' TO ls_toolbar-text.
    APPEND ls_toolbar TO e_object->mt_toolbar.
    MOVE 0 TO ls_toolbar-butn_type.
    MOVE 'TEST' TO ls_toolbar-function.
    MOVE space TO ls_toolbar-disabled.
    MOVE icon_execute_object TO ls_toolbar-icon.
     MOVE 'Get Cell' TO ls_toolbar-quickinfo.
     MOVE  'CELL' TO ls_toolbar-text.

    APPEND ls_toolbar TO e_object->mt_toolbar.
    CLEAR ls_toolbar.


* ...
endmethod.

What i'd really like to do is implement the toolbar buttons dynamically-The calling ABAP could pass some optional parameters or a table specifying what to enable and what to disable. If nothing is passed then the GRID default toolbar buttons would be used.

I'd like to keep the ON TOOLBAR method in the private section so perhaps I'd pass the table to a public method.

The problem I have us that I've already set the event handlers in the CONSTRUCTOR so I'm not sure if I can then alter the toolbar after the instantiation of the alv grid class

Here's my constructor


method CONSTRUCTOR .
CREATE OBJECT grid_container1
        EXPORTING
           container_name = 'CCONTAINER1'.
    CREATE OBJECT  grid1
       EXPORTING
          i_parent = grid_container1.
    SET HANDLER z_object->on_user_command FOR grid1.
    SET HANDLER z_object->on_toolbar FOR grid1.
    SET HANDLER z_object->handle_data_changed FOR grid1.
    SET HANDLER z_object->handle_data_changed_finished FOR grid1.
    SET HANDLER z_object->on_dubbelklik FOR grid1.
    CALL METHOD grid1->register_edit_event
        EXPORTING
           i_event_id = cl_gui_alv_grid=>mc_evt_enter.
  ENDMETHOD.

The z_object refers to my class.

Any suggestions would be really helpful.

Thanks

jimbo