cancel
Showing results for 
Search instead for 
Did you mean: 

Registering an event dynamically

Former Member
0 Kudos

Hello All,

I have a created a button SEARCH dynamically onto an ALV toolbar.

These changes, to create the self-defined function button, are done in the post-exit method of WDDOINIT as its an enhancement to a standard component.

For this I need to create an event handler method ON_SEARCH for the event ON_FUNCTION of the ALV interface controller.

I do not understand where and how can this be done.

Can we register this event handler dynamically. If yes where??

Thanks,

Smita

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Smita,

Add a new function to your ALV model as follows:

data: lr_function TYPE REF TO cl_salv_wd_function.

lr_function = lr_alv_model->if_salv_wd_function_settings~create_function( id = 'SEARCH' ).

You would have used a reference of the class cl_salv_wd_uie_button to create your search button on the toolbar. Set the function editor as that button reference.

lr_function->set_editor( lr_button ).

In the methods tab of your view, you have to explicitly create the event handler for the on_function event of the ALV. In the parameter r_param, you will have the ID that denotes the name of the function, 'search' in this case. So you can handle that particular event in your method.

Hope this helps.

Regards,

Nithya

Former Member
0 Kudos

Hi Smita,

Yes . You can register the Event Handle dynamically. But the Defination of the Event Handle must be defined before registerd. This making the defination dynamically possible.

In NET 310, They have clearly explained how to do this dyamically. Please refer the following link which has the clearn picture about what you want.

http://help.sap.com/saphelp_erp2005/helpdata/en/cf/bf2142b131ca7ee10000000a1550b0/frameset.htm

Warm Regards,

Vijay

Former Member
0 Kudos

Hello Vijay,

Accordingly I have added the code to register a method 'ON_SEARCH' to the event ON_FUNCTION of the ALV component in the POST-EXIT of WDDOINIT method of view.

Following is the code.

METHOD PST6I4ZN9JVV33T7Q3HJ3QK2TRNU . "Exit of WDDOINIT

DATA: L_COMPONENT_API TYPE REF TO IF_WD_COMPONENT,

L_COMPONENT_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE.

L_COMPONENT_API = WD_COMP_CONTROLLER->WD_GET_API( ).

L_COMPONENT_USAGE->ADD_EVENT_HANDLER(

LISTENER = L_COMPONENT_API

HANDLER_NAME = 'ON_SEARCH'

CONTROLLER_NAME = 'INTERFACECONTROLLER'

EVENT_NAME = 'ON_FUNCTION' ).

ENDMETHOD.

But the question here arises is where do write the event-handler method 'ON_SEARCH' without disturbing the standard component.

Also if I go in the enhacement mode and then add the eventhandler method to the method list..I am not able to choose the event ON_FUNCTION of the ALV.

I hope I am clear and not confusing you with it.

Former Member
0 Kudos

Hi smita,

here is my alv code for creating a button search

DATA:

lr_function TYPE REF TO cl_salv_wd_function,

lr_button TYPE REF TO cl_salv_wd_fe_button,

lr_function_settings TYPE REF TO if_salv_wd_function_settings.

lr_function_settings ?= l_value.

lr_function = lr_function_settings->create_function( 'SEARCH' ).

lr_function->set_visible( cl_wd_uielement=>e_visible-none ).

lr_function->set_group( 'Button' ).

CREATE OBJECT lr_button.

text = wd_assist->if_wd_component_assistance~get_text( '235' ).

lr_button->set_tooltip( text ).

lr_button->set_text( text ).

lr_function->set_editor( lr_button ).

Now in event handler method ON_FUNCTION for the ALV i check when r_param->id is

equal to SEARCH as shown below:

case r_param->id.

when 'SEARCH'.

search_dynamic( ).

endcase.

When the r_param->id is equal to SEARCH i just call a normal method called "search_dynamic" which has the logic for dynamic search.

i hope this should solve your problem

Former Member
0 Kudos

Rahul,

Thanks for your prompt response.

I have created a self defined function and have dynamicallly registered my event handler method 'ON_SEARCH' to the event ON_FUNCTION of the ALV. as below..

<i>METHOD PST6I4ZN9JVV33T7Q3HJ3QK2TRNU . "Exit of WDDOINIT

DATA: L_COMPONENT_API TYPE REF TO IF_WD_COMPONENT,

L_COMPONENT_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE.

L_COMPONENT_USAGE = WD_THIS->WD_CPUSE_ALV( ).

IF L_COMPONENT_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.

L_COMPONENT_USAGE->CREATE_COMPONENT( ).

ENDIF.

L_COMPONENT_API = WD_COMP_CONTROLLER->WD_GET_API( ).

L_COMPONENT_USAGE->ADD_EVENT_HANDLER(

LISTENER = L_COMPONENT_API

HANDLER_NAME = 'ON_SEARCH'

CONTROLLER_NAME = 'INTERFACECONTROLLER'

EVENT_NAME = 'ON_FUNCTION' ).

ENDMETHOD.</i>

The method ON_SEARCH should contain the code as you mentioned.

<i>Now in event handler method ON_FUNCTION for the ALV i check when r_param->id is

equal to SEARCH as shown below:

case r_param->id.

when 'SEARCH'.

search_dynamic( ).

endcase.</i>

To do this we need to add the method ON_SEARCH of method type event-handler in the method list.

But the main concern here is I am enhancing a standard component. And so wanted to make changes in the enhancement. But in the enhancement mode when I list the event handler method ON_SEARCH in the method list and F4 on the event column and when i select ON_FUNCTION event it doesnt come across the record. and hence in the method implementation the parameter R_PARAM does not appear in the parameter list of the event handler.

When i try doing this in the normal mode i.e change mode of the standard component it does list down the expected entries. But the main idea is not to change the standard component and hence go for enhancement mode..