Attributes are data objects of any ABAP data type that are internal to a class. The content of the attributes specifies the status of the object. You can also define reference variables, which you can then use to create and address objects. This allows objects to be accessed within classes.
Attributes are defined in the declaration part of a class. Public attributes are completely visible
from outside the class and are therefore part of the interface between objects and their users. To encapsulate
the status of the object, you need to use protected, package-visible, or private attributes. You can
also restrict the changeability of non-private attributes using the
READ-ONLY addition during the declaration.
The content of static attributes forms the instance-independent status of the object, which is valid
for all instances of the class. Static attributes are available once for each class. They are declared
and are retained throughout the entire runtime. All the objects within a class can access its static attributes. Changes to a static attribute in an object are visible to all other objects within that class.
Data Types of Attributes
The data types of all attributes, including instance attributes and in particular
bound data types, belong
to the static properties of a class. Therefore, in a
LIKE addition, you can
use the class component selector or reference variables to refer to the visible attributes of a class
without first creating an object. In this way, you can access the properties of the public static attributes of global classes from every program.
Reference to the data type of an instance attribute
attr of a global class
DATA dref TYPE REF TO cl_global.
DATA: f1 LIKE cl_global=>attr,
f2 LIKE dref->attr.
Attributes declared as structures can be declared as
static boxes using the
BOXED addition, like substructures of nested structures. With static boxes,
initial value sharing results in reduced memory requirement for infrequently used structures of regularly used objects. As a
boxed component, a static box is a deep component administered using an internal reference, like strings and internal tables.