SAP CLASS-METHODS ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID CLASS-METHODS
• CLASS-METHODS ABAP Statement

CLASS-METHODS
Short Reference

ABAP_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 (Only inClasses)
3 CLASS-METHODS class_constructor.


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


AMDP - Methods
5 CLASS-METHODS meth $[DEFAULT IGNORE$|FAIL$]
$[AMDP OPTIONS $[READ-ONLY$] $[CDS SESSION CLIENT clnt$|CURRENT$]$]
$[IMPORTING parameters $[PREFERRED PARAMETER p$]$]
$[EXPORTING parameters$]
$[CHANGING parameters$]
$[RETURNING VALUE(r) typing$]
$[${RAISING exc1$|RESUMABLE(exc1) exc2$|RESUMABLE(exc2) ...$}$]

AMDP Function Implementations for CDSTable Functions (Only in Classes)
6 CLASS-METHODS meth FOR TABLE FUNCTION cds_tabfunc.

What does it do?
The statement CLASS-METHODS declares a static method meth. The naming conventions apply to the name meth.
Using the class component selector (=>), static methods can be used independently of objects. In static methods, the static components of the personal class or their superclasses can be accessed only if the component selector is not used.
The variants of the statement CLASS-METHODS distinguish the following types of method declaration:
General static methods The most general form of the statement CLASS-METHODS allows static methods in classes and interfaces to be declared with any number of input and output parameters.
Functional Static Methods Functional methods of classes and interfaces have exactly one return value and any other formal parameters.
Static constructors Static constructors of classes are methods with the predefined name class_constructor that are called automatically before their class is first used. Static constructors do not have a parameter interface and cannot be declared in interfaces.
Static event handlers Static event handlers are static methods of classes and interfaces that are called by an event of a class or an interface. The only possible formal parameters of an event handler are input parameters that were defined as output parameters of the event.
Static AMDP methods In general, the same rules apply to declarations of static AMDP methods for AMDP procedure implementations and AMDP function implementations that do not implement CDS table functions as to all static methods. There is, however, one special optional addition, AMDP OPTIONS, and no non-class-based exceptions can be declared using EXCEPTIONS .
AMDP function implementations AMDP function implementations declared using the addition FOR TABLE FUNCTION implement a CDS table function in an AMDP class. The formal parameters are determined using the CDS table function. An AMDP function implementation cannot be declared in an interface.



Latest notes:

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 that is visible externally can be called using the class component selector and all names of classes in which it exists. However, the class in which it was declared is always the one that is addressed, which affects the execution of the static constructor or the event handlers.
In the methods of a class, a method of the class hides a built-in function with the same name. This hiding is independent of the type and number of method parameters and the type and number of arguments of the function. This means that a method should not have the same name as a built-in function.
NON_V5_HINTS
ABAP_HINT_END

Return to menu