Methods

Methods are internal procedures of a class that determine the behavior of an object. They can access all the attributes of their class and can thus change the object status. Methods have a parameter interface, through which the system passes values to them when they are called, and through which they can return values to the caller. The private attributes of a class can only be changed using methods.

A method meth is declared in the declaration section of a class and in the implementation part of the class using the processing block.

METHOD meth.
  ...
ENDMETHOD.

You can declare local data types and data objects in methods, just as in all procedures. Methods are called using the CALL METHOD statement or one of its abbreviated forms. You can also call the method dynamically (dynamic invoke).

Instance methods

Instance methods are declared using the METHODS statement. They can access all the attributes of a class and can trigger all its events.

Static methods

Static methods are declared using the CLASS-METHODS statement. They can access static attributes of a class and are allowed only to trigger static events.

Constructors

As well as the normal methods that are called using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are called automatically when an object is created or when a class component is accessed for the first time.

Functional methods

Functional methods are methods with any number of IMPORTING parameters and one RETURNING parameter. Apart from CALL METHOD, you can also use the following expressions to insert functional methods at operand positions:

The use of functional methods in operand positions is restricted to:

The functional method is entered instead of an operand. When the statement is executed, the method is called and the return value is used as an operand. With such a call, only class-based exceptions can be handled.