2012-03-19

WD Screen Variants - Component Usage

overview

<< previous

This is the last installment of this series.  Although it took some time, I enjoyed putting it together and hope you found it useful.

The concept of a selection screen variant is something that most SAP users have come to expect, yet this feature is unavailable in standard Web Dynpro. Below is the next in a series of posts detailing how to bring this necessary feature back to Web Dynpro. Start here to see the full requirements.

Now I’m going to show how easy it is to use the variant component in your own Web Dynpro component.  Start off by creating a new Web Dynpro component that uses one or more components of type WDR_SELECT_OPTIONS and this custom variant component.

Component's used components

In your view Layout, add a ViewContainer UI element.  In the associated window, right-click on the ViewContainer and embed the ZES_SELOPT_VARIANT component.

Embed view

In your view Context, create a new controller usage of both Select Options and the Variant components.

Component usages

In your view WDDOINIT method, initialize the Select Options component just as you would any other time.  My method looks like this.

   1: METHOD wddoinit .                                           " PLM8034
   2:  
   3:   DATA: lr_controller                 TYPE REF TO if_wd_controller.
   4:   lr_controller ?= wd_this->wd_get_api( ).
   5:   wd_this->m_msgman = lr_controller->get_message_manager( ).
   6:  
   7:   me->init_alv( ).
   8:   me->init_selection_screen( ).
   9:   me->init_variant_selector( ).
  10:  
  11: ENDMETHOD.

After initialization of the selection screen, you must initialize the ZES_SELOPT_VARIANT component. After creating the component usage, you get a handle to the interface and do both of the following:



  1. Set the program name.  All variants are saved against this report id.

  2. Append one or more selection screens to the variant.  All fields from all selection screens are available within the variant.  An important caveat: if you attach more than one selection screen to the variant, you must manage distinct field names.


   1: METHOD init_variant_selector .                              " PLM8034
   2:  
   3:   " create the used component
   4:   DATA l_cmp_usage                    TYPE REF TO if_wd_component_usage.
   5:   l_cmp_usage = wd_this->wd_cpuse_variant( ).
   6:   IF l_cmp_usage->has_active_component( ) IS INITIAL.
   7:     l_cmp_usage->create_component( ).
   8:   ENDIF.
   9:  
  10:   " get a pointer to the interface controller of the component
  11:   wd_this->m_wd_variant = wd_this->wd_cpifc_variant( ).
  12:  
  13:   wd_this->m_wd_variant->set_report_name( 'ZEMR_GCS_REPORT_RPT6' ).
  14:   wd_this->m_wd_variant->append_selopt_screen( wd_this->m_selopt1 ).
  15:   wd_this->m_wd_variant->append_selopt_screen( wd_this->m_selopt2 ).
  16:  
  17: ENDMETHOD.

It’s really that easy.  Save and activate your component and you’ll have a robust selection screen with classic variant functionality.


Report Selection Screen


Thanks for reading about it.  Feel free to drop a comment with questions or suggestions.






overview

<< previous

3 comments:

  1. Hello Jeff !

    Thanks a lot for these very useful posts on WD selection-screen variants, that's an awesome solution :)

    Do you have a .nugg file of the all package importable through ZSAPLINK to check the expected result in case one step is no properly followed manually ?

    Thanks in advance for your answer :)


    PEB

    ReplyDelete
    Replies
    1. PEB - I created an SDN project for it - join the group. If you make any improvements to the solution, please let me know so we can share the benefits.

      https://cw.sdn.sap.com/cw/groups/wd-selection-variant

      Delete
    2. Thank you so much for initiating this SDN project Jeff ! I'm quite new in Webdynpro development but I work with other persons who are experimented in WDA though PLM development and for sure we'll look for some improvements and share it in your SDN project :-)

      PEB

      Delete