2007 May 14 8:31 AM
Hi all
can anybody please explain me about Reference varaible me in abap objects.
Thanks and Regards
vijay
2007 May 14 8:35 AM
Hi,
Within the implementation of every instance method, an implicitly created local reference variable called <b>ME</b> is available, which points to the instance in which the method is currently being executed. The static type of <b>me</b> is the class in which the instance method is implemented.
During object creation, <b>me</b> also points to the instance of the generated subclass during the execution of an instance constructor of a superclass that has been called using <b>super->constructor</b>. In the instance constructor of the superclass, or in methods that have been called by the instance constructor, specifying <b>me-></b> with the method call has no effect. Instead, the method implementations of the superclass are always called.
Thanks & Regards
Santhosh
Hi all
can anybody please explain me about Reference varaible me in abap objects.
Thanks and Regards
vijay
2007 May 14 8:33 AM
Within the class reference variable ME references to the current instance.
regards,
Hans
Please reward all helpful answers !!!!!
2007 May 14 8:35 AM
Hi,
Within the implementation of every instance method, an implicitly created local reference variable called <b>ME</b> is available, which points to the instance in which the method is currently being executed. The static type of <b>me</b> is the class in which the instance method is implemented.
During object creation, <b>me</b> also points to the instance of the generated subclass during the execution of an instance constructor of a superclass that has been called using <b>super->constructor</b>. In the instance constructor of the superclass, or in methods that have been called by the instance constructor, specifying <b>me-></b> with the method call has no effect. Instead, the method implementations of the superclass are always called.
Thanks & Regards
Santhosh
2007 May 14 8:40 AM
Hello vijaya,
Check out the code below......This will definitely help you to knw the concept of ME
1.1 Use of ME in methods
Theme A method can have a variable defined within it having the same name as one of the attributes of the class to which the method belongs to.
To clearly identify the class level attribute, the selector ME is used.
Program Description Class TESTCLASS contains method TESTMETHOD. There is a variable I_NUM declared as public attribute in the class as well as in the implementation part of the method.
To access the variable I_NUM at the class level within the method, the selector ME is used. Please see the ouputs of this program for better understanding.
Dump REPORT YSUBOOPS17 .
class testclass definition.
public section.
data : i_num type i value 5.
methods : testmethod .
endclass.
class testclass implementation.
method :testmethod.
data : i_num type i value 2.
write:/5<b> me->i_num</b> , " access variable of the class
/5 i_num . " access variable of the method
endmethod.
endclass.
start-of-selection.
data : i_num type i.
data : my_obj type ref to testclass.
create object : my_obj.
call method my_obj->testmethod.
Output 5 2
<b>Dont forget to reward points if it helps :-)</b>
Thanks,
Sachin
2007 May 14 1:03 PM
Hi,
Within a class, you can use the self-reference ME to access the individual components:
To access an attribute <attr> in the same class: ME-><attr>
To call a method <meth> in the same class: CALL METHOD ME-><meth>
Self references allow an object to give other objects a reference to it. You can also access attributes in methods from within an object even if they are obscured by local attributes of the method.
Regards,
Azaz Ali.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |