Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reg: self reference ME

Former Member
0 Likes
1,457

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,256

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

9 REPLIES 9
Read only

Former Member
0 Likes
1,256

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.

Read only

0 Likes
1,256

hi,

whats the use of ME particularly as we can use call method statemnt to scess the methods

regards

Read only

Former Member
0 Likes
1,257

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

Read only

0 Likes
1,256

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

Read only

0 Likes
1,256

it is just a shorter form and it is easier to read (and understand) the source code. These are the only reasons.

Read only

0 Likes
1,256

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

Read only

0 Likes
1,256

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

Read only

matt
Active Contributor
0 Likes
1,256

>

> 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

Read only

Former Member
0 Likes
1,256

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