Skip to Content

The link to first 2 blogs are as following.

Creating and using Variant in Select Options with Web Dynpro for ABAP -1

*

Creating and using Variant in Select Options with Web Dynpro for ABAP -2

*

Our example consists of one *Main *View having two select options, one for customer and other for plant.  It has 2 buttons, one to save variant and other to get variants.  There are 2 others views, Save_Variant_1 ( for saving dialog) and other is Get_Variant_1 ( for showing the list of available variants and let user choose one).The example WDA component will use WDR_SELECT_OPTIONS as used component.

The 3 following attributes are also added to all 3 views.

M_HANDLER type ref to IF_WD_SELECT_OPTIONS ( to keep the instance of select option handler class) 0.1.

RANGE_TABLE_CUST type ref to data ( to keep range table of customer select option) 0.1.

RANGE_TABLE_PLANT type ref to data ( to keep range table of plant select option)The code does the following.

0.1.

1. When user clicks on Get Variant button in the main view, the on Action event associated with the button is executed which in turn fires the outbound navigational plug. The values of all 3 attributes (given above) are passed as export parameters.!https://weblogs.sdn.sap.com/weblogs/images/6086/mainView4.gif|height=131|alt=image|width=346|src=https://weblogs.sdn.sap.com/weblogs/images/6086/mainView4.gif|border=0!

method+ *ONACTIONON_GET_VARIANT *.

  wd_this->fire_out_to_get_variant_plg(

    m_handler         =  wd_this->m_handler        + ” Ref to if_Wd_Select_Options+

    range_table_cust  =  wd_this->range_table_cust  ” Ref to data

    range_table_plant =  wd_this->range_table_plant ” Ref to data

  ).

+endmethod.

methodHANDLEIN_GET_VARIANT_1 .

wd_this->m_handler = m_handler.

wd_this->range_table_cust = range_table_cust.

wd_this->range_table_plant = range_table_plant.

+endmethod.

0.1.

3. The view *Get_variant_1 contains *a context node (with cardinality 0..N). This node contains 3 children attributes i.e. Variant, description and Global Indicator. This context node will be used to store and display available variants for given WDA component. !https://weblogs.sdn.sap.com/weblogs/images/6086/get_variant_view_context.gif|height=1|alt=|width=1|src=https://weblogs.sdn.sap.com/weblogs/images/6086/get_variant_view_context.gif|border=0!image

4.  The WDModifyView method of the view figures out the name of component andread table INDX with key having pattern as name of component. It gets the name, global indicator and description of variants by reading PGMID field of table INDX. It creates an internal table of variants and binds it to node VARIANTS_TAB view context node. The code is as following.

METHOD wddomodifyview.—-Get component name<br />  my_component = view->if_wd_controller~get_component( ).<br />  my_component_info = my_component->get_component_info( ).<br />  my_component_name = my_component_info->get_name( ).<br />—-Read all the variants for this component<br />  l_len = strlen( my_component_name ).<br /><br />  if l_len GT 20.<br />  l_prog = my_component_name0(20).

  else.

    l_prog = my_component_name.

  endif.

CONCATENATE l_prog ‘%’ into l_prog.

  SELECT relid srtfd srtf2 pgmid usera INTO TABLE i_variant_rec_key

         FROM indx WHERE relid = ‘YW’

                   AND   srtfd like l_prog.

  CLEAR variant_tab.

