ABAP Keyword Documentation → ABAP - Reference → Declarations → Declaration Statements → Classes and Interfaces → Components in Classes and Interfaces → Methods
METHODS
Other versions: 7.31 | 7.40 | 7.54
Syntax Forms
General Instance Methods
1. METHODS meth
[ABSTRACT|FINAL]
|[DEFAULT IGNORE|FAIL]
[IMPORTING parameters [PREFERRED PARAMETER p]]
[EXPORTING parameters]
[CHANGING parameters]
[{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
|{EXCEPTIONS exc1 exc2 ...}].
Functional Instance Methods
2. METHODS meth [ABSTRACT|FINAL]
|[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 ...}].
Instance Constructors
3. METHODS constructor [FINAL]
[IMPORTING parameters [PREFERRED PARAMETER p]]
[{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
|{EXCEPTIONS exc1 exc2 ...}].
Event Handlers
4. METHODS meth [ABSTRACT|FINAL]
|[DEFAULT IGNORE|FAIL]
FOR EVENT evt OF {class|intf}
[IMPORTING p1 p2 ... [sender]].
Redefinition of Instance Methods
5. METHODS meth
[FINAL] REDEFINITION.
Test Methods
6. METHODS meth [ABSTRACT|FINAL]
FOR TESTING
[{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}].
Effect
The statement METHODS
declares or redefines an instance method meth
. For the name meth
, the
naming conventions apply.
Instance methods are bound to objects. To use instance methods, an object of the class must first be created. In instance methods, all components of the same class can be accessed without a component selector.
Use the variants of statement METHODS
to distinguish between the following kinds of method declarations:
-
General Instance Methods
The general form of theMETHODS
statement allows the definition of instance methods with any input and output parameters. -
Functional Instance Methods
Functional methods have exactly one return value and any number of formal parameters. -
Instance Constructors
Instance constructors are methods with the given nameconstructor
, which are called automatically when their class is instantiated. Constructors have any number of input parameters and no output parameters. -
Event Handlers
Event handlers are methods that, although they can be called directly with or in statements, are mainly called when an event of a class or an interface is triggered. The only possible formal parameters of an event handler are input parameters, which have been defined as the output parameters of the event. -
Redefinition of Instance Methods
A method declared in a superclass can be redefined in a subclass as long as it is not flagged as final in the superclass. In a redefinition, the interface of the method is not changed. -
Definition of a Test Method
Test methods can be declared in test classes. They have no interface parameters and are called during ABAP Unit tests by the ABAP runtime environment.