Context Menu in Dialog Programming

...Previous  

The Program source code is provided below copy and paste it in editor and save it.

*&---------------------------------------------------------------------*
*& Module Pool       ZD_CTMENU
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
PROGRAM  ZD_CTMENU.
DATA text1(10) TYPE c.
DATA text2(10) TYPE c.
DATA text_CUT(10) TYPE c.
DATA right_clk TYPE REF TO cl_ctmenu.
DATA OK_CODE TYPE SY-UCOMM.
 DATA:prog TYPE sy-repid,
      flag(1) TYPE c VALUE 'X',
      fld(20) TYPE c,
      off     TYPE i,
      val(20) TYPE c.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
  prog = sy-repid.
* SET PF-STATUS 'ZGUI_9000'.
  SET TITLEBAR 'TITLE'.
ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
CLEAR OK_CODE.
OK_CODE = SY-UCOMM.
CASE OK_CODE.
  WHEN 'OPEN'.
    MESSAGE 'OPEN IS CLICKED' TYPE 'I'.
    WHEN 'CUT'.
      text_CUT = text1. "storing in some temp variable
      CLEAR text1.
    WHEN 'PASTE'.
         GET CURSOR FIELD fld VALUE val."to find out in which i/o field the cursor is in
       if fld = 'TEXT2'.
          text2 = TEXT_CUT.
       ELSEIF fld = 'TEXT1'.
         text1 = TEXT_CUT.
       ENDIF.
      when 'CLEAR'.
        CLEAR : text1 ,TEXT2,TEXT_CUT.
ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT
"RIGHT CLICK on text 1 input/ouput field
FORM on_ctmenu_text1 USING l_menu TYPE REF TO cl_ctmenu.
   CREATE OBJECT right_clk.
  CALL METHOD: right_clk->add_function
                      EXPORTING fcode = 'OPEN'
                                text  = 'Open',
               right_clk->add_function
                       EXPORTING fcode = 'CUT'
                                 text  = 'Cut',
               right_clk->add_function
                       EXPORTING fcode = 'PASTE'
                                 text  = 'Paste',
              right_clk->add_function
                       EXPORTING fcode = 'MOVE'
                                 text  = 'Move',
               l_menu->add_submenu
                       EXPORTING menu = right_clk
                                 text = 'OPTIONS'.
ENDFORM.
"RIGHT CLICK on text 2 input/ouput field
FORM on_ctmenu_text2 USING l_menu TYPE REF TO cl_ctmenu.
   CREATE OBJECT right_clk.
  CALL METHOD: right_clk->add_function
                      EXPORTING fcode = 'OPEN'
                                text  = 'Open',
               right_clk->add_function
                       EXPORTING fcode = 'CUT'
                                 text  = 'Cut',
               right_clk->add_function
                       EXPORTING fcode = 'PASTE'
                                 text  = 'Paste',
              right_clk->add_function
                       EXPORTING fcode = 'MOVE'
                                 text  = 'Move',
               l_menu->add_submenu
                       EXPORTING menu = right_clk
                                 text = 'OPTIONS'.
ENDFORM.

Activate and execute the program.

Output

Type something in text1 input field and Right click that field

Context menu is displayed

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image