CONSTRUCTORS
CONSTRUCTORS
CONSTRUCTORS
REPORT ZDEMO_OBJCONSTRUCTORS.
*Constructors are special methods that cannot be called using CALL METHOD. Instead,
they are called automatically by the system to set the starting state of a new
object or class.
*Constructors are methods with a predefined name. To use them, you must declare
them explicitly in the class.
*
*Static constructor is declared by CLASS-METHODS CLASS_CONSTRUCTOR statement. Here
the naming convention must be followed. If we give any other name then that will
not be the static constructor. Now static constuctor is called
*1. before any other attributes and methods by using obj->var & obj->meth,
*2. before any other static attributes and methods by using cls=>var & cls=>meth,
*3. before creating of an object by using create object obj,
*4. before registering an event handler method by using set handler cls=>meth for
the object obj.
*
*Below is a program where we have defined a static data and a static constructor.
The static constructor is implemented in the method - endmethod portion. In the
start of selection we write the static attribute but in the output we can see the
static
*constructor function comes first.
*
*----------------------------------------------------------------------*
* CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CLS DEFINITION.
PUBLIC SECTION.
CLASS-DATA V_TXT TYPE CHAR20 VALUE 'Class Constructor'.
CLASS-METHODS CLASS_CONSTRUCTOR.
ENDCLASS. "cls DEFINITION
*----------------------------------------------------------------------*
* CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS CLS IMPLEMENTATION.
METHOD CLASS_CONSTRUCTOR.
WRITE: / 'Today''s Date:', SY-DATUM DD/MM/YYYY.
ENDMETHOD. "class_constructor
ENDCLASS. "cls IMPLEMENTATION
START-OF-SELECTION.
WRITE: / CLS=>V_TXT.