Creating and Defining Methods
Methods describe how an object behaves. You implement them using functions defined within classes. They are operations that change the attributes of a class or interface. There are instance- and static methods. Instance methods refer to a certain class instance, whereas static methods are common to all the class instances. Static methods can only address static attributes.
The special methods include constructors and class constructors. Constructors (class constructors) need not be created explicitly if they are not to be implemented.
Prerequisites
You must already have created the class or interface. It is useful if you have already created the attributes of the class, since you can branch directly from a method definition in the Class Builder to its implementation.
Procedure
To create methods for classes and interfaces:
- Change to the
Class Editor.
Choose Methods.
To create a method, make the following entries:
- Methods
Define a unique name with which the method is identified.
Remember to observe the
naming conventions for ABAP Objects.
- Type
Specifies the type as an instance method or a static method (not instance-specific).
- Visibility
Define the visibility of methods for the user of the class. Public assigns the method to the public area of the class and the method can be called by every user of the class. If you make the method protected, it is visible to and can be used by the class itself and any of its subclasses. If the method is private, it is only visible in and available to the class itself. Private methods do not form part of the external point of contact between the class and its users.
- Modeled only
If the flag is set, no entry will be made in the class pool. You cannot access the components at runtime.
- Description
Short description of the method.
Repeat the above steps for any further methods.
If you create a constructor or class constructor method, it is assigned the predefined name CONSTRUCTOR or CLASS_CONSTRUCTOR respectively. The Class Builder also predefines certain other attributes.
Example:
Save your entries.
Result
You have now created methods for an object type. These are included in the definition part of the class or interface, that is, generated into the corresponding class pool or interface pool.
Before you can implement the methods, you must create your parameters and exceptions.
See also:
Creating Parameters and Exceptions
Implementing Methods
Creating Event Handler Methods