banner ads

Class Definition Deferred concept

Class Definition Deferred concept


One class can be refrerred within another class definition with defining the class. But that class must be defined later on. 

Below is a program where we have defined class cls2. Inside there we are referring the object obj1 ref to class cls1 which has the definition deferred. Later on the class cls1 has been defined.

*&---------------------------------------------------------------------*
*& Report  ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zsr_test.

CLASS cls1 DEFINITION DEFERRED.

*----------------------------------------------------------------------*
*       CLASS cls2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 DEFINITION.

  PUBLIC SECTION.
    DATA: obj1 TYPE REF TO cls1.

ENDCLASS.                    "cls2 DEFINITION

*----------------------------------------------------------------------*
*       CLASS cls1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 DEFINITION.

  PUBLIC SECTION.
    DATA: v_cls TYPE char40 VALUE 'This is class 1 Definition'.

ENDCLASS.                    "cls1 DEFINITION

START-OF-SELECTION.

  DATA: obj2 TYPE REF TO cls2.

  CREATE OBJECT: obj2,
                 obj2->obj1.

  WRITE: / obj2->obj1->v_cls.


The output of this as follows:

No comments