Application Development and Automation 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: 
Read only

Menu_button event

ULGIA
Explorer
0 Likes
1,350

Hello everyone,

In my program on the ALV grid, I added a button using the event menu_button. Now I want to change a standard menu button's context menu. For example:

METHOD menu_button.

CASE e_ucomm.
WHEN 'FC2'.
* CALL METHOD e_object->add_function
* EXPORTING
* fcode = 'G1'
* text = 'Tcodes'.
DATA: obsubmenu TYPE REF TO cl_ctmenu.
CREATE OBJECT obsubmenu.

CALL METHOD obsubmenu->add_function
EXPORTING
fcode = 'M1'
text = 'ABAP editor'.

CALL METHOD obsubmenu->add_function
EXPORTING
fcode = 'M2'
text = 'ABAP classes'.

CALL METHOD obsubmenu->add_function
EXPORTING
fcode = 'M3'
text = 'ABAP Functions'.

CALL METHOD e_object->add_submenu
EXPORTING
menu = obsubmenu
text = 'Tcodes'.
when '&MB_EXPORT'. <------------------------------- issue.
message 'WORKING' type 'I'.
ENDCASE.

When I try to debug it, it skips when '&MB_EXPORT' condition and I can not clear, change, add, or do anything else for this standard menu button. It simply does not recognize the button.

If you have any sample codes or any suggestions, please provide them.

Thank you for time and interest

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,262

There is this non-standard solution. I don't know if there's a better solution (could be, as there's all a façade stuff...)

REPORT ztest.
CLASS lcl_app DEFINITION INHERITING FROM cl_gui_alv_grid.
  PUBLIC SECTION.
    METHODS constructor.
    METHODS exit.
    METHODS on_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object.
    METHODS on_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm.
    DATA gt_sbook TYPE TABLE OF sbook.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
  METHOD constructor.
    CALL METHOD super->constructor
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    SELECT * FROM sbook INTO TABLE gt_sbook.
    SET HANDLER on_toolbar FOR me.
    SET HANDLER on_user_command FOR me.
    set_table_for_first_display(
        EXPORTING i_structure_name = 'SBOOK'
                  is_layout        = VALUE #( no_toolbar = space )
        CHANGING it_outtab         = gt_sbook ).
  ENDMETHOD.
  METHOD exit.
    free( ).
  ENDMETHOD.
  METHOD on_toolbar.
    m_cl_menu_button_export->add_function( fcode = 'ZZ' text = 'Test ZZ' ).
  ENDMETHOD.
  METHOD on_user_command.
    CASE e_ucomm.
      WHEN 'ZZ'.
        MESSAGE 'Nice!' TYPE 'I'.
    ENDCASE.
  ENDMETHOD.
ENDCLASS.

DATA go_app TYPE REF TO lcl_app.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF go_app IS NOT BOUND.
    go_app = NEW #( ).
  ENDIF.

AT SELECTION-SCREEN ON EXIT-COMMAND.
  go_app->exit( ).
Read only

0 Likes
1,262

Hello Sandra, thank you for your time.

Can I ask you? m_cl_menu_button_export is an attribute right ? How do you call a method using attribute name?

m_cl_menu_button_export->add_function
Read only

0 Likes
1,262

Attribute means a Data Object inside a class section (public/private/protected). A data object can be any type. Here, m_cl_menu_button_export is declared in the protected section of CL_GUI_ALV_GRID as:

data M_CL_MENU_BUTTON_EXPORT type ref to CL_CTMENU .