We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!

ABAPINTERFACES_CLASS - INTERFACES CLASS

ABAPINTERFACES_CLASS - INTERFACES CLASS

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   PERFORM Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

INTERFACES - implementation

Short Reference



Syntax

INTERFACES intf
  $[PARTIALLY IMPLEMENTED$]
  ${ ${$[ABSTRACT METHODS meth1 meth2 ... $]
     $[FINAL METHODS meth1 meth2 ... $]$}
  $| $[ALL METHODS ${ABSTRACT$|FINAL$}$] $}
  $[DATA VALUES attr1 = val1 attr2 = val2 ...$].

Additions

1. ... ABSTRACT METHODS meth1 meth2 ...

2. ... FINAL METHODS meth1 meth2 ...

3. ... ALL METHODS ${ABSTRACT$|FINAL$}

4. ... DATA VALUES attr1 = val1 attr2 = val2 ...

Effect

In the public visibility section, the statement INTERFACES implements the interface intf in the class. Additions can also be defined to determine the properties of interface components in the class.

Any local or global interfaces can be specified for intf here that are not already bound in a superclass of the current class. The components of the interfaces become public components of the class after the implementation. An interface component called comp has the name intf~comp in the class, where intf is the name of the interface and the character ~ is the interface component selector. A class must implement all methods of the interface in its implementation part, with the following exceptions:

  • Interface methods declared as optional using the addition DEFAULT.
  • Interface methods specified in the class after the addition ABSTRACT METHODS (making them abstract).
  • Partial implementations are permitted in test classes using the addition PARTIALLY IMPLEMENTED.

Notes

  • A class can implement any number of different interfaces. All of the interfaces implemented by a class are of equal status. If one of the interfaces intf implemented in a class is a composite (meaning it contains component interfaces), these are implemented in the class like individual interfaces, regardless of their nesting hierarchy, and their components are called using the name of their component interface instead of using the name intf. Multiple use of the interface component selection in a name (such as intf1~intf2~comp) is generally not supported.

  • Each interface appears only once in a class and every interface component comp is always clearly accessible using the intf~comp. If the components of an interface appear to be implemented more than once in a class (since it is the interface component or one or more other interfaces), these components also exist only once.

  • If the implementation of a non-optional method of a global interface implemented using INTERFACES is missing in a class, a syntax warning occurs instead of a syntax error. This prevents classes from becoming unusable when later enhancements are made to global interfaces. Calls of a missing implementation, however, always raise an exception of the class CX_SY_DYN_CALL_ILLEGAL_METHOD and produce the runtime error CALL_METHOD_NOT_IMPLEMENTED if the exception is not handled. A real syntax error is produced when local interfaces are used and the implementation is missing.

  • If a class implements a method intf~... of a global interface intf implemented using INTERFACES in its implementation part and the method is not declared in the interface, a warning is displayed in the syntax check. This type of method implementation is dead code that cannot be executed and should be removed. Classes would become unusable after syntax errors if methods were later deleted from an implemented global interface and these methods are ignored by the class (for example, because they are implemented as empty methods). An actual syntax error results when local interfaces are used.


Example

Implementation of an interface intf in a class cls.

INTERFACE intf.
  CLASS-DATA selfref TYPE REF TO intf.
  CLASS-METHODS factory RETURNING VALUE(ref) TYPE REF TO intf.
  ...
ENDINTERFACE.

CLASS cls DEFINITION CREATE PRIVATE.
  PUBLIC SECTION.
    INTERFACES intf.
    ALIASES:
      selfref FOR intf~selfref,
      factory FOR intf~factory.
    ...
ENDCLASS.

CLASS cls IMPLEMENTATION.
  METHOD factory.
    IF selfref IS INITIAL.
      selfref = NEW cls( ).
      ref = selfref.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA(iref) = cls=>factory( ).

Addition 1

... ABSTRACT METHODS meth1 meth2 ...

Addition 2

... FINAL METHODS meth1 meth2 ...

Effect

