Showing context/popup menu under the mouse cursor

Problem: you want to show a popup menu under mouse cursor.

Solution: there are special functions for this functionality.

First, you need to create the menu that you will show in a moment. For this use function RSAH_CREATE_MENU. After creating menu you need to show it. For this there is function called RSAH_DISPLAY_POPUP_MENU.Below is an example code for this operation.

DATA:
  lv_selected_id TYPE i,
  lv_menu_handle TYPE cntl_handle,
  ls_menu_item TYPE rsahmenu,
  lt_menu_items TYPE TABLE OF rsahmenu.
 
CALL FUNCTION 'RSAH_CREATE_MENU'
  EXPORTING
    owner_repid = sy-repid
    dynnr       = sy-dynnr
  CHANGING
    mn_handle   = lv_menu_handle.
 
ls_menu_item-pfid = 1.
ls_menu_item-text = 'This is a popup menu option'.
ls_menu_item-enabled = abap_true.
ls_menu_item-ucomm = 'MENU_OPTION'.
APPEND ls_menu_item TO lt_menu_items.
 
CALL FUNCTION 'RSAH_DISPLAY_POPUP_MENU'
  EXPORTING
    mn_handle   = lv_menu_handle
  IMPORTING
    selected_id = lv_selected_id
  TABLES
    menutable   = lt_menu_items
  EXCEPTIONS
    failed      = 1
    OTHERS      = 2.
IF sy-subrc  0.
* Implement suitable error handling here
ENDIF.
DATA:
  lv_selected_id TYPE i,
  lv_menu_handle TYPE cntl_handle,
  ls_menu_item TYPE rsahmenu,
  lt_menu_items TYPE TABLE OF rsahmenu.

CALL FUNCTION 'RSAH_CREATE_MENU'
  EXPORTING
    owner_repid = sy-repid
    dynnr       = sy-dynnr
  CHANGING
    mn_handle   = lv_menu_handle.

ls_menu_item-pfid = 1.
ls_menu_item-text = 'This is a popup menu option'.
ls_menu_item-enabled = abap_true.
ls_menu_item-ucomm = 'MENU_OPTION'.
APPEND ls_menu_item TO lt_menu_items.

CALL FUNCTION 'RSAH_DISPLAY_POPUP_MENU'
  EXPORTING
    mn_handle   = lv_menu_handle
  IMPORTING
    selected_id = lv_selected_id
  TABLES
    menutable   = lt_menu_items
  EXCEPTIONS
    failed      = 1
    OTHERS      = 2.
IF sy-subrc  0.
* Implement suitable error handling here
ENDIF.

Komentowanie jest zakończone.