Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarations →  Declaration Statements →  Classes and Interfaces →  Components in Classes and Interfaces →  Methods 

CLASS-METHODS

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax Forms


General Static Methods

1. CLASS-METHODS meth [DEFAULT IGNORE|FAIL]
   [IMPORTING parameters [PREFERRED PARAMETER p]]
    [EXPORTING parameters]
    [CHANGING parameters]
    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
    |{EXCEPTIONS exc1 exc2 ...}].

Functional Static Methods

2. CLASS-METHODS meth [DEFAULT IGNORE|FAIL]
    [IMPORTING parameters [PREFERRED PARAMETER p]]
    [EXPORTING parameters]
    [CHANGING parameters]
    RETURNING VALUE(r) typing
    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
    |{EXCEPTIONS exc1 exc2 ...}].

Static Constructors

3. CLASS-METHODS class_constructor.

Event Handlers

4. CLASS-METHODS meth [DEFAULT IGNORE|FAIL]
     FOR EVENT evt OF {class|intf}
     [IMPORTING p1 p2 ... [sender]].

Effect

The CLASS-METHODS statement declares a static method meth. For the name meth, the naming conventions apply.

With the class component selector (=>), static methods can be used independently of objects. In static methods, the static components of the class or its superclasses can be accessed only if the component selector is not used.

Using the variants of the CLASS-METHODS statement, different types of method declaration are possible:

  • General Static Methods
    The most general form of the CLASS-METHODS statement allows static methods to be defined with any number of input and output parameters.
  • Functional Static Methods
    Functional methods have exactly one return value and any number of formal parameters.
  • Static Constructors
    Static constructors are methods with the predefined name class_constructor, which are automatically called before their class is first used. Static constructors have no parameter interface.
  • Static Event Handlers
    Static event handlers are static methods that are called by an event of a class or an interface. The only possible formal parameters of an event handler are input parameters, which have been defined as the output parameters of the event.


Note

Like all static components in the inheritance, the static methods of a superclass exist in all subclasses. A static method is always executed in the class in which it was declared. A static method which is visible from outside can be called using the class component selector, as can all names and classes in which it exists. The class in which it was declared is always the one that is addressed. This has an influence on the execution of the static constructor or on the event handlers.

Continue

CLASS-METHODS - IMPORTING, EXPORTING, CHANGING, RAISING

CLASS-METHODS - RETURNING

CLASS-METHODS - class_constructor

CLASS-METHODS - FOR EVENT