Skip to Content

This will help  to learn how to pass parameter values from Window to View and View to View.

There are two Views (View_One and View_Two), Component Controller, Window (Main_Window) and a custom Controller ZEMP_CUST_CONTROLLER. Component controller has Node – Node_EMP1 with attributes NAME, CITY and STATE. Similarly ZEMP_CUST_CONTROLLER has node NODE_EMP2 with attributes ENAME, ECITY and ESTATE. View_One is mapped with component controller context and View_Two is mapped with ZEMP_CUST_CONTROLLER context. The views are embedded in Main_Window which has an outbound plug OB_WINDOW with parameters p_name, p_city and p_state.

When we enter the data in View_One and click on ACTION button those values will be passed to Outbound plug parameters and navigate to View_Two. In View_Two we will fetch those parameters and update the Custom controller context.

Create a Component Controller node NODE_EMP1 with attribute NAME, CITY and STATE.

Componenet_Controller.Jpg

Create a Custom Controller ZEMP_CUST_CONTROLLER node NODE_EMP2 with attribute ENAME, ECITY and ESTATE.

Custom_Controller.JPG

Create View_One, map the component controller context into it.

Contextmapping_View1.Jpg

Lay out of View_One

Layout_View1.Jpg

Create View_Two, click on controller usage add the custom controller ZEMP_CUST_CONTROLLER. Map the node from ZEMP_CUST_CONTROLLER to the context of the View_Two.  

Contextmapping_View2.Jpg

Create Inbound plug in View_Two.

View2_Inbound.jpg

Layout of View_Two

View2_layout.Jpg

Now we have to include window controller in both views, then only we can access the methods specified in window. For that we have to go to properties tab of Views. Click on create controller usage button, then a popup will come and select the window controller from that and click OK.

Property_tab_View1.Jpg

Property_View2.Jpg

Now If you want to pass the data through Window parameter

Create an outbound plug in Window with parameters. Here there are three importing parameters which will get value from View_One and pass it into View_Two.

Window_Outbound.Jpg

Next we have to embed the views in Window and link the plugs. Outbound plug of window is linked with Inbound plug of View2.

Window.jpg

Save Main_Window.

While clicking on the button in the View_One it should move to View_Two. Before that we have to read the context NODE_EMP1 and get the values given in View_One. Those values are passed as to the plug parameters. The following code will do that.

method onactionclick .
        data:
          node_node_emp1                      TYPE REF TO if_wd_context_node,
          elem_node_emp1                     TYPE REF TO if_wd_context_element,
          stru_node_emp1                      TYPE                if_view_one=>element_node_emp1 .
*       navigate from <CONTEXT> to <NODE_EMP1> via lead selection
        node_node_emp1 = wd_context->get_child_node( name = if_view_one=>wdctx_node_emp1 ).

*       get element via lead selection
        elem_node_emp1 = node_node_emp1->get_element(  ).

*       get all declared attributes
        elem_node_emp1->get_static_attributes(
          importing
            static_attributes = stru_node_emp1 ).

data: l_ref_main_window type ref to ig_main_window .
l_ref_main_window =   wd_this->get_main_window_ctr( ).
  l_ref_main_window->fire_ob_window_plg(
    p_city         =       stru_node_emp1-city         
    p_name     =       stru_node_emp1-name
    p_state      =       stru_node_emp1-state

   ).

endmethod.

And in eventhandler method of  View_Two give the following code. Which will get the value from parameters and pass it to context node NODE_EMP2.

method handleib_view2 .

data: lv_name type string,
      lv_city type string,
      lv_state type string.

wdevent->get_data(
  exporting
    name   = ‘P_NAME’
  importing
    value  = lv_name
       ).

wdevent->get_data(
  exporting
    name   = ‘P_CITY’
  importing
    value  = lv_city
       ).

wdevent->get_data(
  exporting
    name   = ‘P_STATE’
  importing
    value  = lv_state
       ).

  data:
    node_node_emp2                      type ref to if_wd_context_node,
    elem_node_emp2                      type ref to if_wd_context_element,
    stru_node_emp2                      type if_view_two=>element_node_emp2 ,
    item_ecity                          like stru_node_emp2-ecity.
