SAP METHODS DEFAULT ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• DEFAULT IGNORE METHODS
• DEFAULT FAIL METHODS

METHODS, DEFAULT
Short Reference

ABAP_SYNTAX
METHODS meth ... DEFAULT IGNORE$|FAIL ...

What does it do?
The addition DEFAULT makes the explicit implementation of an interface method optional and defines a default behavior for calls of non-implemented methods. It cannot be used in classes, only in interfaces. All instance methods and static methods can be defined as optional except for constructors and test methods.
A class that implements an interface with the statement INTERFACES can implement its optional methods, but this is not mandatory. The additions IGNORE or FAIL define the behavior that applies when an optional interface method of an object or class is called at runtime and this object or class is not implemented explicitly.
When a non-implemented optional interface method defined with the addition IGNORE is called, the behavior is the same as when it is implemented with an empty body. In particular, all actual parameters are initialized that receive values from formal parameters using pass by value.
Calls of a non-implemented optional interface method defined using the addition FAIL raise an exception of the class CX_SY_DYN_CALL_ILLEGAL_METHOD and, if not handled, results in a runtime error CALL_METHOD_NOT_IMPLEMENTED occurs.
The default behavior defined using DEFAULT also applies to the redefinition of an inherited optional interface method using the addition REDEFINITION. A subclass that redefines an optional interface method does not need to implement it explicitly. If the implementation is missing, the default behavior is applied along a path of the inheritance tree until an explicit implementation occurs.



Latest notes:

The DEFAULT addition can also be used for BAdI methods.
The default behavior defined using DEFAULT FAIL that applies to calls of a non-implemented optional method matches the behavior of calling a non-implemented non-optional method of a regular global interface. In a BAdI interface on the other hand, DEFAULT IGNORE matches the default behavior of the CALL BADI statement.
If an optional interface method is redefined in a subclass, it should also be implemented explicitly in this subclass. The default behavior is usually not as expected.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The class class implements the interface intf without implementing its optional methods. A call of the non-implemented static method m1 raises a handled exception, due to the addition FAIL. A call of the non-implemented instance method m2 does not execute any statements due to the addition IGNORE , but sets their return value r to 0.
ABEXA 00416
ABAP_EXAMPLE_END

Return to menu