CLASS-DATA attr [options].
CLASS-DATA can only be used in the declaration part of a class
or an interface. The statement declares a static attribute
attr whose validity
is not associated with instances of a class but with the class itself. All instances of the class and its subclasses access the same static attribute.
- Like all static components in the inheritance, the static attributes of a superclass exist in all subclasses. A static attribute that is visible externally can be addressed using the class component selector along with all the names of the classes in which it exists. This means that the class in which it is declared is always addressed, which, for example, has an impact on how the static constructor is executed. A change made to the static attribute applies to all classes in which it exists, independently of the addressing.
Static attributes declared using
CLASS-DATAcan be accessed by using the class component selector only with class names, and not with interface names.
- The static attributes of a shared memory-enabled class are handled in the same way as a normal class, which means they are created in the internal session of a program when the class is loaded there. If a number of programs access the same shared objects, the static attributes of the corresponding classes exist more than once and independently of one another in the programs.
Structured static attributes can be declared as a
static box using the addition
In this example, the static attribute
text of class
c1 is accessed using the class component selector without having created an instance of the class.
CLASS c1 DEFINITION. PUBLIC SECTION. CLASS-DATA text TYPE string VALUE `Static data`. ENDCLASS. START-OF-SELECTION. cl_demo_output=>display_text( c1=>text ).