Using the additions ABSTRACT METHODS and FINAL METHODS, the individual instance methods meth of the interface are made either abstract or final in the class to be implemented. The same rules apply as to the additions ABSTRACT and FINAL of the statement METHODS. In particular, the whole class must be abstract if an interface method is made abstract and no interface methods can be executed at the same time after ABSTRACT METHODS and FINAL METHODS.

The following can be specified as methods meth1, meth2, ...

  • Instance methods that are declared in the interface intf itself
  • Alias names declared in the interface intf for instance methods declared in interfaces that are bound in intf.

For the latter, the name of its own interface with the interface component selector (~) cannot be used. If an interface is bound using multiple INTERFACES statements, the information in the additions FINAL and ABSTRACT must not produce contradictory definitions for the same method.

Example

Definition of abstract methods when binding two interfaces intf1 and intf2 in an abstract class cls. Although intf2 binds the interface intf1, its method meth1 must be made abstract in a separate statement INTERFACES intf1 if there is no alias name for it.

INTERFACE intf1.
  METHODS meth1.
ENDINTERFACE.

INTERFACE intf2.
  INTERFACES intf1.
  METHODS meth2.
ENDINTERFACE.

CLASS cls DEFINITION ABSTRACT.
  PUBLIC SECTION.
    INTERFACES intf1 ABSTRACT METHODS meth1.
    INTERFACES intf2 ABSTRACT METHODS meth2.
ENDCLASS.

Addition 3

... ALL METHODS ${ABSTRACT$|FINAL$}

Effect

Instead of making individual interface methods in the class abstract or final it is possible, using the addition ALL METHODS ${ABSTRACT$|FINAL$}, to make all interface methods either abstract or final.

Example

Integration of an interface intf in an abstract class cls1, in which all methods are made abstract and must be implemented in a subclass cls2.

INTERFACE intf.
  METHODS:
    meth1,
    meth2.
  ...
ENDINTERFACE.

CLASS cls1 DEFINITION ABSTRACT.
  PUBLIC SECTION.
    INTERFACES intf ALL METHODS ABSTRACT.
    ALIASES:
      meth1 FOR intf~meth1,
      meth2 FOR intf~meth2.
ENDCLASS.

CLASS cls2 DEFINITION INHERITING FROM cls1.
  PUBLIC SECTION.
    METHODS:
      meth1 REDEFINITION,
      meth2 REDEFINITION.
ENDCLASS.

CLASS cls2 IMPLEMENTATION.
  METHOD meth1.
    ...
  ENDMETHOD.
  METHOD meth2.
    ...
  ENDMETHOD.
ENDCLASS.

Addition 4

... DATA VALUES attr1 = val1 attr2 = val2 ...

Effect

Using the addition DATA VALUES, initial values can be assigned to individual attributes attr. For attributes, this addition functions in the same way as the addition VALUE of the statement DATA for attributes in its own class.

Only attributes that are themselves declared in the interface intf can be specified as attr1, attr2, ... Attributes declared in interfaces that are bound in intf cannot be specified using alias names or using the name of its own interface with the interface component selector (~).

Constants declared in the interface by the statement CONSTANTS cannot be specified after the addition DATA VALUES.

Note

To specify values for the interface attributes of the component interfaces of a compound interface, the component interface must be directly bound using the statement INTERFACES.

Example

Integration of an interface intf in a class cls, where the interface attributes are provided with start values.

INTERFACE intf.
  CLASS-DATA:
    attr1 TYPE string,
    attr2 TYPE string.
  ...
ENDINTERFACE.

CLASS cls DEFINITION ABSTRACT.
  PUBLIC SECTION.
    INTERFACES intf
      DATA VALUES attr1 = 'Hello'
                  attr2 = 'World'.
    ALIASES:
      attr1 FOR intf~attr1,
      attr2 FOR intf~attr2.
ENDCLASS.

START-OF-SELECTION.
  cl_demo_output=>display( |{ cls=>attr1 } { cls=>attr2 }| ).






Addresses (Business Address Services)   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.

Length: 13088 Date: 20200812 Time: 110539     sap01-206 ( 233 ms )