Search code examples
abapdynpro

Create button with dropdown menu in application toolbar of custom screen


I'm trying to create a button in the application toolbar which when clicked displays a drop down menu. This is a custom screen with no ALV grid though so I can't use the ALV class methods. I create the button and fcode in my GUI status and set it when I call my custom screen but I can't find any way to turn it into a drop down menu. Is there any other way I can do it?

I thought I might be able to use the cl_gui_toolbar methods add_button and set_static_ctxmenu but I'm not sure how I'd get a reference to my running toolbar instance?

My code so far:

*----------------------------------------------------------------------*
*&     Form     f_handle_menu_button
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM f_handle_menu_button.

DATA: go_toolbar TYPE REF TO cl_gui_toolbar,
    go_menu    TYPE REF TO cl_ctmenu.


CALL METHOD go_toolbar->add_button
EXPORTING
  fcode       = '&APPLY'
  icon        = ''
  is_disabled = ''
  butn_type   = 1 "Pushbutton with Menu
  text        = 'Apply Status'.

CREATE OBJECT go_menu.

CALL METHOD go_menu->add_function
  EXPORTING
   fcode       = '&STATUS1'
   text        = 'Status1'
   icon        = ' '
   disabled    = ' '
   checked     = ' '
   hidden      = ' '.

CALL METHOD go_menu->add_function
  EXPORTING
   fcode       = '&STATUS2'
   text        = 'Status2'
   icon        = ' '
   disabled    = ' '
   checked     = ' '
   hidden      = ' '.

CALL METHOD go_toolbar->set_static_ctxmenu
  EXPORTING
   fcode   = '&APPLY'
   ctxmenu = go_menu. 

ENDFORM.      "F_HANDLE_MENU_BUTTON

Solution

  • Triggering a modal dialog from the application toolbar is simpler to implement and fits established UI patterns, such as selecting an ALV layout or selecting a financial, material, or purchasing document in those respective modules. And as you can see from the code, the signature of add_function is hardcoded to accept icons and text only.

    As much as I would like to see this happen, I recommend using a modal dialog instead of a drop-down menu.