Automatically Trigger onEnter event after selecting value from the Value Help(F4 Help)
Introduction
This document helps how to call onEnter action handler of Input filed after selecting value in the Value Help without pressing Enter Key. In the earlier versions of Netweaver ( before Netweaver 7.4 ) you have to manually press Enter key in the Input field after selecting value from the F4 help.
Prerequisites
SAP NetWeaver 7.4
Step by Step Process
Step 1: Create a Web Dynpro Component.
Go to the SE80 transaction and create a Web Dynpro Component.
Enter Description and click on OK.
Save and Activate the Component.
Step 2: Data Binding
Go to the Context tab of Main View and create an attribute CARRID of type S_CARRID_ID( which has dictionary search help).
Step 3: Layout Design.
Now Go to Layout tab,
Create label UI with text ‘Airline’ and input field. Bind the Value of Input filed to the context attribute CARRID.
Create an Action for onEnter of Input field.
Now go to Methods tab of MAIN view and write the below code ONACTIONGET_FLIGHTDATA method.
ONACTIONGET_FLIGHTDATA |
---|
method ONACTIONGET_FLIGHTDATA .
** Get the Airline and update the dependent input fields/ view fields * For Demo purpose I am just displaying a success message * Report success message endmethod. |
Step 4: Create Application.
Save and Activate the Web Dynpro Component. Create the Web Dynpro Application and Save it.
Enter description and save it.
Test Application
Now Right click on Web Dynpro Application and click on Test.
Now Select the F4 help in the input field.
Select the Value in the Value Help and click on OK.
After selecting the value we have to press Enter to trigger onEnter event.
Now we can see onEnter event was triggered after pressing Enter manually in the Input Field.
It is preferable that the onEnter action handler of an Input Fields is executed directly after a value has been selected from the value help.
To Trigger the onEnter event of Input fields automatically after selecting the value from the value help, we have to call the method register_on_enter_for_f4() of interface IF_WD_VIEW_CONTROLLER.
We have to write the below code in WDDOINIT method.
DATA lr_view_controller TYPE REF TO cl_wdr_view.
lr_view_controller ?= wd_this->wd_get_api( ).
lr_view_controller->if_wd_view_controller~register_on_enter_for_f4( register_on_enter = abap_true ).
Write the below code in WDDOINIT method.
WDDOINIT |
---|
method WDDOINIT . wd_this->wd_get_api( )->register_on_enter_for_f4( register_on_enter = abap_true ). endmethod. |
Note: This setting can be made for all value helps for each view separately by calling method register_on_enter_for_f4() in the WDDOINIT method of each view.
Save and Activate the Component.
Result
Now Test the Web Dynpro Application.
Select the F4 help in the input field.
Select the Value in the Value Help and click on OK.
After selecting the value we can see the onEnter action handler is called automatically.
Conclusion
Using this feature we can make onEnter action handler to call automatically immediately after selecting the value from the Value Help. This feature is useful to update the other View Fields that are dependent on the input field by calling onEnter action handler of the input fields automatically after selecting the value from the Value Help. Here I demonstrated a simple Web Dynpro Application. You can use this according to your requirements.
Follow me on Google+
Nice document. Helpful. Thanks for sharing!
Regards,
Karthik
For those who aren't yet at 7.4 level - here's a blog I wrote 3 years ago which basically shows how to do the same thing on a 7.1 stack
Firing a WDA event on using a Search Help - how to do it, without an NDA
Cheers,
Chris
Hi Chris,
Will this be applicable to Date field also...
Hi, am afraid I'm not sure. I always followed the pattern of using date navigator if I needed an immediate event on date selection. Although it is likely that by slightly changing the code I mention in my blog that you would be able to get the date to event. However, using the date navigator would be a much simpler option.
But can we asssign Date Navigator to Search Help of Input field.
As of now i am using SYDATUM as field type for Input field so its populating calendar in the searh help.
Date Navigator functionality works in the similar way
No, not assign as search help, use instead of input field. As it throws an event on date selection.
Hi Kiran,
Nice Document. One question will it be possible to triggered the event on custom search helps too ?
Hi Bhanu,
What do you mean by custom search helps? Did you mean DDIC Z search helps! If so, the answer is yes. For all DDIC search helps this will work.
For OVS search help, this won't trigger automatically. For OVS in the even handler of OVS you can call the method explictly.
Regards,
Kiran
Hello Kiran Kumar Valluru,
I followed you document to register an event on I/P field.Below is the code i written in my WDDOINIT( ) of my View controller which is having one I/P field.
DATA lr_view_controller TYPE REF TO cl_wdr_view.
lr_view_controller ?= wd_this->wd_get_api( ).
lr_view_controller->if_wd_view_controller~register_on_enter_for_f4( register_on_enter = abap_true ).
But i'm getting error "IF_WD_VIEW_CONTROLLER~REGISTER_ON_EVENT_FOR_F4 is not declared or inherited in class "CL_WDR_VIEW" .Pls guide me.
Thanks
Katrice
Hi,
Please see the prerequisite. You should be on Netweaver 7.4 to use the mentioned method. If you are on lower Netweaver version you can follow the blog which Chis Paine has mentioned above in the comments.
Cheers,
Kiran
Hi Kiran,
Will it work for the Standard Date input field?
I have an On_Enter method for the Date input field. Will the same method will trigger the method while selecting teh date from the calendar.
I tried but it didnt got triggered. Please give your suggestion.
Thanks
Nalla B.
Hi,
No, The onEnter event will not be called automatically for date fields as there is no screen render when you select the date from date value help.
Regards,
Kiran
Thanks kiran.
But I have a dropdown value which has to be loaded based on the dates in the input field?
What is the possibility other than On_Enter or going for a custom button to load the values?
Kindly give some suggestions.
Thanks,
Nalla B.
Hi,
As mentioned earlier, you cannot trigger Enter event automatically for date fields. You need to press Enter(or some action) after entering dates. Or, remove the date field and create a DateNavigator with events associated with it. Or creating a Freely programmed value help for calendar help which is tricky.
Regards,
Kiran
Hi Kiran,
It is very useful.I tired it on input fields and it worked. But how to trigger the same in ALV table having input fields?.
Because, i have To-Date field in my ALV table, if we select todate as past date and on press on enter only, It is triggering the event. I want to achieve the same as per your document.
Thanks
Katrice
Its' very useful. Thanks
-Srikanth
Hi Kiran,
Thanks for the blog.
I am facing one issue with it. The action is triggering twice in my case. I am selecting the value from F4 help and its calling the same action twice.
I am showing in one popup in this action and its coming twice.
Is there any way to stop this?
Thanks in Advance.
Regards,
Sameer
I have a question.Suppose i have a table with an add button on it's toolbar and an input field having F4 help.Now the user can click on add many times creating multiple blank rows.Now he/she presses on the F4 help of say xth row and selects a value.How will i get the index of the selected value?
Nice document. Helpful. Thanks for sharing!