Tuesday, February 12, 2013

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:


6 comments:

abhigt said...

Good One....



Keep Posting Dear.

yektek training said...

good post easy to understand also thanks a lot

Anonymous said...

I understand the use of this keyword but what could be a practical scenario where this would be useful. Anyway it has to be declared at a later point why not at the beginning ?

Unknown said...

Thanks.. very good post for concept clearing

camelliacanan said...

Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..

SAP FICO Training in Chennai

SAP MM Training in Chennai

Business World said...

Thank you for sharing the great blog. BEST SAP ABAP TRAINING IN HYDERABAD