06-18-2016 7:54 AM
Problem statement : Is it possible to access an instance method from a static method in ABAP ?. (In java it is not possible).
I tried to analyse this problem statement with the below sample code. After execution I CONCLUDED that it is possible but still need to confirm...
*&---------------------------------------------------------------------*
*& Report ZCLASS1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zclass1.
*----------------------------------------------------------------------*
* CLASS oops3 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS oops3 DEFINITION.
PUBLIC SECTION.
METHODS : m_inst1.
CLASS-METHODS : m_stat1.
ENDCLASS. "oops3 DEFINITION
*----------------------------------------------------------------------*
* CLASS oops3 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS oops3 IMPLEMENTATION.
METHOD m_inst1.
WRITE : 'I was called from method m_stat1'.
ENDMETHOD. "m_inst1
METHOD m_stat1.
DATA : insideobj TYPE REF TO oops3.
CREATE OBJECT insideobj.
CALL METHOD insideobj->m_inst1.
ENDMETHOD. "m_stat1
ENDCLASS. "oops3 IMPLEMENTATION
START-OF-SELECTION.
CALL METHOD oops3=>m_stat1.
06-18-2016 9:35 AM
Of course it works, why do you need a confirmation? The most known example is the "factory" method whose goal is to return an instance. It may be forbidden of creating an instance (CREATE OBJECT) from outside by declaring the class with the private or protected instantiation flag.
06-18-2016 9:35 AM
Of course it works, why do you need a confirmation? The most known example is the "factory" method whose goal is to return an instance. It may be forbidden of creating an instance (CREATE OBJECT) from outside by declaring the class with the private or protected instantiation flag.