cancel
Showing results for 
Search instead for 
Did you mean: 

I have 3 questions

Former Member
0 Kudos

hello everyone

these days I am studying wd4a,I ask many questions in here , and I get answers that I want.

So I must thanks everyone ,thanks you help.

and today I have another 3 question

1,if I define a method in component controller,how can I use it?

if I define a nmethod in view,I know I use wd_this->my_method

I think I need a interface , but I am not sure which one I should use

can you tell me the code?

2,I define a event in component controller,its name is : my_event

I am not sure the next step,

in view , I define a method ,name is my_event_handle,right?

then,double click my_event_handle,implement it

3,I dont know the difference between method and event from myself.

when should I use method?

when should I use self define event?

thanks again.

elisa

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Elisa

1,if I define a method in component controller,how can I use it?

if I define a nmethod in view,I know I use wd_this->my_method

I think I need a interface , but I am not sure which one I should use

can you tell me the code?

you can access component contorller methods by using following code:

say i have a method in component controller called: execute_zbapi, now to access this method inside my view I need a ref object....so I do this:

DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .

lo_componentcontroller = wd_this->get_componentcontroller_ctr( ).

lo_componentcontroller->execute_zbapi( ).

you can use code wizard button to get to the component controller methods...you can start the code wizard by clicking on the button which is right beside the "pattern" button. a pop up window will open...you can select the second option there and get to your component controller methods if you are inside your view....it is a very handy tool...

2,I define a event in component controller,its name is : my_event

I am not sure the next step,

in view , I define a method ,name is my_event_handle,right?

then,double click my_event_handle,implement it

if you want to use events defined in component controller inside view....you need to define an event handler method in your view...and under the event column (on the same scrren where you put in your method name )you need to assign the event you created in component controller....under the event column you can use the F4 help (the little circle button), than select your component...normally you will have only one option there to pick...if you have only one component controller....you can also check this program out...very good example....DEMO_ROADMAP...check how they define the event in component controller and how they used in the "Main" view...

3,I dont know the difference between method and event from myself.

when should I use method?

when should I use self define event?

method can hold logic which you need to use with out any user interaction....events we normally use to capture a user interaction....say clicking on a button or hit of an enter etc...say, you want to navigate to your output view from your input view....when you create an action for this purpose an event handler method gets created automatically for you...there you fire the plug to your out put view...

hope this help....

J.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

1,if I define a method in component controller,how can I use it?

if I define a nmethod in view,I know I use wd_this->my_method

I think I need a interface , but I am not sure which one I should use

can you tell me the code?

Ans:

If you are defining one method in Component controller, that method can be used in the view by calling that method which is defined in the component comtroller.

For eg :

You defined one method named in compoent controller method tab named get_data. this method can be called by clicking the web dynpro code wizard(ctrl + f7) button. in that give the component name in the method call in used controller option and specify the name of the method it will display the code in your method editor tab. the code will like wd_comp_controller->get_data( ).

By this u can call method from component controller.

If u are defing set of methods in the view method tab, those methods can be used by wd_this->method1. no need of interface for calling view methods.

2,I define a event in component controller,its name is : my_event

I am not sure the next step,

in view , I define a method ,name is my_event_handle,right?

then,double click my_event_handle,implement it

no its not like that if u create a event a action is created in the action tab for that event. Events will be created automatically for particular actions.

3,I dont know the difference between method and event from myself.

when should I use method?

when should I use self define event?

event : a event is raised for doing some actions.

method : a method is called for doing some actions.

use method for doing particular actions regularly.

use event for doing the single actions.

Regards,

Ragu.

Former Member
0 Kudos

Hi elisa,

For the difference between method, event refer this below link.

In case if you have used method in the component controller to make use of the this method in the view...

For example : DISPLAY is the method you have used in the component controller.

In the view Method tab

In the Method wddoinit call the method using the code wizard

*Method call in used controller

Define the Controller name and method name..

wd_comp_controller->display( ).

In the weddynpro ABAP 60% of the code is done through the code widzard..The way you define the methods and events and make use of it using the code wizard..

Regards,

Sravanthi

Regards,

Sravanthi

Former Member
0 Kudos

Hi,

1. For calling a component controller method u do not nead to write the code.

Just go in the control wizard and select Method Call in Used Controller .

Now select your component name and method of the component controller.

After pressinf the enter key u will have the code.

2. I am not clear with, what u want actually. please clarify.

3. difference between the event handler and method is that, event handler is called automatically when some event occurs

and method u need to call. For example: when u press a button then some action occurs this is because of the event handler.

Regards

Pankaj Aggarwal

Former Member
0 Kudos

Pls find the answers below:

if I define a method in component controller,how can I use it?

u can call the method using 'Code Wizard' or directly e.g your method name is 'my_method' then you can call..

wd_comp_controller->my_method( ).

Answer of ur 2nd and 3rd question is;

An event is triggered when e.g some user action is triggered, like when u press enter on the screen, an event is triggered or when you press on push button an event is triggered, and if you want to perform some action based on the event, you need to create an Event Hanlder method for that. e.g in this case when a push button is pressed, you can write event handler for push button and write the code directly over there, basically it's a method.

Former Member
0 Kudos

Hello,

Please read this article: [Web Dynpro for ABAP: Tutorial 6 u2013 Component Usage|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/2e71ce83-0b01-0010-11a4-98c28a33195f]

And follow some answers:

Question 1 [Programming Controller Methods|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2fhelp%2fsdn_help_nw04s%2fsaphelp_nw04s%2fhelpdata%2fen%2f1e%2f75e3d86397bc4db8f579d9f020f661%2fcontent.htm].

Question 2 [Events and Event Handlers|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2fhelp%2fsdn_help_nw04s%2fsaphelp_nw04s%2fhelpdata%2fen%2feb%2fed6f4169e25858e10000000a1550b0%2fcontent.htm].

Question 3 [Controller: Methods|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2fhelp%2fsdn_help_nw04s%2fsaphelp_nw04s%2fhelpdata%2fen%2f83%2f0c5ebd79bbf147889bb7384e24ff00%2fcontent.htm].

Regards.