Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

Use of Me Keyword in SAP ABAP

When we create a variable in the public section of a class, we can use it within the methods of that class. Let’s say we assign it an initial value. Later, if we create another variable with the same name inside a method and assign it a new value, this new (local) value will be used within that method.

To access the original value from the class, we need to use the ME operator.

Example:

We first create a public variable v_txt with an initial value ‘Class Variable’. Then, inside a method, we declare another variable (local to the method) with the same name v_txt, but assign it a different value: ‘Method Variable’.

If we use v_txt directly in the method, it will reference the local variable, and we will get ‘Method Variable’.

If we use me->v_txt, we explicitly refer to the class attribute, and we get ‘Class Variable’.

Similarly, private and protected methods cannot be accessed directly from outside the class. However, we can call them from within another public method using the ME operator.

*&---------------------------------------------------------------------*
*& Report  ZREP_LCLCLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zrep_lclclass.

" local class definition.
CLASS lcl_operator  DEFINITION.

  PUBLIC SECTION.

    DATA v_txt TYPE string VALUE 'Class Variable'.
    METHODSm_operator.
    
  PROTECTED SECTION.
    METHODSm_protectedmethod.
    
  PRIVATE SECTION.
    METHODSm_privatemethod.
ENDCLASS.

" local class implementation
CLASS lcl_operator IMPLEMENTATION.
  METHOD m_protectedmethod.
    WRITE :/ 'Hi from protected method'.
  ENDMETHOD.
  METHOD m_privatemethod.
    WRITE :/ 'Hi from private method'.
  ENDMETHOD.
  METHOD m_operator.
    DATA v_txt TYPE string VALUE 'Method Variable'.

    WRITE/ v_txt,
           / me->v_txt.
    me->m_protectedmethod)" protected method
    me->m_privatemethod)" private method
  ENDMETHOD.
ENDCLASS.


START-OF-SELECTION.

  " object for class.
  DATA(lo_classNEW lcl_operator).
  lo_class->m_operator).

OUTPUT :

Related Questions

Leave an answer

Leave an answer