Entering content frameProcess documentation Defining a Static Menu Locate the document in its SAP Library structure

Use

In the SAP GUI for Windowsä Environment, you set up menus in the toolbar dynamically using the events toolbar, menu_button and context_menu_request. In the SAP GUI for HTML, you are not recommended to follow this procedure for reasons of performance. Instead, you should define all menus of the toolbar as static as described below (context menus are generally not supported). You define these menus at the event toolbar before the ALV Grid Control is displayed.

Process Flow

  1. Define an event handler method for the event TOOLBAR .
  2. Declare a structure for defining an element in the toolbar, a menu structure and a reference variable to the context menu class:
  3. data: ls_toolbar  TYPE stb_button,
          ls_menu    TYPE stb_btnmnu,
          lc_menu    TYPE REF TO cl_ctmenu.

  4. Define a pushbutton of the menu type in the toolbar first:
  5. CLEAR ls_toolbar.
    ls_toolbar-function  = 'STATIC_MENU1'.
    ls_toolbar-icon      = icon_led_interactive.
    ls_toolbar-butn_type = '2'.
    ls_toolbar-text      = 'first static menu'.

    Note

    You use the field butn_type to communicate the type of the GUI element to the ALV Grid Control. For menus with a default button, you use type ' 1 '.

  6. Use the event parameter E_OBJECT to append the new definition to the table mt_toolbar :
  7. APPEND ls_toolbar TO e_object->mt_toolbar.

  8. Create an instance of the context menu class, and use the method ADD_FUNCTION to add functions to the menu (in this example, only one function is added):
  9. create object lc_menu.
    call method lc_menu->add_function
       exporting fcode  = 'STATIC_MENU1_FUNC1'
       text             = 'first menu entry'.

  10. To link the menu entry with the menu, you fill the menu structure accordingly:
  11. ls_menu-ctmenu = lc_menu.
    ls_menu-function = 'STATIC_MENU1'.

  12. Pass the menu structure to the event parameter E_OBJECT :
  13. append ls_menu to e_object->mt_btnmnu.

  14. Call the static method set_focus for your instance:

call method cl_gui_control=>set_focus
    exporting control = sender.

Result

You can retrieve the function code that you have defined in the field function in the event handler method for the event USER_COMMAND to implement the associated function.

 

 

 

 

 

Leaving content frame