Skip to Content
0
Former Member
May 19, 2008 at 08:33 AM

why do we need a Self Reference "me" to use the components of a class

964 Views

Hi

I am not clear why do we need a self reference variable "me" to call the components of its own class? when it can be accessed directly as in the following examples?

In my first example below i can call the method display_name directly without creating a reference object or instance of the class within the class.

In the second example i am using the self refernce Write me->name to access the component of a class.

My question is why do we need "me" when i can use the components directly as shown in my first example.

CLASS egocentric DEFINITION.
  PUBLIC SECTION.
    DATA:
     name(10) TYPE c READ-ONLY.

    METHODS set_name.
    METHODS display_name.

ENDCLASS.                    "egocentric DEFINITION

*---------------------------------------------------------------------*
*       CLASS egocentric IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS egocentric IMPLEMENTATION.

  METHOD set_name.

    MOVE 'Abap Objects' TO name.

    CALL method display_name.

  ENDMETHOD.                    "write_name

  METHOD display_name.

    write: name.

  ENDMETHOD.                    "display_name

ENDCLASS.                    "egocentric IMPLEMENTATION


*Global Data
DATA oref TYPE REF TO egocentric.

START-OF-SELECTION.
  CREATE OBJECT oref.
  CALL METHOD oref->set_name.

CLASS egocentric DEFINITION.
        PUBLIC SECTION.
            DATA:
             name(10) TYPE c VALUE u2018Instructoru2019
READ-ONLY.
             METHODS write_name.
ENDCLASS.
CLASS egocentric IMPLEMENTATION.
        METHOD write_name.
            WRITE me->name.
        ENDMETHOD.
ENDCLASS.
*Global Data
DATA oref TYPE REF TO egocentric.
START-OF-SELECTION.
        CREATE OBJECT oref.
        CALL METHOD oref->write_name.