* navigate from <CONTEXT> to <NODE_EMP2> via lead selection
  node_node_emp2 = wd_context->get_child_node( name = if_view_two=>wdctx_node_emp2 ).


node_node_emp2->set_attribute(
*    INDEX  = USE_LEAD_SELECTION
    value  = lv_name
    name   = ‘ENAME’
       ).

node_node_emp2->set_attribute(
*    INDEX  = USE_LEAD_SELECTION
     VALUE  = lv_city
     name   = ‘ECITY’
       ).

node_node_emp2->set_attribute(
*    INDEX  = USE_LEAD_SELECTION
     VALUE  = lv_state
     name   = ‘ESTATE’
       ).
endmethod.

Save it. Create a WD application and Activate. And execute.

Input Screen

input_Screen.JPG

Output screen

Output.JPG

If you want to pass the data through parameters of View.

Create an outbound plug in View1 with parameters.

View1_OB.JPG

Create an Inbound plug in View_Two.

View2_Inbound.jpg

In Window – Outbound plug of view1 should be linked with Inbound plug of View 2.

Win_Plugs.Jpg

Give the Following code in the Onaction click method of View1.

method ONACTIONCLICK .
   DATA:
      node_node_emp1                      TYPE REF TO if_wd_context_node,
      elem_node_emp1                      TYPE REF TO if_wd_context_element,
      stru_node_emp1                       TYPE              if_view_one=>element_node_emp1 .
*   navigate from <CONTEXT> to <NODE_EMP1> via lead selection
    node_node_emp1 = wd_context->get_child_node( name = if_view_one=>wdctx_node_emp1 ).

*   get element via lead selection
    elem_node_emp1 = node_node_emp1->get_element(  ).

*   get all declared attributes
    elem_node_emp1->get_static_attributes(
      IMPORTING
        static_attributes = stru_node_emp1 ).


   wd_this->fire_ob_view1_plg(
     p_city    =                           stru_node_emp1-city
     p_name =                           stru_node_emp1-name
     p_state  =                           stru_node_emp1-state
   ).

endmethod.

In View Two handle method provide the follwoing code.

method handleib_view2 .
  data: name      type string,
        city      type string,
        state     type string.


  name = p_name.
  city = p_city.
  state = p_state.

  data:
    node_node_emp2                      type ref to if_wd_context_node,
    elem_node_emp2                      type ref to
if_wd_context_element,
    stru_node_emp2                      type
if_view_two=>element_node_emp2 ,
    item_ename                          like stru_node_emp2-ename,
  item_estate                         like stru_node_emp2-estate,
  item_ecity                          like stru_node_emp2-ecity.
* navigate from <CONTEXT> to <NODE_EMP2> via lead selection
  node_node_emp2 = wd_context->get_child_node( name =
if_view_two=>wdctx_node_emp2 ).

* get element via lead selection
  elem_node_emp2 = node_node_emp2->get_element(  ).

* get single attribute
  elem_node_emp2->set_attribute(
    exporting
      name =  `ENAME`
      value = name ).


*   navigate from <CONTEXT> to <NODE_EMP2> via lead selection
    node_node_emp2 = wd_context->get_child_node( name =
if_view_two=>wdctx_node_emp2 ).

*   get element via lead selection
    elem_node_emp2 = node_node_emp2->get_element(  ).

*   get single attribute
    elem_node_emp2->set_attribute(
      exporting
        name =  `ESTATE`
        value = state ).

* navigate from <CONTEXT> to <NODE_EMP2> via lead selection
  node_node_emp2 = wd_context->get_child_node( name =
if_view_two=>wdctx_node_emp2 ).

* get element via lead selection
  elem_node_emp2 = node_node_emp2->get_element(  ).

* get single attribute
  elem_node_emp2->set_attribute(
    exporting
      name =  `ECITY`
      value = city ).

endmethod.

  

To report this post you need to login first.

2 Comments

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

  1. Jacob Vennervald

    Hi Pradeep

    Thanks for a good article.

    Can you tell me we I would use outbound-plug on the window for this action and not the outbound-plug on the window???

    In general I’m having a hard time figuring out, when it would make sence to use starndard inbound or outbound plugs in windows, when they are not marked in “interface”?

    Maybe you can shed some light on that?

    /Jacob 🙂

    (0) 

Leave a Reply