Context Menus for Lists

As with normal screens, the system creates a standard context menu when you use a dialog status in a list. You can call this standard context menu using the right-hand mouse button (Shift + F10). It displays all of the functions assigned to function keys.

You can define context menus for list lines in the same way as for screen elements. To do this, you must assign a special function code to the function key SHIFT + F10 in the dialog status of the list. To define context menus for a list, you must first define a dialog status for the list and set it using SET PF-STATUS.

In this dialog status, which you will normally create using the List status template, the List with context menu option must be selected in the function key setting attributes. To do this, place the cursor on a function key setting in the Menu Painter and choose Attributes, or Start of the navigation pathGoto Next navigation step Attributes Next navigation step F key settingEnd of the navigation path. The function code %CTX is assigned to function key SHIFT + F10. Since the introduction of context menus on lists, it is no longer possible to assign SHIFT + F10 freely to any function in the Menu Painter. In any existing dialog status where a function code was assigned to SHIFT + F10, it has been reassigned to SHIFT + CTRL + 0. You must activate the function code %CTX manually before it has any effect in the dialog status.

As on screens, context menus on lists are generated dynamically in ABAP programs as objects of the class CL_CTMENU. For context menus on lists, you must program a callback routine in the ABAP program:

FORM on_ctmenu_request USING l_menu TYPE REF TO cl_ctmenu.
...
ENDFORM.

In this subroutine, you can define a context menu using the object reference l_menu as described in the Context Menus section. To define a specific context menu, for example, you could get the cursor position on the list using GET CURSOR. If required, you may need to find out the current list level from the corresponding system fields (for example, sy-listi).

When you right-click a list line (or choose SHIFT + F10), the callback routine is executed, and the context menu defined in it is displayed. If the user chooses a menu item, the system carries on processing according to the function code assigned to it. The function is either executed by the runtime environment, or the corresponding event is triggered (in which case, the function code is placed in the system field sy-ucomm).

If you right-click outside a list line, the system displays the standard context menu.