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

what is reference ME ?

Former Member
0 Likes
1,183

Hi All,

what is reference-> ME?

Regards,

Luke

3 REPLIES 3
Read only

Former Member
0 Likes
940

Hi ,

Each class implicitly contains the reference variable me. In objects, the reference variable mealways contains a reference to the respective object itself and is therefore also referred to as the self-reference. Within a class, you can use the self-reference me to access the individual class components:

· To access an attribute attr of your class: me->attr

· To call a method meth of your class: CALL METHOD me->meth

When you work with attributes of your own class in methods, you do not need to specify a reference variable. The self-reference me is implicitly set by the system. Self-references allow an object to give other objects a reference to it. You can also access attributes in methods from within an object even if they are obscured by local attributes of the method.

regards

Deepak

Read only

Former Member
0 Likes
940

Hi Luke,

in some cases you need to have a self-reference available. In ABAP Objects,

self-references are always predefined, but they are only useful in certain contexts

and only there are they syntactically available.

CLASS lcl_sdn DEFINITION.

PUBLIC SECTION.

...

METHODS set_type

IMPORTING im_make TYPE string

... .

PRIVATE SECTION.

DATA: make TYPE string,

...

ENDCLASS.

CLASS lcl_sdn IMPLEMENTATION.

METHOD set_type.

DATA make TYPE string.

me->make = im_make.

TRANSLATE me->make TO UPPER CASE.

make = me->make.

CONCATENATE '_' make INTO make.

...

ENDMETHOD.

ENDCLASS.

You can address an object itself by using the predefined reference variable ME

within its instance methods. Generally, you do not need to use the prefix

me-> in such cases, but you may use it to improve readability.

METHOD set_make.

IF im_make IS INITIAL.

init_make( ). " me->init_make( ). also possible

ELSE.

make = im_make.

ENDIF.

ENDMETHOD.

However, it is required when you want to show a distinction between local data

objects and instance attributes with the same name.

The following case shows another important use: 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.

Bye,

Peter

Read only

Former Member
0 Likes
940

thx