—-Only keep global or user’s variant<br />  LOOP AT i_variant_rec_key INTO w_variant_rec_key.<br />    IF w_variant_rec_key-usera NE sy-uname AND<br />       w_variant_rec_key-pgmid15(1) NE ‘/’.<br />      DELETE i_variant_rec_key INDEX sy-tabix.<br />    ENDIF.<br /><br />    CLEAR stru_variants_tab.<br />    MOVE : w_variant_rec_key-pgmid0(14)  TO stru_variants_tab-variant,<br />           w_variant_rec_key-pgmid16(24) TO stru_variants_tab-description.<br />    IF w_variant_rec_key-pgmid15(1) = ‘/’.<br />      stru_variants_tab-global = ‘X’.<br />    ENDIF.<br />    APPEND stru_variants_tab TO variant_tab.<br />  ENDLOOP.<br /><br />  CALL METHOD node_variants_tab->bind_table<br />    EXPORTING<br />      new_items = variant_tab.<br /><br />ENDMETHOD.</p><p>5. The view will show a table of variants. There will be 2 buttons on the view. When the user chooses one button and click OK the following code will be executed. This code use statement import … from database statement to get the variant data. It updates the attributes (range tables and handler) with variant values and fires the outbound plug to go to main along with the parameter.</p><p>!https://weblogs.sdn.sap.com/weblogs/images/6086/ChooseVariantscreen.gif|height=230|alt=image|width=337|src=https://weblogs.sdn.sap.com/weblogs/images/6086/ChooseVariantscreen.gif|border=0!</p><p>METHOD onactionon_click_ok .<br />  DATA:<br />    node_variants_tab                   TYPE REF TO if_wd_context_node,<br />    elem_variants_tab                   TYPE REF TO if_wd_context_element,<br />    stru_variants_tab                   TYPE if_get_variant_1=>element_variants_tab ,<br />    item_variant                        LIKE stru_variants_tab-variant,<br />    my_component       TYPE REF TO if_wd_component,<br />    my_component_info  TYPE REF TO if_wd_rr_component,<br />    my_component_name  TYPE string,<br />    l_prog             TYPE indx-srtfd,<br />    l_id               TYPE indx-srtfd,<br />    l_pgmid            TYPE indx-pgmid,<br />    r_cust             TYPE RANGE OF kunnr,<br />    r_plant            TYPE RANGE OF werks_d,<br />    l_len              type I.<br /><br />field-SYMBOLS <fs> type ANY TABLE.<br />   navigate from —-Get component name<br />  my_component = WD_COMP_CONTROLLER->wd_get_api( ).<br />  my_component_info = my_component->get_component_info( ).<br />  my_component_name = my_component_info->get_name( ).<br />—-Read all the variants for this component

  l_len = STRLEN( my_component_name ).

  IF l_len GT 20.

    l_prog = my_component_name0(20).<br />  ELSE.<br />    l_prog = my_component_name.<br />  ENDIF.<br /><br />  CONCATENATE  : l_prog ‘%’ INTO l_prog,<br />                 item_variant ‘%’ INTO l_pgmid.<br />  SELECT  srtfd INTO l_id UP TO 1 ROWS<br />           FROM indx WHERE relid = ‘YW'<br />                     AND   srtfd LIKE l_prog<br />                     AND   pgmid LIKE l_pgmid.<br />    EXIT.<br />  ENDSELECT.<br /><br />  IF sy-subrc = 0.<br />    IMPORT r_cust = r_cust r_plant = r_plant<br />           FROM DATABASE indx(yw) ID l_id.<br />    if sy-subrc = 0.<br />      assign wd_this->range_table_cust->* to <fs>.<br />      <fs> = r_cust.<br />      ASSIGN wd_this->range_table_plant->* to <fs>.<br />      <fs> = r_plant.<br />    endif.<br />  ENDIF.<br /><br />  wd_this->fire_to_main_plg(<br />    range_table_cust =   wd_this->range_table_cust              ” Ref to data<br />    range_table_plant  =   wd_this->range_table_plant           ” Ref to data<br />  ).

 

6. The associated method of inbound navigation plug of view Main calls select option handler method to set the range tables of select options. Now the view is populated from the values coming from variant.

!https://weblogs.sdn.sap.com/weblogs/images/6086/mainView5.gif|height=132|alt=image|width=345|src=https://weblogs.sdn.sap.com/weblogs/images/6086/mainView5.gif|border=0!</body>

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Anonymous
    Hello Sharad,

    This is a great real-world scenarios with ABAP Webdnpro. Blogs like these are of great use to developers especially around the newer Netweaver areas.Good Job!

    Expecting more like these from u. Keep Blogging..

    Best Regards,
    Naveen

    (0) 
  2. Developer General
    Hello Sharad,
    thank You very much for your great method to save
    and get variant .
    May be You can advice me how get and save inside variant settings of report, that is one of views
    that we saved for users.

    Thank You very much and best regards
    Irena

    (0) 
  3. Xavier .
    Hi Sharad,

    Thank you for posting the Blog, The best Blog which i have seen so far in SDN

    Keep it up————

    Regards

    Xavier

    (0) 

Leave a Reply