Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Context Menu

Former Member
0 Kudos

hi.

can anybody give me guidelines for how to use contaxt menus in abap.

1 ACCEPTED SOLUTION

Former Member

Hi,

Context Menus

The user interface of a screen is defined by a GUI status, which you define in the Menu Painter and assign the type Dialog status. For each dialog status, the system

automatically creates a standard context menu, which the user can display by clicking the righthand mouse button on the screen (or choosing Shift+F10). The standard context menu contains all of the function keys to which functions are assigned. It therefore makes it easy to access any function code that is available using the keyboard, since normally only the most important are assigned to the application toolbar.

However, as well as the standard context menu, you can define context-specific menus for any of the following screen elements:

Input/output fields

Text fields

Table controls

Group boxes

Subscreens

When you select one of these elements using the right-hand mouse button, you can create a dynamic context menu in the ABAP program. This may contain any functions, and is not

restricted to function keys. You cannot assign context menus to pushbuttons, checkboxes, or radio buttons. However, you can assign unique function codes to them instead.

Example

The following example shows some of the technical possibilities for creating context menus, but

does not necessarily observe all of the style guidelines.

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.

IF screen-group1 = 'MOD'.

IF flag = 'X'.

screen-active = '1'.

ELSEIF flag = ' '.

screen-active = '0'.

ENDIF.

MODIFY SCREEN.

ELSEIF screen-name = 'TEXT_IN_FRAME'.

IF flag = 'X'.

screen-active = '0'.

ELSEIF flag = ' '.

screen-active = '1'.

ENDIF.

MODIFY SCREEN.

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.

CALL METHOD: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.

CALL METHOD: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.

CALL METHOD: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.

CALL METHOD: 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.

Regards,

Bhaskar

3 REPLIES 3

Former Member
0 Kudos

Hi,

-


>Context Menus

The user interface of a screen is defined by a GUI status, which you define in the Menu Painter and assign the type Dialog status. For each dialog status, the system automatically creates a standard context menu, which the user can display by clicking the right-hand mouse button on the screen (or choosing Shift+F10 ). The standard context menu contains all of the function keys to which functions are assigned. It therefore makes it easy to access any function code that is available using the keyboard, since normally only the most important are assigned to the application toolbar.

However, as well as the standard context menu, you can define context-specific menus for any of the following screen elements:

Input/output fields

Text fields

Table controls

Group boxes

Subscreens

When you select one of these elements using the right-hand mouse button, you can create a dynamic context menu in the ABAP program. This may contain any functions, and is not restricted to function keys. You cannot assign context menus to pushbuttons, checkboxes, or radio buttons. However, you can assign unique function codes to them instead.

-


>

Context menus (right mouse key, SHIFT F10) are shortcuts for functions that are frequently used.

They can be used to display context-sensitive menus. The context is defined by the position (cursor for SHIFT F10, mouse location for right mouse key) where the user called the context menu. If needed, you can specify the context more precisely with the displayed contents. This permits the user to select functions that are relevant for the current context using the context menu.

You define whether a context menu should be offered when you create a screen object (screens, input fields, table controls, boxes, ...). When the user selects a context menu on an object, an event mechanism (as understood by ABAP objects) calls a certain subroutine in the application program.

The program is assigned a menu reference. The program uses this menu reference to build the display menu. Menus defined with the Menu Painter and dynamic menus can be used here.

After the user executes a menu function, the application program regains control and can react to the user input.

Context menus are assigned to output fields. When you assign a context menu to a box, table control or screen (normal or subscreen), all the subordinate output fields that do not have a context menu inherit that one.

You can create a context menu from within the object list of the Object Navigator. Position the cursor on GUI status and right-click. The Object Navigator automatically opens the Menu Painter.

Of course you can also create a context menu directly in the Menu Painter.

A context menu is a special GUI status. Assign it a name, a descriptive text and status type Context menu.

In a context menu you can link any function codes and function texts. In particular, you can take advantage of your screen pushbuttons. The functions already provided in the interface can be used as an F4 input help.

The link technique ensures consistent context menus in large applications.

You should observe the following rules when designing context menus.

Do not use any functions that cannot be found elsewhere in the system (pushbuttons or interface).

Avoid using more than two hierarchy levels in context menus.

Do not use more than 10 entries, but map all the available pushbuttons.

Use separators to structure the context menu optically.

Place object-specific statements at the beginning of the menu.

Pressing the right mouse key triggers a callback routine in your program. You can create this callback routine in your application program with forward navigation. It is named ON_CTMENU_. You define which callback routine is called in the Screen Painter.

You can directly assign a callback routine to input/output fields, text fields and status icons. Checkboxes, radio buttons and pushbuttons do not have their own callback routines. However, these fields can inherit context menus from boxes or screens.

If you assign a callback routine to a table control, it is triggered for all the fields of the table control that do not have their own callback routine.

The callback routine has the following form:

FORM ON_CTMENU_ USING p_menu TYPE REF TO cl_ctmenu.

.

ENDFORM.

The context menu is built with a method call for the instance of class cl_ctmenu that was passed.

Clicking with the right mouse key on an output field triggers the corresponding callback routine.

You can now use the static method load_gui_status of class cl_ctmenu to load a context menu that was predefined in the Menu Painter. Using other methods of class cl_ctmenu (see next slide) you can also completely rebuild the context menu or modify a loaded menu.

If the user triggers a function in the context menu, the corresponding function code is placed in the command field and triggered depending on function type PAI of the screen.

The class cl_ctmenu provides a number of other methods in addition to the static method load_gui_status. You can use them to adjust the context menu at runtime (e.g. using the values in data fields).

The corresponding methods are called within the callback routine.

You can find further information in the documentation for class cl_ctmenu in the Class Builder.

regards,

vineela.

Former Member

Hi,

Context Menus

The user interface of a screen is defined by a GUI status, which you define in the Menu Painter and assign the type Dialog status. For each dialog status, the system

automatically creates a standard context menu, which the user can display by clicking the righthand mouse button on the screen (or choosing Shift+F10). The standard context menu contains all of the function keys to which functions are assigned. It therefore makes it easy to access any function code that is available using the keyboard, since normally only the most important are assigned to the application toolbar.

However, as well as the standard context menu, you can define context-specific menus for any of the following screen elements:

Input/output fields

Text fields

Table controls

Group boxes

Subscreens

When you select one of these elements using the right-hand mouse button, you can create a dynamic context menu in the ABAP program. This may contain any functions, and is not

restricted to function keys. You cannot assign context menus to pushbuttons, checkboxes, or radio buttons. However, you can assign unique function codes to them instead.

Example

The following example shows some of the technical possibilities for creating context menus, but

does not necessarily observe all of the style guidelines.

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.

IF screen-group1 = 'MOD'.

IF flag = 'X'.

screen-active = '1'.

ELSEIF flag = ' '.

screen-active = '0'.

ENDIF.

MODIFY SCREEN.

ELSEIF screen-name = 'TEXT_IN_FRAME'.

IF flag = 'X'.

screen-active = '0'.

ELSEIF flag = ' '.

screen-active = '1'.

ENDIF.

MODIFY SCREEN.

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.

CALL METHOD: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.

CALL METHOD: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.

CALL METHOD: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.

CALL METHOD: 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.

Regards,

Bhaskar

Former Member
0 Kudos

Can you please help me with an example of  ALV LIST with context menu.