Sunday, September 2, 2018

Class Definition Deferred

Class Definition Deferred.

 It is concept in which delay the definition of a class .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.

One example of using the addition DEFERRED PUBLIC 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. After the statement DEFERRED PUBLIC, however, the class name can be specified after REF TO without the class having been loaded previously.[source:SAP KEY DEFINITION].

*&---------------------------------------------------------------------*
*& Report  ZCLASS_DEFERRED
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZCLASS_DEFERRED.
CLASS ABC DEFINITION DEFERRED.

***NOW GOING TO DEFINE CLASS XYZ AND MAKING OBJ THAT REFERNCES THE CLASS ABC.

CLASS XYZ DEFINITION.
PUBLIC SECTION.
DATA OBJ1 TYPE REF TO ABC.
ENDCLASS.

CLASS ABC DEFINITION.
PUBLIC SECTION.
 DATA V1 TYPE CHAR40 VALUE 'HI I AM FROM CLASS ABC DEFINITION'.
ENDCLASS.

*******************************************************************
START-OF-SELECTION.
DATAOBJ2 TYPE REF TO XYZ.
CREATE OBJECT OBJ2,OBJ2->OBJ1.
WRITE:OBJ2->OBJ1->V1.