cancel
Showing results for 
Search instead for 
Did you mean: 

syntax

Former Member
0 Kudos

Hi Experts,

I am new to webdynpro aswell as OOP concepts. I have two views..view1 has a method named method1 and view2 has method2. How to access method1 of view1 in method2 of view2. Please let me know the syntax.

Thanks

Mahathi

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Mahathi,

Welcome to WDA! As how Sidh pointed out you cannot call a method of 1 view from within another view. If you intend to have such methods which can be called form multiple views then you need to put them at the component controller level or create a global class for the same. At view level you need to put in coding which is only related to that particular view as per good MVC practice. It would be great if you can incorporate this approach from your learning stage itself.

If you have created the method at component controller level then you can make use of this method in any of the views within your component. You can also checkmark the "Interface" checkbox beside the method to make this method available via the interface to other external web dynpro components.

If the component controller is declared as a used controller on the Properties tab of any other controller, an additional attribute is automatically created for the controller that declared the usage:

WD_COMP_CONTROLLER is the reference to the component controller. Using this reference, all methods and all public attributes of the component controller can be accessed (wd_comp_controller-><meth>, where

<meth> is a placeholder for the methods name).

Regards,

Uday

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Mahathi,

You can create methods in component controller, which will be accessable globally.

This will improve re-usability of your code and make it simple. In this way you can acces it from all the views.

To write Method in component controller,

1. Create a Web Dynpro Application.

2. Double click on Component Controller.

3. Go to methods tab.

4. Write the method and activate it.

Now Go to the view method and click the code Wizard

-> Method call in used controller

-> Give controller name

-> Now you can select the method

Hope this will be helpful.

pranav_nagpal2
Contributor
0 Kudos

hi mahathi,

write the method in component controller and then access that method in both the views, as component controller is global thing in WD abap...... to access the method from component controller you can use code wizard........

also you have to write code in view only if it is specific to view.. it is not recommended to write any business logic in view.... hope you are not writing...

regards

Pranav

Edited by: Pranav Nagpal on Dec 2, 2008 6:53 AM

Former Member
0 Kudos

Hi,

You can not access the method of the one viw in the other.

To Access method globally, you have to write method in component controller. then you can call method using the code wizard( control key + F7 ) --> Radio button method call in used component.

OR

thru reference available to the component controller in your view attributes i.e. WD_COMP_CONTROLLER


  DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
  lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).

  lo_componentcontroller->g_method(
  ).

OR


  wd_comp_controller->g_method().