Creating Attributes
Attributes contain data. They define the state of an object.
Prerequisites
You must already have created the internal data types in the class to which you want to refer when you create the attributes. For further information, refer to
Creating Internal Types in Classes.
Procedure
Start the Class Editor in change mode.
Choose Attributes.
To create an attribute, enter the following:
- Attribute
A unique name that identifies the attribute. Remember to observe the
naming conventions in ABAP Objects.
- Type
You can specify an attribute as a constant, an instance attribute, or a static attribute (that is shared by all instances of the class).
- Visibility
Defines the visibility of attributes to users of the class. If an attribute is public, it is assigned to the public section of the class and can be addressed by any user. Remember that public attributes form part of the external point of contact to the class, and as such stand in the way of full encapsulation.
Protected attributes are visible in and can be addressed by all subclasses of the class.
Private attributes are only visible in and can only be addressed by the defining class. In particular, they are not visible in the subclasses of the class.
- Modeled
If this option is set, the system does not enter the component in the class pool and the component cannot be addressed at runtime.
- Read Only
If this option is set, users cannot change this attribute.
- Typing method
ABAP keyword to specify the type reference. You can use TYPE, LIKE or
Type Ref To (for class references).
- Reference type
This may be any elementary ABAP type (including generic types) or an object type (classes and interfaces).
- Description
Short description of the component
- Initial value
If the attribute is a constant, you must specify an initial value.
Repeat steps 1 to 3 for each attribute.
Example:
Save your entries.
Result
You have now created a set of attributes. The system generates the corresponding ABAP code in the definition part of the class or interface pool for all of the attributes except those for which you set the Modeled option.