Wednesday, March 20, 2013

ME in Method


When we declare a variable of any type in public section of a class then we can use it in the implementation. Let us suppose we declare a variable of any type with an initial value in public section. Then we declare the variable again inside a method initiating with a different value. Now if we write the variable inside the method, the system will print the changed value not the previous one. To reflect the previous value of the variable we have to use ME operator.

In the following example we have declared a public variable v_txt and initiate with a value. Then we have declared the same variable again inside the method but instantiated with different value. Inside the method we are writing that variable with ME operator and get the previously initiated value. By declaring directly we are getting the changed value.

REPORT  zsr_test NO STANDARD PAGE HEADING.

*----------------------------------------------------------------------*
*       CLASS cl_me DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_me DEFINITION.
  PUBLIC SECTION.
    DATA v_txt TYPE char40 VALUE 'Class Attribute'.
    METHODS m_me.
ENDCLASS.                    "cl_me DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_me IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_me IMPLEMENTATION.
  METHOD m_me.
    DATA v_txt TYPE char40 VALUE 'Method Attribute'.

    WRITE: / me->v_txt,
           / v_txt.
  ENDMETHOD.                    "m_me
ENDCLASS.                    "cl_me IMPLEMENTATION

START-OF-SELECTION.
  DATA obj TYPE REF TO cl_me.
  CREATE OBJECT obj.
  CALL METHOD obj->m_me.

The program generates the following output.

10 comments:

  1. I got the exact answers for what I was searching , Thank You.....!!

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. please send me any alv oop single screen with multiple table use and single container use.

    Emailid-ashwanishrm744@gmail.com
    Ashwani

    ReplyDelete
  4. Thanks, Nice code demo.

    I have a question and trying to find best practise answer for it.

    Class_Parent abstract.

    Public.
    Method1.
    Method2.
    endlcass.

    Class_Child.

    redefine method1.

    redefine method2.

    endclass.

    Class_child implementation.

    Method 1.

    method2().->> Which one is correct and best practise over other

    me->method2( ). ->> Which one is correct and best practise over other

    endmethod.

    method2.
    endmethod.

    endclass.

    Higlighted are my confusion area which one is good practise,because I redine locally.

    ReplyDelete


  5. Best SAP Success Factors Training Institute in Chennai
    http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
    Best SAP MM Training in Chennai
    http://thecreatingexperts.com/sap-mm-training-in-chennai/
    Best SAP SD Training in Chennai
    http://thecreatingexperts.com/sap-sd-training-in-chennai/
    http://thecreatingexperts.com/sap-hr-training-in-chennai/
    Best SAP FICO Training in Chennai
    http://thecreatingexperts.com/sap-fico-training-in-chennai/
    Best SAP ABAP Training in Chennai
    http://thecreatingexperts.com/sap-abap-training-in-chennai/
    Best SAP BASIS Training in Chennai
    http://thecreatingexperts.com/sap-basis-training-in-chennai/

    If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
    CONTACT:8122241286
    http://thecreatingexperts.com/sap-mm-training-in-chennai/

    Both Classroom/Online Training is Available!!!!!!

    ReplyDelete
  6. Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.

    SAP HR Training in Chennai

    SAP SD Training in Chennai

    SAP Basis Training in Chennai

    ReplyDelete
  7. Hi,
    i want to get the 'ME' instance name in debugger mode. Is it possible?

    ReplyDelete
  8. Thanks for sharing the valuable information here. sap training institutes in hyderabad in information with this content. Thank you and please keep update like this informative details.
    http://www.sapschool.in/

    ReplyDelete
  9. This post is really nice and informative. The explanation given is really comprehensive and informative..sap hr training

    ReplyDelete

Note: Only a member of this blog may post a comment.