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

RE:ABAP objects

alex_georgek
Associate
Associate
0 Likes
551

Hi all,

What do you mean by

me->name = name.

in OOPs ABAp.Please explain with a simple example.

Thanks in advance.

Alex.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
531

Hello Alex

ME is in ABAP corresponds to THIS in Java.

It is the instance itself.

As soon as you create an instance of a class you can refer within any instance method (but not static method) to its instance attributes ( e.g. MD_NAME) either using:


METHOD constructor.

  me->md_name = id_name.  " IMPORTING parameter of CONSTRUCTOR method
" Or:
  md_name = id_name. " same effect
  
ENDMETHOD.

Regards

Uwe

3 REPLIES 3
Read only

uwe_schieferstein
Active Contributor
0 Likes
532

Hello Alex

ME is in ABAP corresponds to THIS in Java.

It is the instance itself.

As soon as you create an instance of a class you can refer within any instance method (but not static method) to its instance attributes ( e.g. MD_NAME) either using:


METHOD constructor.

  me->md_name = id_name.  " IMPORTING parameter of CONSTRUCTOR method
" Or:
  md_name = id_name. " same effect
  
ENDMETHOD.

Regards

Uwe

Read only

Former Member
0 Likes
531

hi,

You can address the object itself within object methods using the implicitly available reference variable ME.

Description of the example:

In the CONSTRUCTOR, the instance attribute name is covered by the locally defined variable name. In

order to still be able to address the instance attribute, you need to use ME.

CLASS lcl_airplane DEFINITION.

PUBLIC SECTION.

METHODS CONSTRUCTOR

IMPORTING im_name TYPE string

im_weight TYPE I.

PRIVATE SECTION.

DATA name TYPE string.

DATA weight TYPE I.

ENDCLASS.

CLASS cl_airplane IMPLEMENTATION.

METHOD CONSTRUCTOR.

DATA name TYPE string VALUE `-airplane`.

CONCATENATE im_name name INTO ME->name.

weight = im_weight.

ENDMETHOD.

ENDCLASS.

Hope this is helpful, Do reward.

Read only

Former Member
0 Likes
531

hi alex

Internally, each method has an implicit self-reference variable, the reserved word me

A method can access the components of its class simply by their name; however,

It may use me simply for clarity

If a method declares a local variable with the same name as one of the class components, to avoid ambiguity it must use me to address the variable originally belonging to the class.

A method must use me to export a reference to itself (that is, its object)

class c1 definition.

public section.

data : num type i value 5.

methods : c1 method.

endclass.

class c1 implementation.

method: c1method.

data: num type i value 3.

write: /10 me->num, " access variable of the class

/10 num. "access variable of the method

endmethod.

endclass.

start-of-section.

data: num type i.

data: obj1 type ref to c1.

create object: obj1.

call method obj1->c1method.

Regards

Naresh

Hope this is helpful. Rewards Points