cancel
Showing results for 
Search instead for 
Did you mean: 

A question about wd_this

Former Member
0 Kudos

Hi

I tried searching for this but couldn't find an answer.

Now how come for attributes and context elements of a view we always need to prefix wd_this-> but not for methods? Something to do with if_main being a self reference?

Thanks

Pushpraj

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I wish people read the question before hastening to answer.

Suppose we have an attribute declared in the view (under the attributes tab) viz gv_name. Also we have a method called save_data.

Now I use the attribute like wd_this->gv_name. But I can use the method both as wd_this->save_data( ) and simply save_data( ).

Why so?

Pushpraj

TomVanDoo
Active Contributor
0 Kudos

I can't tell for 100% sure, but compare it to plain abap objects

If in a class we have a global attribute "something"

and now in a method of this class, we also have a local attribute "something" (same name)

me->something then refers to the global attribute, whilst something refers to the local attribute (prioritization)

None the less, you can call a method without the me-> reference, because a method is always globally in a class.

coming back to the WDA framework where every controller is a locally defined class within the global component class, I believe that the WD_THIS is actually a failsafe to distinguish between global attributes (of the local class) and local attributes of the method (of the local class)

whereas for methods, there can't be any mixup...

(disclaimer:I tried to explain my thoughts as clear as possible. Knowing how chaotic my thoughts sometimes are, the explanation might still be blurry)

Former Member
0 Kudos

Thanks Tom.

Here's what I feel after having done a bit of testing in my WDC.

In fact we can declare attributes with the same name in the component controler and view. The former being called by prefixing wd_comp_comtroller->. Same for methods too.

View attributes need to be prefixed with wd_this-> so as to distinguish them from local variables which may hold the same name. As for methods we can't have any definitions inside other methods and so no chance for a mixup there.

Anyway, thanks.

Pushpraj

ChrisPaine
Active Contributor
0 Kudos

Pushpraj,

I'm equally as confused - even your last post doesn't really answer why we need this.

In a class you can have a class attribute and a local method variable - and there is no prefix that we must use to get access to the class attribute.

I think you have to go back to the WD Java origins of WD ABAP - in WD Java there was/is declared in the component and view classes a reference to a variable "wdThis" which has pointers to the component api. When they built WD ABAP they needed somewhere to store the various class attributes (in much the same way as Java) and they came up with the "attributes" tab.

Now this is where I'm lost - in WD Java to define a new attribute of the class - you do just that - you have no need to reference it back to wdThis...

I think it comes down to the interface tick (the ability in WD ABAP to expose a class attribute globally) (I guess it had to happen - half the ABAP coders out there still think in terms of GLOBAL variables) - in WD Java you'd use a setter and getter method were you wanting to change/get a class attribute (and even there potentially you should instead be using the context? - why have two different methods of data transfer within the same code) - whereas ABAP doesn't really bother - in order to allow access to the attributes via the compiled external reference presented to other classes (internally to the class wd_this ) is generated. And here I think the guys who built the compiler/code checking tools got lazy - they found it easier just to redirect all class attribute checking to the wd_this interface - rather than build an internal representation.

But in truth - it's not that hard to type wd_this->blah... sometimes it's even nice in ABAP classes to refer to me->blah just to reinforce that the variable is a class attribute ( not that ABAP allows variable overloading ).

I find issues such as no forward creation of methods/attributes/messages etc by double clicking on the code I've written to be a much bigger issue, and far more irritating.

Sorry this probably didn't answer your question - but it was an interesting question and I just wanted to add a little to it.

Perhaps some of the developers who I've accused of being lazy when they developed this requirement to have wd_this when referencing the class attributes will stand up and explain better why they did this!

Former Member
0 Kudos

Well you lost me there a bit Chris.

But thanks for that insight into the developers's minds.

Pushpraj

Former Member
0 Kudos

hi Pushpraj Singh

wd_this is an implicit object created by SAP. If you use this in component controller methods this wd_this refers to component controller. If u use in view mehtods that refers to view controller. Instead of using this you can create your own instance like IF_wd_COMPONENTCONTROLLER and access the attributes. simillary for view also.

Former Member
0 Kudos

HI,

wd_this is used to refer the local interface(Which is depends on the controller like view,component).

You can use this attribute to point to the local attributes and methods.


Life cycle methods(WDDOINIT, WDDOMODIFY etc) and action methods and plug handle methods
cannot be explicitly called by wd_this becasue they will be triggered by WDA environment.

Note: You can declare a user method manually in methods tab of the view and call using wd_this.

For more information refer to this link.

[Wd_this|http://help.sap.com/saphelp_nw70ehp2/helpdata/en/47/c21ba177be3376e10000000a421937/content.htm]

I hope it helped you to understand.

Regards and Best wishes.