‎2008 Feb 06 11:45 AM
Hi all,
What do you mean by
me->name = name.
in OOPs ABAp.Please explain with a simple example.
Thanks in advance.
Alex.
‎2008 Feb 06 11:59 AM
Hello Alex
ME is in ABAP corresponds to THIS in Java.
It is the instance itself.
As soon as you create an instance of a class you can refer within any instance method (but not static method) to its instance attributes ( e.g. MD_NAME) either using:
METHOD constructor.
me->md_name = id_name. " IMPORTING parameter of CONSTRUCTOR method
" Or:
md_name = id_name. " same effect
ENDMETHOD.
Regards
Uwe
‎2008 Feb 06 11:59 AM
Hello Alex
ME is in ABAP corresponds to THIS in Java.
It is the instance itself.
As soon as you create an instance of a class you can refer within any instance method (but not static method) to its instance attributes ( e.g. MD_NAME) either using:
METHOD constructor.
me->md_name = id_name. " IMPORTING parameter of CONSTRUCTOR method
" Or:
md_name = id_name. " same effect
ENDMETHOD.
Regards
Uwe
‎2008 Feb 06 12:07 PM
hi,
You can address the object itself within object methods using the implicitly available reference variable ME.
Description of the example:
In the CONSTRUCTOR, the instance attribute name is covered by the locally defined variable name. In
order to still be able to address the instance attribute, you need to use ME.
CLASS lcl_airplane DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR
IMPORTING im_name TYPE string
im_weight TYPE I.
PRIVATE SECTION.
DATA name TYPE string.
DATA weight TYPE I.
ENDCLASS.
CLASS cl_airplane IMPLEMENTATION.
METHOD CONSTRUCTOR.
DATA name TYPE string VALUE `-airplane`.
CONCATENATE im_name name INTO ME->name.
weight = im_weight.
ENDMETHOD.
ENDCLASS.
Hope this is helpful, Do reward.
‎2008 Feb 06 12:23 PM
hi alex
Internally, each method has an implicit self-reference variable, the reserved word me
A method can access the components of its class simply by their name; however,
It may use me simply for clarity
If a method declares a local variable with the same name as one of the class components, to avoid ambiguity it must use me to address the variable originally belonging to the class.
A method must use me to export a reference to itself (that is, its object)
class c1 definition.
public section.
data : num type i value 5.
methods : c1 method.
endclass.
class c1 implementation.
method: c1method.
data: num type i value 3.
write: /10 me->num, " access variable of the class
/10 num. "access variable of the method
endmethod.
endclass.
start-of-section.
data: num type i.
data: obj1 type ref to c1.
create object: obj1.
call method obj1->c1method.
Regards
Naresh
Hope this is helpful. Rewards Points