Skip to Content
Author's profile photo Amy King

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.

Assigned Tags

      20 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kazuo Azuma
      Kazuo Azuma

      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

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      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

       

      Author's profile photo Kazuo Azuma
      Kazuo Azuma

      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

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      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.

      In the code snippet below, the object named selection_screen is the selection screen object obtained from the WDR_SELECT_OPTIONS component usage.

      I hope that helps to clarify.

      Cheers,
      Amy

      Author's profile photo Chad Schmidt
      Chad Schmidt

      Amazing post Amy, well done.  Can't thank you enough.

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      Thanks very much Chad!

      Author's profile photo Ishita Shah
      Ishita Shah

      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

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      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 ) ) .

        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 ) )
        ).

      Cheers,
      Amy

      Author's profile photo Ishita Shah
      Ishita Shah

      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.

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      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.

      METHOD wddoinit.
      
      * -- Initialize the select-options component usage
      
        DATA(lo_cpuse_select_options) = wd_this->wd_cpuse_select_options( ).
      
        IF lo_cpuse_select_options->has_active_component( ) IS INITIAL.
          lo_cpuse_select_options->create_component( ).
        ENDIF.
      
      * -- Add fields to the select-options
      
        DATA(lo_ifc_select_options) = CAST iwci_wdr_select_options( lo_cpuse_select_options->get_interface_controller( ) ).
        DATA(lo_select_options) = lo_ifc_select_options->init_selection_screen( ).
      
      * Carrier
        lo_select_options->add_selection_field(
          i_id             = 'CARRID'
          it_result        = lo_select_options->create_range_table( 'S_CARR_ID' )
          i_suggest_values = abap_true
        ).
      
      * Connection
        lo_select_options->add_selection_field(
          i_id             = 'CONNID'
          it_result        = lo_select_options->create_range_table( 'S_CONN_ID' )
          i_suggest_values = abap_true
        ).
      
      * -- 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 #( ( lo_select_options ) )
        ).
      
      ENDMETHOD.

      I hope that helps. Good luck!

      Amy

      Author's profile photo Ishita Shah
      Ishita Shah

      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

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      Hi Ishita,

      The parameter select_options_set expects a table of type zwdr_select_options_set.

      DATA lt_select_options_set TYPE zwdr_select_options_set.
      
      APPEND lo_select_options TO lt_select_options_set. 
      
      lo_ifc_variants->initialize(
        component_name     = ...
        application_name   = ...
        select_options_set = lt_select_options_set
      ).

      Statement chaining is introduced in NW 7.0 EhP 2 and inline declarations in 7.40.

      DATA(lv_name) = wd_comp_controller->wd_get_api( )->get_component_info( )->get_name( ).

      is equivalent to:

      DATA lo_component TYPE REF TO if_wd_component.
      DATA lo_comp_info TYPE REF TO if_wd_rr_component.
      DATA lv_name TYPE string.
      
      lo_component = wd_comp_controller->wd_get_api( ).
      lo_comp_info = lo_component->get_component_info( ).
      lv_name = lo_comp_info->get_name( ).
      

      The application name is retrieved in a similar fashion. You can follow along with this blog for a step-by-step.

      Cheers,
      Amy

      Author's profile photo Ishita Shah
      Ishita Shah

      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

      Author's profile photo Ishita Shah
      Ishita Shah

      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

      Author's profile photo Ramin Shafai
      Ramin Shafai

      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.

       

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      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.

      Author's profile photo Ramin Shafai
      Ramin Shafai

      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

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      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!

      Author's profile photo Ramin Shafai
      Ramin Shafai

      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.

      Author's profile photo Paul Dunk
      Paul Dunk

      This is fantastic!  Thanks Amy.