‎2023 Jun 09 11:52 AM
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
‎2023 Jun 09 4:30 PM
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( ).
‎2023 Jun 10 3:53 PM
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
‎2023 Jun 10 5:45 PM
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 .