REPORT demo_dynpro_context_menu. DATA: field1 TYPE i VALUE 10, field2 TYPE p DECIMALS 4. DATA: prog TYPE sy-repid, flag(1) TYPE c VALUE 'X'. DATA: ok_code TYPE sy-ucomm, save_ok TYPE sy-ucomm. prog = sy-repid. CALL SCREEN 100. MODULE status_0100 OUTPUT. SET TITLEBAR 'TIT100'. IF flag = 'X'. SET PF-STATUS 'SCREEN_100' EXCLUDING 'REVEAL'. ELSEIF flag = ' '. SET PF-STATUS 'SCREEN_100' EXCLUDING 'HIDE'. ENDIF. LOOP AT SCREEN INTO DATA(screen_wa). IF screen_wa-group1 = 'MOD'. IF flag = 'X'. screen_wa-active = '1'. ELSEIF flag = ' '. screen_wa-active = '0'. ENDIF. MODIFY SCREEN FROM screen_wa. ELSEIF screen_wa-name = 'TEXT_IN_FRAME'. IF flag = 'X'. screen_wa-active = '0'. ELSEIF flag = ' '. screen_wa-active = '1'. ENDIF. MODIFY SCREEN FROM screen_wa. ENDIF. ENDLOOP. ENDMODULE. MODULE cancel INPUT. LEAVE PROGRAM. ENDMODULE. MODULE user_command_0100. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN 'HIDE'. flag = ' '. WHEN 'REVEAL'. flag = 'X'. WHEN 'SQUARE'. field2 = field1 ** 2. WHEN 'CUBE'. field2 = field1 ** 3. WHEN 'SQUAREROOT'. field2 = field1 ** ( 1 / 2 ). WHEN 'CUBICROOT'. field2 = field1 ** ( 1 / 3 ). ENDCASE. ENDMODULE. ************************************************************ * Callback-Routines: ************************************************************ FORM on_ctmenu_text USING l_menu TYPE REF TO cl_ctmenu. l_menu->load_gui_status( EXPORTING program = prog status = 'CONTEXT_MENU_1' menu = l_menu ). ENDFORM. FORM on_ctmenu_frame USING l_menu TYPE REF TO cl_ctmenu. l_menu->load_gui_status( EXPORTING program = prog status = 'CONTEXT_MENU_2' menu = l_menu ). l_menu->load_gui_status( EXPORTING program = prog status = 'CONTEXT_MENU_1' menu = l_menu ). l_menu->set_default_function( EXPORTING fcode = 'HIDE' ). ENDFORM. FORM on_ctmenu_reveal USING l_menu TYPE REF TO cl_ctmenu. l_menu->load_gui_status( EXPORTING program = prog status = 'CONTEXT_MENU_3' menu = l_menu ). l_menu->load_gui_status( EXPORTING program = prog status = 'CONTEXT_MENU_1' menu = l_menu ). l_menu->set_default_function( EXPORTING fcode = 'REVEAL' ). ENDFORM. FORM on_ctmenu_input USING l_menu TYPE REF TO cl_ctmenu. DATA calculate_menu TYPE REF TO cl_ctmenu. CREATE OBJECT calculate_menu. calculate_menu->add_function( EXPORTING fcode = 'SQUARE' text = text-001 ). calculate_menu->add_function( EXPORTING fcode = 'CUBE' text = text-002 ). calculate_menu->add_function( EXPORTING fcode = 'SQUAREROOT' text = text-003 ). calculate_menu->add_function( EXPORTING fcode = 'CUBICROOT' text = text-004 ). l_menu->add_submenu( EXPORTING menu = calculate_menu text = text-005 ). ENDFORM.
Description
The static Next-Screen-Number of screen 100 is 100. The elements TEXT2 and FIELD2 do not have their own context menus. They inherit the context menu FRAME of the frame. The modification group MOD is assigned to them. The screen flow logic is:
- PROCESS BEFORE OUTPUT.
MODULE status_0100.
PROCESS AFTER INPUT.
MODULE cancel AT EXIT-COMMAND.
MODULE user_command_0100.
The GUI status SCREEN_100 is set to PBO statically, in which, depending on the field flag, the function codes HIDE or REVEAL are hidden. The context menus to the screen elements are set up in the callback routines as follows:
- TEXT: Loading of the static context menu CONTEXT_MENU_1 without modification. This context menu has a line Cancel.
- FRAME: Setup of the context menu from the static context menus. CONTEXT_MENU_2 und CONTEXT_MENU_1. This context menu has two lines Hide result and Cancel. The line for the function code HIDE is highlighted.
- REVEAL: Creation of the context menus from the static context menus CONTEXT_MENU_3 and CONTEXT_MENU_1. This context menu has two lines Display result and Cancel. The line to the function code REVEAL is highlighted.
- INPUT: Setting up the context menu by incorporating the multiline local context menu CALCULATE_MENU as submenu. For the latter, a local reference variable with reference to CL_CTMENU is created, an object is created and the new function codes SQUARE, CUBE, SQUAREROOT and CUBICROOT are added. At the integration into the context menu for INPUT, a text must be specified for the entry, after which the submenu is attached.
When executing the program and pressing the right (secondary) mouse button or SHIFT F10, the user receives the context menu TEXT in the first line, the context menu INPUT in the second line, and the context menu FRAME in the third line. The fourth line is hidden after program start. On all other remaining screen components, the standard context menu appears with all static function codes and additionally F1 and F4.
When selecting a new dynamic function, calculations are carried out with the number in input field FIELD1 and then put to FIELD2. When selecting the function Hide result (HIDE), the screen is modified dynamically. Thereby, the fourth line is made visible making the context menu REVEAL accessible.