‎2007 Sep 20 10:34 AM
Hi All,
I have a classic report with some fields. Whenever I right click on any of the values in the report column, a context menu should appear with the options I define.
Any idea abt how to do this?
Regards,
Sushma.
‎2007 Sep 20 11:18 AM
Hi,
<u><b>Context Menus for Lists</b></u>
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 have defined 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 Goto Attributes F key setting. The function code %CTX is assigned to function key ShiftF10. Since the introduction of context menus on lists, it is no longer possible to assign ShiftF10 freely to any
function in the Menu Painter. In any existing dialog status where a function code was assigned to ShiftF10, it has been reassigned to ShiftCtrl+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 [Page 639] 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, SYLISTI).
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.
Ex.
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.
Regards,
Bhaskar
‎2007 Sep 20 11:03 AM
Hello Sushma,
Please check the below program.
I hope It helps you.
REPORT Zjai_test.
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.
CLEAR wa_spfli.
ENDCASE.
FORM on_ctmenu_request USING l_menu TYPE REF TO cl_ctmenu.
DATA lin TYPE i.
GET CURSOR LINE lin.
IF lin > 2 AND sy-lsind = 0.
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.
ENDFORM.
Please Reward if it is helpful.
Regards
Jay
‎2007 Sep 20 11:18 AM
Hi,
<u><b>Context Menus for Lists</b></u>
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 have defined 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 Goto Attributes F key setting. The function code %CTX is assigned to function key ShiftF10. Since the introduction of context menus on lists, it is no longer possible to assign ShiftF10 freely to any
function in the Menu Painter. In any existing dialog status where a function code was assigned to ShiftF10, it has been reassigned to ShiftCtrl+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 [Page 639] 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, SYLISTI).
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.
Ex.
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.
Regards,
Bhaskar
‎2007 Sep 20 12:47 PM
Hi Bhaskar,
.But the context menu is getting displayed only with shift+F10...but not with right click......
‎2007 Sep 20 12:55 PM
Hi,
Its working fine when we right click. I tested and send to you. once again try with that code.
Regards,
Bhaskar
‎2007 Sep 20 12:59 PM
Hey I have have tried with the right click many no of times but only shift+F10 is working...Do we need to change some settings for the right click to work?