ABAP Keyword Documentation → ABAP - Reference → Declarative statemnts → Classes and Interfaces → Components in Classes and Interfaces → Data Types and Attributes
CLASS-DATA
Other versions: 7.31 | 7.40 | 7.54
Syntax
CLASS-DATA attr [options].
Effect
The statement 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.
The naming conventions apply to the name
attr. The syntax of the additions options
is identical to the statement
DATA
for instance attributes (only
the addition WITH HEADER LINE
must not be used).
Notes
- 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 addresssed, 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.
-
You can access static attributes declared with
CLASS-DATA
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, that is they are created in internal mode of a program when the class is loaded. 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
BOXED
.
Example
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.
WRITE c1=>text.