‎2008 Jul 21 12:35 PM
Hi,
I created a class in se24 and in method wrote simple addition logic
I created a object in my prog for the class and entered the numbers it works fine.
But when I use ME to reference the method its showing an error ME is not defined by any DATA statemnt
the code is as follows
class zp_class definition load.
PARAMETERS : p_x type i,
p_y type i.
data : z type i.
CALL METHOD me->zadd
EXPORTING
v_x = p_x
v_y = p_y
IMPORTING
v_z = z
.
write :z .
How to make use of ME plz guide me
regards
‎2008 Jul 21 2:03 PM
Hi ,
me is used to refer the methods and attributes of the same class within the methods of that class only.
This will explain by the folllowing example.
&----
*& Report Z_SIMPLE_CLASS
*&
&----
REPORT z_simple_class.
----
CLASS c1 DEFINITION
----
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA: a TYPE i value 3,
b TYPE i value 4.
METHODS: m_add exporting a type i
b type i,
m_sub.
ENDCLASS. "c1 DEFINITION
CLASS c1 IMPLEMENTATION.
METHOD m_add.
DATA c TYPE i.
c = a + b.
WRITE: 'c:= ', c.
ENDMETHOD. "m_add
METHOD m_sub.
DATA c TYPE i.
CALL METHOD me->m_add.
b = c.
a = b.
c = a - b.
WRITE: 'c:= ', c.
ENDMETHOD. "m_sub
ENDCLASS. "c1 IMPLEMENTATION
START-OF-SELECTION.
DATA: cc1 TYPE REF TO c1,
a1 type i value -4,
b1 type i value -4.
CREATE OBJECT cc1.
cc1->m_add( importing a = a1 b = b1 ).
write: cc1->a.
write: cc1->b.
by
Prasad G.V.K
Edited by: PRASAD GVK on Jul 21, 2008 3:03 PM
‎2008 Jul 21 12:47 PM
Hi,
You can use me only in a class which refers to the current object i.e You can use me inside the methods of class to call the other methods of class and also to refer the attributes of class. Only members of the class can access me to refer to all the members of current object.
Thanks,
Naveen kumar.
‎2008 Jul 21 2:00 PM
hi,
whats the use of ME particularly as we can use call method statemnt to scess the methods
regards
‎2008 Jul 21 2:03 PM
Hi ,
me is used to refer the methods and attributes of the same class within the methods of that class only.
This will explain by the folllowing example.
&----
*& Report Z_SIMPLE_CLASS
*&
&----
REPORT z_simple_class.
----
CLASS c1 DEFINITION
----
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA: a TYPE i value 3,
b TYPE i value 4.
METHODS: m_add exporting a type i
b type i,
m_sub.
ENDCLASS. "c1 DEFINITION
CLASS c1 IMPLEMENTATION.
METHOD m_add.
DATA c TYPE i.
c = a + b.
WRITE: 'c:= ', c.
ENDMETHOD. "m_add
METHOD m_sub.
DATA c TYPE i.
CALL METHOD me->m_add.
b = c.
a = b.
c = a - b.
WRITE: 'c:= ', c.
ENDMETHOD. "m_sub
ENDCLASS. "c1 IMPLEMENTATION
START-OF-SELECTION.
DATA: cc1 TYPE REF TO c1,
a1 type i value -4,
b1 type i value -4.
CREATE OBJECT cc1.
cc1->m_add( importing a = a1 b = b1 ).
write: cc1->a.
write: cc1->b.
by
Prasad G.V.K
Edited by: PRASAD GVK on Jul 21, 2008 3:03 PM
‎2008 Jul 21 2:42 PM
hi I know that one but why it is used is there any specific reason as we can also do the same with call method statemnt
regards
prasanth
‎2008 Jul 21 2:44 PM
it is just a shorter form and it is easier to read (and understand) the source code. These are the only reasons.
‎2008 Jul 21 3:25 PM
Hi,
Genrerally me-> is used to improve readability.
You can address an object itself by using the predefined reference variable ME within its instance methods.
When a foreign method is called a client object is to export a reference to itself. ME can then be used as an actual parameter with EXPORTING or CHANGING.
Regards
Abhijeet
‎2008 Jul 21 3:30 PM
Hi,
The main reason behind introducing me is,
if you are using an attribute at Object level and method level with same name, then , me is exacly used to show the difference between Object attribute and method attribute(local to method) in usage.
Object attribute is simply called with me like me.
Eg: if you are using a variable a in class declaration and in method add/sub like in my earlier program, to identify the difference ,
object variable is referred with me->a and
local variable used as a simply.
I hope you should understand now clearly.
by
Prasad G.V.K
‎2008 Jul 22 8:47 AM
>
> it is just a shorter form and it is easier to read (and understand) the source code. These are the only reasons.
There's a robustness argument as well.
I use "me" when I use any instance method or attribute within a class. When referring to static methods and attributes, I use CLASS_NAME=>method/attribute. In this way, if someone comes along later and defines some local data in a method with the same name as an instance attribute, for example, it won't affect the running of the program.
matt
‎2008 Jul 21 7:36 PM
I think prasad have explained the solution very properly.Just to support his answer i am giving you example and in which cases we should use me refrence variaable.
class vehicle definition.
public section.
method constructor
importing im_make type string
im_model type string
private section.
data make type string.
endclass
class vehicle implementation.
method constructor.
data make type string VALUE 'abc'.
concatenate IM_MAKE MAKE into ME->make.*
endmethod.
endclass.
Just observe above program.
make is a global attribute in claa as well as
local varible in constructor definition.
so which is the nest way to distinguish between *global make *
and * local make*.
So now again if you have any doubt then feel free to ask.
regards
panky