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: 

unable to trigger my event

Former Member
0 Kudos

dear experts,

I need to add some extra features to title bar of my alv report.i got some documents and iam trying on that.Here in my program its displaying the newly created icon but when i click on that icon its not displaying or teriigering my event -

class lcl_event_receiver definition deferred.

TYPE-POOLS: ICON.

data: con type ref to cl_gui_custom_container,

gr_alvgrid type ref to cl_gui_alv_grid.

DATA: ITAB_EXCLUDE TYPE UI_FUNCTIONS.

DATA: WA_EXCLUDE TYPE UI_FUNC.

data: it_toolbar TYPE stb_button.

data: begin of itab occurs 0.

include structure mara.

data: end of itab.

data: event_receiver TYPE REF TO LCL_EVENT_RECEIVER.

select * from mara into table itab.

call screen 1000.

----


  • CLASS lcl_event_receiver DEFINITION

----


*

----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

class-methods: handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive,

handle_menu_buttons for event menu_button of cl_gui_alv_grid importing e_object e_ucomm,

handle_USER_COMMAND for event user_command of cl_gui_alv_grid importing e_ucomm.

ENDCLASS. "lcl_event_receiver DEFINITION

----


  • CLASS lcl_event_receiver IMPLEMENTATION

----


*

----


CLASS lcl_event_receiver implementation.

method handle_toolbar.

move 'DETAIL-TAIL' TO IT_TOOLBAR-FUNCTION.

MOVE ICON_DETAIL TO IT_TOOLBAR-ICON.

MOVE 2 TO IT_TOOLBAR-BUTN_TYPE.

APPEND IT_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

ENDMETHOD. "handle_toolbar

METHOD HANDLE_MENU_BUTTONS.

IF E_UCOMM = 'DETAIL'.

CALL METHOD e_object->add_function

EXPORTING

fcode = 'DISPLAY'

text = 'DISPLAY'.

ENDIF.

ENDMETHOD. "HANDLE_MENU_BUTTONS

METHOD handle_user_command.

CASE e_ucomm.

WHEN 'DISPLAY'.

MESSAGE 'Menu Clicked' TYPE 'I'.

ENDCASE.

ENDMETHOD. "handle_user_command

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

----


  • MODULE STATUS_1000 OUTPUT

----


*

----


MODULE STATUS_1000 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

CREATE OBJECT CON

EXPORTING

  • PARENT =

CONTAINER_NAME = 'CO_CON'

  • STYLE =

  • LIFETIME = lifetime_default

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

  • EXCEPTIONS

  • CNTL_ERROR = 1

  • CNTL_SYSTEM_ERROR = 2

  • CREATE_ERROR = 3

  • LIFETIME_ERROR = 4

  • LIFETIME_DYNPRO_DYNPRO_LINK = 5

  • others = 6

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT GR_ALVGRID

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

I_PARENT = CON

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

  • I_FCAT_COMPLETE = SPACE

  • EXCEPTIONS

  • ERROR_CNTL_CREATE = 1

  • ERROR_CNTL_INIT = 2

  • ERROR_CNTL_LINK = 3

  • ERROR_DP_CREATE = 4

  • others = 5

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WA_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_MAXIMUM.

APPEND WA_EXCLUDE TO ITAB_EXCLUDE.

WA_EXCLUDE = CL_GUI_ALV_GRID=>MC_mb_SUM.

APPEND WA_EXCLUDE TO ITAB_EXCLUDE.

CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

I_STRUCTURE_NAME = 'MARA'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

IT_TOOLBAR_EXCLUDING = ITAB_EXCLUDE

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

CHANGING

IT_OUTTAB = ITAB[]

  • IT_FIELDCATALOG =

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • TOO_MANY_LINES = 3

  • others = 4

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT event_receiver.

SET HANDLER event_receiver->handle_user_command

event_receiver->handle_menu_buttons

event_receiver->handle_toolbar FOR ALL INSTANCES. "*Calling the interactive toolbar method of ALV

CALL METHOD GR_ALVGRID->set_toolbar_interactive.

ENDMODULE. " STATUS_1000 OUTPUT

&----


*& Module USER_COMMAND_1000 INPUT

&----


  • text

----


MODULE USER_COMMAND_1000 INPUT.

ENDMODULE. " USER_COMMAND_1000 INPUT

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

Hi,

One thing which I cannot see in your code and which is crucial in order your custom button can work is this


CALL METHOD gr_alvgrid->set_toolbar_interactive.  "place it after SET HANDLER...

Now handle_user_command method should be triggered.

Regards

Marcin

4 REPLIES 4

MarcinPciak
Active Contributor
0 Kudos

Hi,

One thing which I cannot see in your code and which is crucial in order your custom button can work is this


