SAP CLASS ATTRIBUTES



Get Example source ABAP code based on a different SAP table
  



ABAP_OBJ - Attributes of Classes
Attributes are internal data objects of a class of any ABAP data type. The content of the attributes determines the state of the object. Reference variables can also be defined, which can then be used 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 visible from outside the class without restrictions and as such are part of the interface between objects and their users. To encapsulate the state of the object, protected, package-visible, or private attributes must be used. In addition to the visibility, the modifiability of non-private attributes can also be restricted using the addition READ-ONLY in the declaration.
ITOC

Instance Attributes
The content of instance attributes represents the instance-dependent state of the object. Instance attributes are declared using the DATA statement. The addition COMMON PART cannot be used in classes.



Latest notes:

The attempt to access an instance attribute via an initial object reference variable, in contrast to the call of an instance method, results in an exception that is not catchable.
The data types of all class attributes belong to the static properties of a class. A LIKE addition enables the visible class attributes to be referenced using the class component selector or reference variables without first creating an object.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Referring to an instance attribute behind LIKE with the object component selector without creating an instance of the class of the attribute.
ABEXA 00559
ABAP_EXAMPLE_END

Static Attributes
The content of static attributes represents the instance-independent state of the class that is valid for all instances. Static attributes exist once for each class. They are declared using the statement CLASS-DATA and are preserved for the entire runtime. All the objects of a class can access its static attributes. Changes to a static attribute in an object are visible to all other objects of 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, the class component selector or reference variables can be used to refer to the visible attributes of a class, without first creating an object. In this way, the public static properties of global classes can be accessed in every program.

ABAP_EXAMPLE_VX5
Reference to the data type of an instance attribute attr of a global class cl_global. DATA dref TYPE REF TO cl_global.

DATA: f1 LIKE cl_global=>attr,
f2 LIKE dref->attr.
ABAP_EXAMPLE_END

Boxed Components
Like substructures of nested structures, attributes declared as structures can be declared as static boxes using the addition BOXED. In static boxes, initial value sharing takes effect, which leads to fewer memory requirements for little used structures of frequently used objects. A static box used as a boxed component is a deep component that is managed using an internal reference, such as strings and internal tables.