Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Deffered definition of class

Former Member
0 Kudos
687

Hi,

I am writing below a small code which says Deffered definition of class.

Can anyone tell me what is the main objective of going for deffered defintion .

1.6 Deferred Definition of a Class

Theme This program will demonstrate how one can refer to a class without defining the class before that point. But, the class has to be defined later on.

Program description In this program , class C1 has an interface reference O2 declared with reference to class C2. But, before that, class C2 is not defined. It is defined later with a single public attribute , NUM .

This demonstrates the theme.

In the main section of the program, object : OBJ1 is created from class C1.

Then, an object is created from the reference variable O2 in class C1. Finally, the attribute num of that object is displayed.

Dump report ysubdel1.

<code>

CLASS C2 DEFINITION DEFERRED.

CLASS C1 DEFINITION.

PUBLIC SECTION.

DATA O2 TYPE REF TO C2.

ENDCLASS.

CLASS C2 DEFINITION.

public section.

data : num type i value 5.

ENDCLASS.

start-of-selection.

data : obj1 type ref to C1.

CREATE OBJECT obj1.

create object obj1->o2.

write:/5 obj1->o2->num .

</code>

Thanks,

satya

4 REPLIES 4

dhorions
Contributor
0 Kudos
206

Definition deferred can be used if you want the instantiation of the object to be in the source code <b>before</b> the definition of the class .

In your case: you use class c2 in class c1, and only define the class c2 after that.

Former Member
0 Kudos
206

But why? Anyways we are again defining class c2 so wht is the importance of doing that.

Like will there any specific requirement for doing so in real time.

Thanks,

satya

0 Kudos
206

Hi,

The reason behind this is simple.

When you create your Module pool program or say Report program with TOP-INCLUDE you will want all you global data to be declared in that place.

Declare a Reference variable of a Local class in the TOP include what you can do is this.

In the TOP include you can mention that DEFINITION is deffered and then create a global variable in the TOP INCLUDE.

Then you can create the Local class in any INCLUDE program.

So basically your TOP include and the INCLUDE program which has the class are two seperate repository objects.

For you to be able to create your data in the TOP include it is useful to use this DEFINITION DEFERRED.

Regards,

Sesh

Former Member
0 Kudos
206

<b>In general , we define & use a class within the same context.

A context is the common environment of a set of classes, e.g. a no. of local classes

in a program. If we need to refer to a class using the addition 'TYPE REF TO' before the class has been defined, in such cases it is necessary to declare a class using the

'definition deferred', it must be noted that the class has to defined at a later point of time within the same context.

The variant CLASS <nm-o-class> DEFINITION DEFERRED only indicates that the class occurs in the same context at a later point of time, so that the system does not look

in a higher level context . Thank you.

</b>