Object Oriented Programming in ABAP - Use of ME in methods
A method can have a variable defined within it having the same name as one of the attributes of the class to which the method belongs to. To clearly identify the class level attribute, the selector ME is used.
Class TESTCLASS contains method TESTMETHOD. There is a variable I_NUM declared as public attribute in the class as well as in the implementation part of the method.
To access the variable I_NUM at the class level within the method, the selector ME is used. Please see the output of this program for better understanding.
CLASS testclass DEFINITION.
DATA : i_num TYPE i VALUE 5.
METHODS : testmethod .
CLASS testclass IMPLEMENTATION.
DATA : i_num TYPE i VALUE 2.
WRITE:/5 me->i_num , " access variable of the class
/5 i_num . " access variable of the method
DATA : i_num TYPE i.
DATA : my_obj TYPE REF TO testclass.
CREATE OBJECT : my_obj.
CALL METHOD my_obj->testmethod.