CALL METHOD gr_alvgrid->set_toolbar_interactive.  "place it after SET HANDLER...

Now handle_user_command method should be triggered.

Regards

Marcin

0 Kudos

hi marcin, thanks a lot for your help..i have coded but still unable to trigger user_commaned method.Could you check this in your machine-

class lcl_event_receiver definition deferred.

TYPE-POOLS: ICON.

data: con type ref to cl_gui_custom_container,

gr_alvgrid type ref to cl_gui_alv_grid.

DATA: ITAB_EXCLUDE TYPE UI_FUNCTIONS.

DATA: WA_EXCLUDE TYPE UI_FUNC.

data: it_toolbar TYPE stb_button.

data: begin of itab occurs 0.

include structure mara.

data: end of itab.

data: event_receiver TYPE REF TO LCL_EVENT_RECEIVER.

select * from mara into table itab.

call screen 1000.

----


  • CLASS lcl_event_receiver DEFINITIONL

----


*

----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

class-methods:

handle_menu_buttons for event menu_button of cl_gui_alv_grid importing e_object e_ucomm,

handle_USER_COMMAND for event user_command of cl_gui_alv_grid importing e_ucomm,

handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive.

ENDCLASS. "lcl_event_receiver DEFINITION

----


  • CLASS lcl_event_receiver IMPLEMENTATION

----


*

----


CLASS lcl_event_receiver implementation.

method handle_toolbar.

move 'DETAIL-TAIL' TO IT_TOOLBAR-FUNCTION.

MOVE ICON_DETAIL TO IT_TOOLBAR-ICON.

MOVE 2 TO IT_TOOLBAR-BUTN_TYPE.

APPEND IT_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

ENDMETHOD. "handle_toolbar

METHOD HANDLE_MENU_BUTTONS.

IF E_UCOMM = 'DETAIL-TAIL'.

CALL METHOD e_object->add_function

EXPORTING

fcode = 'DISPLAY-TAIL'

text = 'DISPLAY'.

ENDIF.

ENDMETHOD. "HANDLE_MENU_BUTTONS

METHOD handle_user_command.

CASE E_UCOMM.

WHEN 'DISPLAY-TAIL'.

MESSAGE 'THESE IS TEST EVENT' TYPE 'I'.

ENDCASE.

ENDMETHOD.

ENDCLASS.

----


  • MODULE STATUS_1000 OUTPUT

----


*

----


MODULE STATUS_1000 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

CREATE OBJECT CON

EXPORTING

  • PARENT =

CONTAINER_NAME = 'CO_CON'

  • STYLE =

  • LIFETIME = lifetime_default

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

  • EXCEPTIONS

  • CNTL_ERROR = 1

  • CNTL_SYSTEM_ERROR = 2

  • CREATE_ERROR = 3

  • LIFETIME_ERROR = 4

  • LIFETIME_DYNPRO_DYNPRO_LINK = 5

  • others = 6

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT GR_ALVGRID

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

I_PARENT = CON

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

  • I_FCAT_COMPLETE = SPACE

  • EXCEPTIONS

  • ERROR_CNTL_CREATE = 1

  • ERROR_CNTL_INIT = 2

  • ERROR_CNTL_LINK = 3

  • ERROR_DP_CREATE = 4

  • others = 5

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WA_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_MAXIMUM.

APPEND WA_EXCLUDE TO ITAB_EXCLUDE.

WA_EXCLUDE = CL_GUI_ALV_GRID=>MC_mb_SUM.

APPEND WA_EXCLUDE TO ITAB_EXCLUDE.

CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

I_STRUCTURE_NAME = 'MARA'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

IT_TOOLBAR_EXCLUDING = ITAB_EXCLUDE

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

CHANGING

IT_OUTTAB = ITAB[]

  • IT_FIELDCATALOG =

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • TOO_MANY_LINES = 3

  • others = 4

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT event_receiver.

SET HANDLER event_receiver->handle_menu_buttons

event_receiver->handle_toolbar

event_receiver->handle_user_command

FOR ALL INSTANCES.

CALL METHOD GR_ALVGRID->set_toolbar_interactive.

ENDMODULE. " STATUS_1000 OUTPUT

&----


*& Module USER_COMMAND_1000 INPUT

&----


  • text

----


MODULE USER_COMMAND_1000 INPUT.

ENDMODULE. " USER_COMMAND_1000 INPUT

0 Kudos

This is working fine for me, message THESE IS TEST EVENT is shown on screen once I pick button from dropdown list.

Maybe you are trying to select other option (standard one). This method will only be triggered for your custom options on alv toolbar (here dropdown list).

Regards

Marcin

0 Kudos

ya thank you pciak..same here..its working.thank you for your patience.thread closed