2013 Nov 12 7:36 AM
in class(method implementation)
method meth.
me->meth_sub( ). "1
call method me->meth_sub( ). "2
meth_sub( ). "3
call method meth_sub( ). "4
endmethod.
When I call another method in method implementation, all of the four seems have the same effect.
out of class:
(call method) class=>meth( )
(call method) obj->meth( )
We have to use class or obj to call a method.
My questions are:
1, Is "call method" ommitable?
2, what does 'me' stand for in method implementation. can I use a class name or sth else to replace 'me'?
2013 Nov 12 7:39 AM
We can not omit the call method
Me=> denotes the the menthod of the same class is called inside the class.
Thanks,
Vijay.
2013 Nov 12 7:42 AM
But as far as I tried, "call method" can be omitted, and "ME" also.
2013 Nov 12 7:47 AM
Hello Check the below link :
Programs can only access the instance components of an object using references in object reference variables. This is done using the object component selector -> (ref is a reference variable):
· To access an attribute attr: ref->attr
· To call a method meth: CALL METHOD ref->meth
You can access static components using the class name or the class component selector => as well as the reference variable. It is also possible to address the static components of a class before an object has been created.
· To access a static attribute attr: class=>attr
· To call a static method meth: CALL METHOD class=>meth
Note that the properties of instance attributes behave like static components. It is therefore possible to refer in a LIKE addition to the visible attributes of a class – through the class component selector or through reference variables, without prior creation of an object.
Each class implicitly contains the reference variable me. In objects, the reference variable mealways contains a reference to the respective object itself and is therefore also referred to as the self-reference. Within a class, you can use the self-reference me to access the individual class components:
· To access an attribute attr of your class: me->attr
· To call a method meth of your class: CALL METHOD me->meth
When you work with attributes of your own class in methods, you do not need to specify a reference variable. The self-reference me is implicitly set by the system. 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.
http://help.sap.com/saphelp_nw70/helpdata/en/c3/225b5f54f411d194a60000e8353423/content.htm
Thanks,
Vijay Simha CR
2013 Nov 12 9:05 AM
HI ming Yu,
Within the implementation of every instance method, an implicitly created local reference variable called me is available, which points to the instance in which the method is currently being executed. The static type of me is the class in which the instance method is implemented.
Each class implicitly contains the reference variable me. In objects, the reference variable mealways contains a reference to the respective object itself and is therefore also referred to as the self-reference. Within a class, you can use the self-reference me to access the individual class components:
-To access an attribute attr of your class: me->attr
-To call a method meth of your class: CALL METHOD me->meth
When you work with attributes of your own class in methods, you do not need to specify a reference variable. The self-reference me is implicitly set by the system. 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.
And for your other question ,
Yes u can call a method without using call method.
check the program :
INTERFACE I1.
METHODS m1.
endinterface.
INTERFACE i2.
INTERFACEs i1.
METHODS m2.
ALIASES m FOR i1~m1.
endinterface.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACEs i2.
METHODs m3.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD i2~m .
write: 'M1'.
endmethod.
METHOD i2~m2.
write: 'm2'.
endmethod.
METHOD m3.
write 'm3'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA obj type REF TO c1.
CREATE OBJECT obj.
obj->i2~m( ).
obj->i2~m2( ).
obj->m3( ).
I Hope this answers your questions.
Regards,
Sivaganesh.