CLASS-DATA
Short Reference
ABAP Syntax CLASS-DATA attr [ options ].
What does it do? 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).
Latest 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 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-DATA can 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,
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 ABAP Coding 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 ).
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved