Ansicht
Dokumentation

ABAPMETHODS_DEFAULT - METHODS DEFAULT

ABAPMETHODS_DEFAULT - METHODS DEFAULT

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.
SAP E-Book

METHODS, DEFAULT

Short Reference



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

Effect

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.

Notes

  • 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.

Example

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.






SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   Vendor Master (General Section)  
This documentation is copyright by SAP AG.

Length: 3650 Date: 20240328 Time: 205911     sap01-206 ( 82 ms )