Web Dynpro Selection Screen Variants Part 5: Variants in Action
The series Web Dynpro Selection Screen Variants concludes with a demonstration of using component ZWDR_SELECT_OPTIONS_VARI within a Web Dynpro report selection-screen.
Part 5: Variants in Action
Open an existing Web Dynpro which implements a selection screen using component WDR_SELECT_OPTIONS. For this demonstration, we use a selection screen of fields from table SFLIGHT.
Add component ZWDR_SELECT_OPTIONS_VARI as a used component. Name the usage VARIANTS.
View
Add the VARIANTS used component interface controller to the view containing the selection screen,
Methods
In the view containing the selection screen, add the following into hook method WDDOINIT to initialize the variants component usage and link it with the current application and selection screen object. In the code snippet below, the object named selection_screen is the selection screen object obtained from the WDR_SELECT_OPTIONS component usage.
* -- Initialize the select-options variants component usage
DATA(lo_cpuse_variants) = wd_this->wd_cpuse_variants( ).
IF lo_cpuse_variants->has_active_component( ) IS INITIAL.
lo_cpuse_variants->create_component( ).
ENDIF.
* -- Initialize the variants component with this component's name, application and all
* select-options
DATA(lo_ifc_variants) = wd_this->wd_cpifc_variants( ).
lo_ifc_variants->initialize(
component_name = wd_comp_controller->wd_get_api( )->get_component_info( )->get_name( )
application_name = wd_comp_controller->wd_get_api( )->get_component( )->get_application( )->get_application_info( )->get_name( )
select_options_set = VALUE #( ( selection_screen ) )
).
Layout
In the view containing the selection screen, add a ViewContainerUIElement to the layout in the position where you want the variants button to appear. Assign the container ID, VC_VARIANTS.
Window
Lastly, embed interface view W_VARI of used component ZWDR_SELECT_OPTIONS_VARI into ViewContainerUIElement VC_VARIANTS.
Run the Application
Now your selection screen will include a Variants button offering users three familiar options: Get, Delete and Save as Variant.
Get Variant
When the user selects to Get a variant, a search help will guide them to select a variant.
Delete Variant
When the user selects to Delete a variant, a search help will guide them to select one or more variants and a confirmation dialog will confirm the deletion.
Save as Variant
When the user selects Save as Variant, a dialog will prompt them to enter a name and description for their variant.
Hi Amy san
I have a one question about sample coding(initialize the variants),
an error occurred in the following message.....
Field "SELECTION_SCREEN" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. "DATA" statement.....
what is the cause of the error?
regards
azuma
Hi Azuma,
There must be someplace where you are using the field "selection_screen" where it has not yet been defined. If you click on the error message in SAPgui, the IDE should bring you to the location of the error.
Cheers,
Amy
Hi Amy san
The point of my question is about the following sample code;method WDDOINIT…
DATA(lo_ifc_variants) = wd_this->wd_cpifc_variants( ).
lo_ifc_variants->initialize(
component_name = wd_comp_controller->wd_get_api( )->get_component_info( )->get_name( )
application_name = wd_comp_controller->wd_get_api( )->get_component( )->get_application( )->get_application_info( )->get_name( )
select_options_set = VALUE #( ( selection_screen ) )
).
Is this selection_screen a reserved word? Or is it necessary to declare?
Regards
azuma
Hi Azuma,
That variable name is only a place holder. This final chapter of the series details how to add the variants feature to an existing web dynpro component which already uses a selection-screen. The code snippet is meant to be added into whichever view uses the IF_WD_SELECT_OPTIONS object. It is this object which is represented by the placeholder, selection_screen.
I hope that helps to clarify.
Cheers,
Amy
Amazing post Amy, well done. Can't thank you enough.
Thanks very much Chad!
Hi Amy,
I am facing one issue to set back the value in the selection screen of the calling component when the "GET" variant is selected.To achieve this, do we have to call the VARIANT_GET method of used component controller in the using component controller? I understand we have set the select_options_ref in the component controller attribute, but how can we access that.
Thanks
Ishita
Hi Ishita,
Take a look in Part 5 at the WDDOINIT hook method of the view which contains your selection screen. Make sure the used component is properly initialized there and is passed the reference to your selection screen object. See my reply above to Azuma for clarification on the selection screen object meant by VALUE #( ( selection_screen ) ) .
Cheers,
Amy
Hi Amy,
Thanks alot for the quick response.I have placed the below code in the WDDOINIT Hook method of my selection screen component.But it is not identifying wd_this->m_handler as placeholder .Please help.Much thanks on this.
Hi Ishita,
Here is an example of the wddoinit method of a view that uses both a select-options component and the variants component as component usages. Note that it is lo_select_options that is used to initialize the variants component and how that object is obtained.
I hope that helps. Good luck!
Amy
Hi Amy,
Thank you very much for the quick response.Really appreciate it.The VALUE keyword is not found in my release.I suppose that is creating an issue here.As also inline data declaration is not working for me.Can you suggest any other alternate option to achieve this.90% of my development is completed as per your blog.Please suggest further.
Thanks
Ishita
Hi Ishita,
The parameter select_options_set expects a table of type zwdr_select_options_set.
Statement chaining is introduced in NW 7.0 EhP 2 and inline declarations in 7.40.
is equivalent to:
The application name is retrieved in a similar fashion. You can follow along with this blog for a step-by-step.
Cheers,
Amy
Hi Amy,
Again thanks for your reply. I understand the inline declaration is not supported and i have used the old declaration pattern in my code.
My only issue here is how the data of select options can be passed to and from used variant component.For me the VALUE keyword in below statement is not working.
select_options_set = VALUE #( ( lo_select_options ) )
If i use below code will that work, in place of above line.lt_select_options is of type zwdr_select_options_set.
select_options_set = lt_select_options_set
If yes than how wil i pass screen data to VARIANT_SAVE method.Any HOOK methods we can use?
Thanks
Ishita
Hi Amy,
Thank you so uch for your prompt response and help.I could successfully implement the component.It now works as required.Will look out for more post from you always.
Thanks
Ishita
Amy,
What about the new WD_SELECT_OPTIONS_20 component? It seems to come with a built in function for Saved Searches...
The demo example WDR_TEST_SEL_OPT_AUTO_20 shows this, however it doesn't show how to code the save and retrieve functions.
Do you have any idea how to invoke the built-in Saved Searches function in SELECT_OPTION_20?
Thanks
Ramin.
Hi Ramin,
You’re correct! Component WD_SELECT_OPTIONS_20 does support saving select-options settings for applications using UI Guidelines 2.0 and above. This blog describes how to add the same behavior to applications using the older component WDR_SELECT_OPTIONS and UI Guidelines 1.x.
You can do a where-used search to see how applications are using the new component.
Cheers.
Thanks for your response Amy. But the only components that use the Saved Search functionality of SELECT_OPTION_20 are FPM apps, which use the logic in FPM framework for saving/loading searches, ie. function modules: FPM_LOAD_SEARCH, FPM_SAVE_SEARCH.
The only non-fpm app is the demo sample WDR_TEST_SEL_OPT_AUTO_20, which manually sets up hard-coded saved-searches:
I really don't get the value of this example. Do they want us to hard-code saved-searches? or build our own logic to save searches to a Z table and read them?
Thanks
My organization isn't yet using UI Guidelines 2.0 so we aren't yet using WD_SELECT_OPTIONS_20. SAP documentation or the support portal may have documentation on implementing the save feature, but probably the FPM examples you found provide a good template for development.
Good luck!
Thanks Amy.
I did do a lot of searching in support portal, that's how I got to your blog 🙂 You come up as number one in the search! There are zero documentation on saved-searches for WD_SELECT_OPTIONS_20.
But I did see a few posts from people with the same question as me, everyone's wondering if they have to build their own persistence logic or not. Wish there was at least a Yes/No direction from SAP.
Anyways, thanks.
This is fantastic! Thanks Amy.