Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  Classes and Interfaces →  CLASS 

CLASS - DEFERRED

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CLASS class DEFINITION DEFERRED [PUBLIC]. 

Effect

This variant of the statement CLASS is used to make the class class known, regardless of the location of the actual definition of the class in the program. It does not introduce a declaration part and must not be ended using ENDCLASS.

  • Without the PUBLIC addition, the statement makes the local class of its actual definition known before its actual definition. The program must contain a declaration part for class at a later point. You cannot access individual components of the class before it is actually defined. You need this statement if you want to make reference to a local class before it is defined.
  • Using 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 recursions when making references to global classes.


Note

This variant of the statement CLASS can also only be listed in the context described under CLASS.


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.

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. 

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 statement DEFERRED PUBLIC statement, the class name can be specified after REF TO without the class having been loaded previously.