Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Built-In Types, Data Objects, Functions, and Constructors →  Built-In Data Objects 

The Self-Reference me

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. me is handled like a local constant, which means that the value of me cannot be modified in an instance method. The static type of me is the class in which the instance method is implemented.

The name me is reserved and cannot be used in a class for attributes, formal parameters, and local data objects.

Other versions: 7.31 | 7.40 | 7.54


Note

When an object is created, me also points to the instance of the new subclass when an instance constructor of a superclass called using super->constructor is executed. In the instance constructor of the superclass, or in methods called by the instance constructor, me-> is ignored in the method call if specified. Instead, the method implementations of the superclass are always called.


Example

Accesses identically named data objects of a class in a method. If specified on its own, str indicates the local data object of the method. The self reference me is used to access the instance attribute str of the method.

CLASS cls DEFINITION. 
  PUBLIC SECTION. 
    METHODS meth. 
  PRIVATE SECTION. 
    DATA str TYPE string VALUE `attr`. 
ENDCLASS. 

CLASS cls IMPLEMENTATION. 
  METHOD meth. 
    DATA str TYPE string VALUE `local`. 
    cl_demo_output=>display( |{ str }\n{ 
                               me->str }| ). 
  ENDMETHOD. 
ENDCLASS. 

START-OF-SELECTION. 
  NEW cls( )->meth( ).