cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Variables from one View to another

Former Member
0 Kudos

First of all Hi this is my first post on the sap forums.

Aplogies if I have come to the wrong place or if this question is very easy, but I am new to abap and web dynpro and have found myself struggling a little bit. So I stumbled across this site and thought I would ask for help.

My problem is this, I have 2 variables on my MAIN view, one called MONTH and the other called YEAR. What I want to do is on a button click on the MAIN view pass the values of these variables to another view called SUMMARY_RPT and then use these variables in an SQL query I have on this view.

Anybody out there that can help ?

Many Thanks,

George

Accepted Solutions (1)

Accepted Solutions (1)

arjun_thakur
Active Contributor
0 Kudos

Hi George,

Welcome to webdynpro abap community. To pass data from one view to another, you can should create two attributes (type string) in the attribute tab of of the component controller. Now these will act as global variable for you. Now you can access these attribute in your view in this way:


wd_comp_controller->gv_val "gv_val is the name of the attribute

Populate the value in it and use it anywhere you want.

There is one more way to do the same.

Create a node under context in component controller and create 2 attributes(type string) after that. Map this node to both the views. Now get the value of month , year and set these attribute with the same values with the help of code wizard in view 1. Now in the view2 simply read those attribute and you'll get the value of month and year which was entered in the first view. Read the attribute with the help of code wizard. Now you can use them accordingly.

I would suggest you to use 1st method as it is better performance wise.

I hope it helps.

Regards

Arjun

Answers (2)

Answers (2)

Former Member
0 Kudos

Apologies I forgot to ask one last question...

Any ideas how I assign my attribute in my context controller to my 2 textboxes because at the moment my variable contains null ?

Many Thanks,

George

Edited by: George Georgiou on Mar 18, 2009 10:57 AM

arjun_thakur
Active Contributor
0 Kudos

George,

If you have to get the input from the user then I would suggest that you should create a node under in context tab of the component controller and create two context attribute under it. Map this node to both the views. Now bind the value property of the inputfield with these context attribute. Then in view 2, press Ctrl+f7 and read these context attributes. and use them accordingly

Regards

Arjun

Former Member
0 Kudos

Great have done it now, thank you for all your help Arjun, I have awarded you some points.

arjun_thakur
Active Contributor
0 Kudos

Welcome George.

Regards

Arjun

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi

You must be navigating from one view to other view.

You might have created Outbound plug in View1 , Inbound Plug in View2.

go tothe Outbound Plug tab in View1, and at the down add parameter Month type your time

Year type your type

pass these two parameters where you are firing the outbound plug.

go to the Second View choose inbound plug tab and go to your inbuond plug event handler method.

Manually add two parameters Month of your type, Year of your type.

and simply inside the method access Month and Year.

Abhi

Former Member
0 Kudos

Thank you very much for the fast responses and great welcome

I have tried to do what you guys have suggested, I have added 2 fields in the component controller under a node called FINPERIOD and have added 2 attributes named PERIOD and GJAHR - I have also assigned these attributes to the relevant textboxes on my first view.

On my second view I am trying to use the variables in this way as the second poster suggested :-

wd_comp_controller-> "attribute name goes here

But I am unsure as to what the attribute name is, is it the name of the attribute in the component controller or is it the name of the textbox ?

Again, sorry if I am not making myself clear I am still trying to come to grips withweb dynpro.

arjun_thakur
Active Contributor
0 Kudos

George,

You said that you have create two attributes under a node and you have binded it with the UI elements. Map that node with second view as well. So now in second view, press ctrl+F7 and read the attribute which you have created. Code will be generated and in a variable you'll get the values which were entered in the first view.

Regards

Arjun

Former Member
0 Kudos

Arjun,

Sorry I worded my last post wrong. I have created 2 new attributes in the 'attributes' tab of the context controller named MONTH and YEAR. I can now use the variabled in my second view with the following statement:

wd_comp_controller->MONTH & wd_comp_controller->YEAR

I dont get a error message when I activate so I think all is working ok... fingers crossed!

Many Thanks for you help guys.

Regards,

George