SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

Object Oriented Programming in ABAP - Use of ME in methods

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.

 



REPORT zstp_oo_abap.

CLASS testclass DEFINITION.
  PUBLIC SECTION.
    DATA : i_num TYPE i VALUE 5.
    METHODS : testmethod .
ENDCLASS.

CLASS testclass IMPLEMENTATION.
  METHOD :testmethod.
    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
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  DATA : i_num TYPE i.
  DATA : my_obj TYPE REF TO testclass.
  CREATE OBJECT : my_obj.
  CALL METHOD my_obj->testmethod.

Output -

image

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in