Creating 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 two types of methods: Instance methods, which always refer to a particular class instance, and static methods, which are shared by all class instances. Static methods can only address static attributes.

Prerequisites

You must already have created a 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.

The following description assumes that you are familiar with the principles of ABAP Objects.

Procedure

  1. Start the Class Editor in change mode.
  2. Choose Methods.
  3. To create a method, enter the following information:

    - Methods
    A unique name to identify the method. 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
    Defines the visibility of the method for the users of your class. If the method is public, it is assigned to the public section of the class, and can be called by any user. 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
    If you select this option, the system does not enter the method in the class pool. You cannot then address it at runtime.

    - Description
    Short description of the method.
  4. Repeat steps 1-3 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:
  5. 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. For details of how to do this, refer to Creating parameters and exceptions.