Skip to Content
0
Jun 18, 2016 at 06:54 AM

Calling an instance method from static method?

1347 Views

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.