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:


10 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 ?

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Kumaresh Karar said...

Thanks.. very good post for concept clearing

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

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

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

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

Keerthi Suresh said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-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...

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

gilledashivani said...

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

akhila priya said...

This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up Java online training Bangalore