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 . 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.
REPORT demo_list_context_menu . DATA: wa_spfli TYPE spfli, wa_sflight TYPE sflight. START-OF-SELECTION. SET PF-STATUS 'BASIC'. SELECT * FROM spfli INTO wa_spfli. WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom, wa_spfli-cityto. HIDE: wa_spfli-carrid, wa_spfli-connid. ENDSELECT. CLEAR wa_spfli. AT USER-COMMAND. CASE sy-ucomm. WHEN 'DETAIL'. CHECK NOT wa_spfli IS INITIAL. WRITE sy-lisel COLOR COL_HEADING. SELECT * FROM sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND connid = wa_spfli-connid. WRITE / wa_sflight-fldate. ENDSELECT. ENDCASE. FORM on_ctmenu_request USING l_menu TYPE REF TO cl_ctmenu. DATA lin TYPE i. IF sy-listi = 0. GET CURSOR LINE lin. IF lin > 2. CALL METHOD l_menu->add_function EXPORTING fcode = 'DETAIL' text = text-001. ENDIF. CALL METHOD l_menu->add_function EXPORTING fcode = 'BACK' text = text-002. ENDIF. ENDFORM.
In the dialog status BASIC for the basic list, %CTX is assigned to Shift+F10 . In the callback routine, a context menu is defined. The definition depends on the cursor position and the list currently displayed.
If the user right-clicks the two-line default page header on the basic list, the system displays a single-line context menu. The Back function is executed by the runtime environment. If you right-click a list line, a two-line context menu is displayed. The Detail function triggers the event AT USER-COMMAND .