Mentor SAP

Context Menus

You can use a context menu to provide functions to the users that depend on the respective program context. Use context menus if you need to assign these functions to the control (or even part of it) and not to the entire screen.

 

 

Context Menus – Process Flow

A context menu is displayed if a user presses the right mouse button (or Shift + F10) and the mouse pointer is positioned over a GUI control. When a user presses the right mouse button, the ALV grid control triggers the CONTEXT_MENU_REQUEST event. The mouse pointer that is the corresponding control that triggers the alert determines the context.

 

If the user selects a function from the context menu, the ALV grid control triggers the USER_COMMAND event. By default, the ALV grid control has a context menu that you can replace or extend.

 

 

CONTEXT_MENU_REQUEST Event

When a user presses the right mouse button, the control over which the mouse pointer is positioned triggers the CONTEXT_MENU_REQUEST event. To display a specific context menu, implement a handler method for the event and register this handler method at the application server (SET HANDLER ... FOR go_alv_grid).

 

 

Static Context Menu

The easiest way to create a context menu is to load a GUI status of type context menu. You can create a context menu in the object list of the Object Navigator. Use the context menu of the Object Navigator to create a new GUI status with type context menu and enter the required function codes and their texts in the Menu Painter. You create a submenu by entering text but no code for a line in the Menu Painter. A small triangle on the right indicates that there is a submenu. You can create a maximum of three levels.

 

 

Loading and Extending of a Context Menu

To load the GUI status into the context menu, use the static method load_gui_status of class cl_ctmenu.

 

The parameters are assigned the following values:

 

You can extend the context menu that you loaded, using the add_function method of the cl_ctmenu class.

 

 

 

Dynamic Context Menus

The cl_ctmenu class provides the load_gui_status static method and a range of other methods. You can use these methods to create or adjust the context menu at runtime by calling them in the handler method. For more information, see the documentation for the cl_ctmenu class.

 

 

Processing Functions of Context Menus

If the user chooses a function of the context menu, the USER_COMMAND event is triggered. The event exports the code of the function that the user selects using the e_ucomm parameter.

 

 

USER_COMMAND Event

A function code triggered through the context menu is processed in the same way as a function code that is triggered by a button that you define. You must define, implement, and register a corresponding handler method for the USER_COMMAND event of your ALV instance on the application server. You then use the e_ucomm function code within the handler method to decide the function that you need to execute.