Tuesday, June 23, 2009

Attributes

Attributes are internal data objects of any ABAP data type within 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 as such are part of the interface between objects and their user. To encapsulate the status of the object, you need to use protected or private attributes. You can also limit the changeability of non-private attributes using the READ-ONLY addition during the declaration.

Instance Attributes

The content of instance attributes forms the instance-specific status of the object. Instance attributes are declared using the DATA statement. You cannot use the COMMON PART addition in classes.

Static Attributes

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 using the CLASS-DATA statement 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 the instance attributes and in particular the 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, the access to the properties of the public static attributes of global classes is possible in every program.

Example

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.

Boxed Components

Attributes declared as structures can be declared as boxed components using the addition BOXED, like substructures of nested structures. In boxed components, initial value sharingcauses less memory to be used for little used structures of much used objects. A boxed component is a deep component administered using an internal reference, like strings and internal tables.

No comments:

Blog Archive