cancel
Showing results for 
Search instead for 
Did you mean: 

Pass value from 1 view to other view

former_member248300
Participant
0 Kudos

Hello Friends,

I am new to ABAP dynpro, I am working on one sample program. I have created 2 views, in 1st view I have 2 input fields and go button. In second view, 1 input field and 'back button'. I want to enter 2 numbers in 1st view and multiply it and display it in 2nd view.

Please help to achieve this functionality.

Thanks,

Shreekant

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, This is pretty simple. Create an attribute in the component controller and mark it as public. ( Now this is your global attribute and can be accessed across views ) Now in your first vew, in your onAction method for the button store your result in this variable as follows:

wd_comp_controller->attribute_name = a1 * a2.
Now in your view 2, wd_comp_controller->attribute_name will contain the result of multiplication. Regards, Radhika.

former_member248300
Participant
0 Kudos

Hi Radhika,

Thanks for the reply, If I have result in 'wd_comp_controller->attribute_name', then how will I display it in my 2nd view text field?

Please reply me.

Thanks,

Shreekant

Former Member
0 Kudos

You must have bound your textview with an attribute which is under a node, right ? So just set that attribute as follows;

data: l_node type ref to if_Wd_context_node.

l_node = wd_context->get_child_node( 'NODENAME' ).
l_node->set_Attribute(  exporting name = 'ATTRIBUTE' "attribute bound to textview
                                                     value = wd_comp_controller->attribute_name ).
Regards, Radhika.

former_member248300
Participant
0 Kudos

Hi Radhika,

Sorry for troubling you.. Here is the code I have written for OnAction on Button. (for view1(input_view))

method ONACTIONGOTO_RESULT .

DATA lo_el_context1 TYPE REF TO if_wd_context_element.

DATA ls_context1 TYPE wd_this->element_context.

DATA lv_zint1 LIKE ls_context1-zint1.

  • get element via lead selection

lo_el_context1 = wd_context->get_element( ).

  • get single attribute

lo_el_context1->get_attribute(

EXPORTING

name = `ZINT1`

IMPORTING

value = lv_zint1 ).

DATA lo_el_context2 TYPE REF TO if_wd_context_element.

DATA ls_context2 TYPE wd_this->element_context.

DATA lv_zint2 LIKE ls_context2-zint2.

  • get element via lead selection

lo_el_context2 = wd_context->get_element( ).

  • get single attribute

lo_el_context2->get_attribute(

EXPORTING

name = `ZINT2`

IMPORTING

value = lv_zint2 ).

  • Multiply 2 numbers

data: l_data type int4.

clear: l_data.

l_data = lv_zint1 * lv_zint2.

  • wd_this->fire_go_to_result_plg( ).

endmethod.

>>> In the above code, I have stored the value in l_data, which I want to populate in result_view.

If I use 'wd_this->fire_go_to_result_plg( ).' in above code, it will go to result_view, but no value is populating.

Please can you provide me the sample code to achieve it...

OR, also let me know if any other simple method to achieve this functionality.

Thanks for the help.

Regards,

Shreekant

Former Member
0 Kudos

Hi Shreekant

Suppose you have three attributes under node in component controller

node1

ZINT1

ZINT2

ZINT3

from your code reult is in l_data

Add declaration as

DATA:

node TYPE REF TO if_wd_context_node,

elem TYPE REF TO if_wd_context_element,

stru_elem TYPE <your viewname>=>element_node1.

item LIKE stru_elem-ZINT3.

node = wd_context->get_child_node(u2018node1u2019).

elem = node->get_element( ).

elem->get_attribute(

exporting

name = 'ZINT3'

importing

value = item ).

write your logic and move the l_data to item (item = zint1 * Zint2 )

elem->set_attribute(

name = u2018ZINT3u2019

value = item ).

wd_this->fire_go_to_result_plg( ).

then bind the ZINT3 to the textfield of view2.

Please chek out this link

https://www.sdn.sap.com/irj/sdn/nw-ui?rid=/webcontent/uuid/fed073e5-0901-0010-4eb4-c9882aac7b11 [original link is broken]

Thanks

Tulasi Palnati

Edited by: Tulasi Palnati on Jul 28, 2009 8:15 AM

Former Member
0 Kudos

Hi Shreekanth, As suggested in my earlier reply, declare l_data in Component Controller's -> Atrribute Tab. Mark it as Public. and

l_data = lv_zint1 * lv_zint2 
" Change the above statement to as shown below
wd_comp_controller->l_data = lv_zint1 * lv_zint2.

" now in your view 2 wd_comp_controller->l_data will contain the result
Regards, Radhika.

former_member248300
Participant
0 Kudos

Thanks Radhika and Tulasi,

I could able to solve the issue...

I also added 2 more new views and could able to pass values between views.

Thanks again,

Shreekant

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Create three context attributes in the component controller

Map the context of component controller to view1 and also to view2

Design the layoout as per your requirement.

Create Outboundplug for view1

Create one action to view1 and bind the action to buttonwrite your busines logic and call the Outbound plug here.

Desgin the view2 as per your requirements and bind the values from the context.

create an inbound plug for view2.

In the method tab you will find out handel<your inbound plug name> event.

Now in the window create the navigation links from view1 to view2.

Create the Web Dynpro application. Save it and activate all.

Now test your application

Thanks

Tulasi

Edited by: Tulasi Palnati on Jul 27, 2009 12:47 PM