
Creating Attributes
Attributes contain data. They define the state of an object, that is the instance of a class.
Prerequisites
You must already have created the internal data types in the class to which you want to refer when you create the attributes. See also :
Creating Internal Types in Classes.
Procedure
Select the class or interface and change to the
Class Editor.
Choose Attributes.
To create an attribute, make the following entries:
- Attribute
Define a unique name with which the attribute is identified. 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
Define the visibility of attributes for the user of the class. Public assigns the attribute to the public area of the class and the attribute can be called by every user of the class. 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.
Attributes that are protected are visible and can be used by the class itself and any of its subclasses.
Attributes that are private are only visible in and available to the class itself. Private attributes therefore are not visible in the subclasses.
- Modeled only
If you have selected this option, the system does not enter the interface in the class pool. You cannot access the components at runtime.
- Typing method
ABAP keyword for defining the type reference. You can choose one of the following: Type, Like or Type Ref To (for class references).
- Reference type
You can use any elementary ABAP type (including generic types) or object type (classes and interfaces).
- Read-Only
This option restricts the changeability of attributes as well as visibility. Users cannot change the attribute if a flag is set.
- Description
Short description of the components.
- Initial value
You must enter an initial value for constants.
Repeat the above steps for each attribute.
Example:

If you need the definition of a structured data object here, click on
and define the structure within the DATA statement in the displayed editor:
DATA: BEGIN OF structure, ...
END OF structure.
Then perform the syntax check.
- Save your entries.
Result
You have created and specified attributes for a class or interface. 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 Only modeled option.