Tuesday, December 29, 2015

Instance Method vs Static Method



Instance method can access both – instance components as well as static components. Static method can only access static components. In the following example we have instance component v_var and static component cl_v_var. We have an instance method m_one and a static method cl_m_one. We can access both of those components from the instance method but when we want to access instance component from the static method then it will give a syntax error as follows.


REPORT  zsr_test NO STANDARD PAGE HEADING.

*----------------------------------------------------------------------*
*       CLASS cl_one DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_one DEFINITION.
  PUBLIC SECTION.
    DATA v_var TYPE char40 VALUE 'Instance Component'.
    CLASS-DATA cl_v_var TYPE char40 VALUE 'Static Component'.

    METHODS m_one.
    CLASS-METHODS cl_m_one.
ENDCLASS.                    "cl_one DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_one IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_one IMPLEMENTATION.
  METHOD m_one.
    WRITE: / v_var,
           / cl_v_var.
  ENDMETHOD.                    "m_one

  METHOD cl_m_one.
    WRITE: / cl_v_var.
  ENDMETHOD.                    "cl_m_one
ENDCLASS.                    "cl_one IMPLEMENTATION

START-OF-SELECTION.
  CALL METHOD cl_one=>cl_m_one.
  SKIP.

  DATA obj TYPE REF TO cl_one.
  CREATE OBJECT obj.
  CALL METHOD obj->m_one.

The program generates the following output.

5 comments:

Unknown said...

Nice news and thanks for sharing this here to let me know this updates,please know the recent updates by visiting this link also…because I had gain some info from here also:
SAP Training Tutorials | SAP Support Portal

Unknown said...

Thanks for sharing this Information, Got to learn new things from your Blog on Sap abap.
http://thecreatingexperts.com/sap-abap-training-in-chennai/

Anonymous said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

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

Unknown said...



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!!!!!!

Camelliacanan said...

Really i enjoyed very much. And this may helpful for lot of peoples. So you are provided such a nice and great article within this.

SAP HR Training in Chennai

SAP SD Training in Chennai

SAP Basis Training in Chennai