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: 

toolbar of class cl_gui toolbar

Former Member
0 Kudos
1,749

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
200

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

5 REPLIES 5

Former Member
0 Kudos
201

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

0 Kudos
200

Hello,

thank you for your answer, I dont mean the tool buttons which I can insert to the alv grid, this is a toolbar like in the example report SAPTOOLBAR_IN_SPLITTER , or like in the se80 the top of the left side where you can switsch for example between the transport organizer and the test repository.

I only want to know how to handle with the functions, as I don't call them directly in the PAI.

0 Kudos
200

Now I have this one but still without result:

Datadefinition:


DATA mytoolbar TYPE REF TO cl_gui_toolbar.
DATA buttongroup TYPE ttb_button.


*----------------------------------------------------------------------*
*       CLASS lcl_toolbar_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_toolbar_event_receiver DEFINITION.

  PUBLIC SECTION.
    METHODS: on_function_selected
               FOR EVENT function_selected OF cl_gui_toolbar
                 IMPORTING fcode.
ENDCLASS.                    "lcl_toolbar_event_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_toolbar_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_toolbar_event_receiver IMPLEMENTATION.

  METHOD on_function_selected.

    CASE fcode.

      WHEN 'FC1'.
        break-point.

    ENDCASE.

  ENDMETHOD.                    "on_function_selected

ENDCLASS.                    "lcl_toolbar_event_receiver IMPLEMENTATION

In PBO:


DATA: toolbar_event_receiver TYPE REF TO lcl_toolbar_event_receiver.

  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.

* set event-handler for toolbar-control
  CREATE OBJECT toolbar_event_receiver.
  SET HANDLER toolbar_event_receiver->on_function_selected for mytoolbar.


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

What do I have forget? It still don't work.........

0 Kudos
200

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

Former Member
0 Kudos
200

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