Application Development and Automation 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: 
Read only

oops concept

Former Member
0 Likes
388

Hi frnz

what is the meaning of definition deferred and definition load in oops ?

thank u

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
354

hi,

If you mention the Deferred with class then class which you are going to create is known then later we create the definition for that class.

For Load we are going to load the class from Class Library.

For more details go through the following.

CLASS class DEFINITION {DEFERRED [PUBLIC]} | LOAD.

Extras:

1. ... DEFERRED [PUBLIC]

2. ... LOAD

Effect

These two variants of the CLASS statement are used to make the class class known, regardless of the location of the actual definition of the class in the program. These variants do not introduce a declaration part and must not be enclosed using ENDCLASS.

Addition 1

... DEFERRED [PUBLIC]

Effect

The variant with the DEFERRED addition makes a class known provisionally in the program.

Without the PUBLIC addition, this variant makes a local class known before its actual definition. The program must contain an actual declaration part for class at a later point in the program. You cannot access individual components of the class before it is actually defined. You need to use this statement if you want to make a reference to a local class before it is defined.

With the PUBLIC addition, this variant makes a global class known and defers loading the class until the end of the current program unit. You can only access individual components of the class after it has been loaded. This statement can be used to prevent unwanted recursion when making references to global classes.

Addition 2

... LOAD

Effect

The variant with the LOAD addition loads a global class class from the Class Library. This statement was needed before Release 6.20 if you wanted to access one of the static components of class from within a program, or to declare an event handler for class before class had been loaded automatically. From Release 6.20 onwards, the LOAD addition is only needed if the compilation of an ABAP program fails because it includes recursive accesses of a globa l class. In such cases, you may be able to make the program compilable by explicitly loading the class before recursion.

Example

In this example, the class c1 uses the class c2 and vice versa. This means that one of the classes must be made known before it is actually defined. The global class cl_gui_cfw is also loaded before one of its static attributes is used.

CLASS c1 DEFINITION DEFERRED.

CLASS c2 DEFINITION.

PUBLIC SECTION.

DATA c1ref TYPE REF TO c1.

ENDCLASS.

CLASS c1 DEFINITION.

PUBLIC SECTION.

DATA c2ref TYPE REF TO c2.

ENDCLASS.

CLASS cl_gui_cfw DEFINITION LOAD.

DATA state LIKE cl_gui_cfw=>system_state.

An example of using the DEFERRED PUBLIC addition would be a type group in which a reference type is declared with a reference to a global class, which itself contains components with references to this reference type. In this situation, the entire class cannot be loaded before the type group, since the types are not yet known. However, after the CLASS DEFINITION ... DEFERRED PUBLIC statement, the class name can be specified after REF TO without the class having been loaded previously.

*if useful reward points.*

1 REPLY 1
Read only

Former Member
0 Likes
355

hi,

If you mention the Deferred with class then class which you are going to create is known then later we create the definition for that class.

For Load we are going to load the class from Class Library.

For more details go through the following.

CLASS class DEFINITION {DEFERRED [PUBLIC]} | LOAD.

Extras:

1. ... DEFERRED [PUBLIC]

2. ... LOAD

Effect

These two variants of the CLASS statement are used to make the class class known, regardless of the location of the actual definition of the class in the program. These variants do not introduce a declaration part and must not be enclosed using ENDCLASS.

Addition 1

... DEFERRED [PUBLIC]

Effect

The variant with the DEFERRED addition makes a class known provisionally in the program.

Without the PUBLIC addition, this variant makes a local class known before its actual definition. The program must contain an actual declaration part for class at a later point in the program. You cannot access individual components of the class before it is actually defined. You need to use this statement if you want to make a reference to a local class before it is defined.

With the PUBLIC addition, this variant makes a global class known and defers loading the class until the end of the current program unit. You can only access individual components of the class after it has been loaded. This statement can be used to prevent unwanted recursion when making references to global classes.

Addition 2

... LOAD

Effect

The variant with the LOAD addition loads a global class class from the Class Library. This statement was needed before Release 6.20 if you wanted to access one of the static components of class from within a program, or to declare an event handler for class before class had been loaded automatically. From Release 6.20 onwards, the LOAD addition is only needed if the compilation of an ABAP program fails because it includes recursive accesses of a globa l class. In such cases, you may be able to make the program compilable by explicitly loading the class before recursion.

Example

In this example, the class c1 uses the class c2 and vice versa. This means that one of the classes must be made known before it is actually defined. The global class cl_gui_cfw is also loaded before one of its static attributes is used.

CLASS c1 DEFINITION DEFERRED.

CLASS c2 DEFINITION.

PUBLIC SECTION.

DATA c1ref TYPE REF TO c1.

ENDCLASS.

CLASS c1 DEFINITION.

PUBLIC SECTION.

DATA c2ref TYPE REF TO c2.

ENDCLASS.

CLASS cl_gui_cfw DEFINITION LOAD.

DATA state LIKE cl_gui_cfw=>system_state.

An example of using the DEFERRED PUBLIC addition would be a type group in which a reference type is declared with a reference to a global class, which itself contains components with references to this reference type. In this situation, the entire class cannot be loaded before the type group, since the types are not yet known. However, after the CLASS DEFINITION ... DEFERRED PUBLIC statement, the class name can be specified after REF TO without the class having been loaded previously.

*if useful reward points.*