Skip to Content
author's profile photo Former Member
Former Member

toolbar of class cl_gui toolbar

I have created a toolbar of class cl_gui_toolbar. But the question is that I don't know how to handle with this toolbar, shall I have to create an event to handle the function of the buttons? Do someone has an idea?

CREATE OBJECT mytoolbar
    EXPORTING
      parent       = container_1_2
      display_mode = cl_gui_toolbar=>m_mode_vertical.

  CLEAR buttongroup.

  PERFORM fill_data_table
    USING:
    'FC2' '@2N@' cntb_btype_button  text-006    text-006,
    'FC3' '@12@' cntb_btype_button  text-007    text-007,
    'FC4' '@2L@' cntb_btype_button  text-008    text-008.

  CALL METHOD mytoolbar->add_button_group
    EXPORTING
      data_table = buttongroup.

FORM fill_data_table
         USING
               fcode  TYPE ui_func
               icon   TYPE iconname
               type   TYPE tb_btype
               text   TYPE text40
               tip    TYPE iconquick.

  CALL METHOD mytoolbar->fill_buttons_data_table
    EXPORTING
      fcode        = fcode
      icon          = icon
      butn_type  = type
      text           = text
      quickinfo    = tip
    CHANGING
      data_table  = buttongroup.

ENDFORM.                    " FILL_DATA_TABLE

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 18, 2008 at 11:11 AM

    refer below programs

    BCALV_GRID_05 Add a Self-Defined Button to the Toolbar

    BCALV_GRID_07 Define a Menu in the Toolbar

    BCALV_TEST_FUNCTIONS Program BCALV_TEST_FUNCTIONS: Hide Toolbar

    BCALV_TEST_GRID_TOOLBAR Program BCALV_TEST_TOOLBAR

    BCALV_TEST_NEUE_FUNCTION Report BCALV_TEST_NEUE_FUNCTION: Insert Ico

    BCALV_TEST_TOOLBAR Program BCALV_TEST_TOOLBAR

    BCALV_TEST_USER_COMMANDS Report BCALV_TEST_NEUE_TOOLBAR

    BCALV_TOOLBAR_EVENT_RECEIVER Include BCALV_TOOLBAR_EVENT_RECEIVER

    BCALV_TOOLBAR_EVENT_RECEIVER01

    BCALV_TREE_04 ALV Tree Control: Add a Button to the Toolb

    BCALV_TREE_05 ALV Tree Control: Add a Menu to the Toolbar

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello

      You have forgotten to register the events you want to handle.

      For a sample report have a look at SAPTOOLBAR_DEMO1. The crucial parts of the coding are shown below:

      ...
      *-----------------------------------------------------------------------
      * module status_0100.
      *-----------------------------------------------------------------------
      MODULE status_0100 OUTPUT.
        SET PF-STATUS 'TOOLBAR'.
        SET TITLEBAR '001'.
        IF b_init IS INITIAL.
      
          edfcode = 'test'.                                       "#EC NOTEXT
          edicon  = '@01@'.                                       "#EC NOTEXT
          edtip   = text-004.
          edtext  = 'Test'.                                       "#EC NOTEXT
          edtype = cntb_btype_dropdown.
          cbenabled = 'X'.
          cbvisible = 'X'.
          rdhorz = 'X'.
      
          " Define events you want to handle
          myevent-eventid = cl_gui_toolbar=>m_id_function_selected.
          myevent-appl_event = 'X'.
          APPEND myevent TO myevent_tab.
          myevent-eventid = cl_gui_toolbar=>m_id_dropdown_clicked.
          APPEND myevent TO myevent_tab.  
      
          CREATE OBJECT evt_receiver.
      
          PERFORM create_horz_toolbar.
          mytoolbar = mytoolbar_h.
      
          b_init = 'X'.
        ENDIF.
      ENDMODULE.                    "status_0100 OUTPUT
      ...
      
      ...
      *   create a toolbar with horizonzal display mode
      FORM create_horz_toolbar.
        CREATE OBJECT mycontainer_h
           EXPORTING
             container_name = 'CONTAINER'.                        "#EC NOTEXT
      
        CREATE OBJECT mytoolbar_h
           EXPORTING
             parent = mycontainer_h.
      
        " Register events...
        CALL METHOD mytoolbar_h->set_registered_events
          EXPORTING
            events = myevent_tab.
      
        " ...and set event handler
        SET HANDLER evt_receiver->on_function_selected
                    FOR mytoolbar_h.
        SET HANDLER evt_receiver->on_dropdown_clicked
                    FOR mytoolbar_h.
      ENDFORM.                    "create_horz_toolbar
      ...
      

      Regards

      Uwe

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 02:49 AM

    Hi,

    This is working at my end, I have placed a button on toolbar & fired some task on button click.

    I hope this will solve your purpose.

     CLASS lcl_events_d0100 DEFINITION DEFERRED.
     DATA: event_receiver1  TYPE REF TO lcl_events_d0100.
    
    CLASS lcl_events_d0100 DEFINITION.
      PUBLIC SECTION.
    *--for placing buttons
        METHODS handle_toolbar_set
            FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING
                  e_object
                  e_interactive.
    
    *---user command on clicking a button
        METHODS handle_user_command
            FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING
                 e_ucomm.
    ENDCLASS.                    "lcl_events_d0100 DEFINITION
    
    *--Declaration for toolbar buttons
    DATA : ty_toolbar      TYPE stb_button.
    DATA : e_object        TYPE REF TO cl_alv_event_toolbar_set,
           io_alv_toolbar  TYPE REF TO cl_alv_event_toolbar_set.
    
    
    CLASS lcl_events_d0100 IMPLEMENTATION.
    
    **---method for handling toolbar
      METHOD handle_toolbar_set.
        CLEAR ty_toolbar.
        ty_toolbar-function = 'EDIT'. "name of btn to  catch click
        ty_toolbar-butn_type = 0.
        ty_toolbar-text = 'EDIT'.
        APPEND ty_toolbar    TO e_object->mt_toolbar.
      ENDMETHOD.                    "handle_toolbar_set
    
      METHOD handle_user_command.
        
        CASE e_ucomm.
          WHEN 'EDIT'.
    
          perform save_database.
          
        ENDCASE.
    
      ENDMETHOD.                    "handle_user_command
    
    ENDCLASS.                    "lcl_events_d0100 IMPLEMENTATION
    
      DATA ref_grid TYPE REF TO cl_gui_alv_grid.
      SET HANDLER event_receiver1->handle_toolbar_set   FOR ref_grid.
      SET HANDLER event_receiver1->handle_user_command  FOR ref_grid.
    
    
    
    

    Thanks & Regards,

    Krishna..

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.