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

The self reference ME

Former Member
0 Likes
2,514

hi please tell me about this 'ME'.

When this need to be used and why it is needed .

I read following sentence from the documentation..

'Each instance method contains a predefined reference varaiable of the type of the current class.This variable is called ME'.

6 REPLIES 6
Read only

Former Member
0 Likes
1,259

when you are using the methods and/or attributes of an instance of your class, you can reference them bei using me->your_method or me->your_attribute. this way you and others can see in your coding, that you are using an attribute and not just a local variable or the method of another class.

greetings,

dsp

Read only

Former Member
0 Likes
1,259

Hi

Me keyword is used to access its own method of the class.

it is the self reference to a method of the same class

Regards

Hari

Read only

Former Member
0 Likes
1,259

Hi there,

you might want to look at some [examples|http://wiki.sdn.sap.com/wiki/display/Snippets/ABAPObjects-CreatingyourFirstLocalClass-Usingself-referenceInINHERITING] on SDN wiki. They are contrived, and overuse of name overloading is bad practice in my view, but they should give you an idea of what me (and super) are all about.

-- Sebastian

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,259
Read only

Former Member
0 Likes
1,259

The self reference me-> is used to clearly distinguish class attribute and a local variable. Here is an example:

CLASS lcl_appl DEFINITION.
  PUBLIC SECTION.
    METHODS: init.
  PRIVATE SECTION.
    DATA: a TYPE c LENGTH 2 VALUE '10'.
ENDCLASS.                 


CLASS lcl_appl IMPLEMENTATION.
  METHOD init.
    DATA: a TYPE c LENGTH 2 VALUE '20'.
    WRITE me->a.
    WRITE a.
  ENDMETHOD.                  
ENDCLASS.                 

DATA: oref_appl TYPE REF TO lcl_appl.

START-OF-SELECTION.
  CREATE OBJECT oref_appl.
  oref_appl->init( ).

Guess the output?

Read only

0 Likes
1,259

Me is equal to THIS operator in Java as You can refer to any member of the current object from within an instance method or a constructor using yor ME operator.

Thnaks