CLASS - DEFERRED, LOAD

Short Reference

Syntax

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.

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.