Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  Classes and Interfaces →  CLASS 

CLASS - IMPLEMENTATION

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CLASS class IMPLEMENTATION. 
  ...
  METHOD ...
    ...
  ENDMETHOD.
  ...
ENDCLASS.

Effect

In the statement block CLASS class IMPLEMENTATION - ENDCLASS, the following methods of a class class must be implemented, in any order:

  • All concrete methods that are declared using METHODS or CLASS-METHODS in the declaration part of the class.
  • All concrete methods of interfaces that are listed by the statement INTERFACES in the declaration part of the class.
  • All methods inherited from superclasses that are listed by the statement METHODS ... REDEFINITION in the declaration part of the class.

The implementation of each method corresponds to a processing block METHOD - ENDMETHOD. No statements are allowed in the implementation part outside of method implementations. All components of the class can be accessed in an instance method implementation. All static components of the class can be accessed in a static method implementation. You do not need a component selector to address the component of your own class. Within the implementation of each instance method, there is an implicitly created, local reference variable named me available at runtime. It points to the current instance of the method.

When implementing methods declared in an interface bound by the class INTERFACES intf, the name of the method in METHOD must have either intf~ in front of it or use an alias name declared using ALIASES. The interface method must be declared in the interface. Otherwise, a syntax error will occur when local interfaces are used. If you specify a global interface using intf~, only a syntax warning is issued. In this way, the classes remain usable even after subsequent removal of the methods from the global interface, provided they have not used the methods themselves.


Notes

  • A class that does not need to implement any methods on the basis of its declaration part either has an empty implementation part or none at all.
  • Abstract methods in abstract classes cannot be implemented in the implementation part.
  • The implementation part of a class can only be specified in the context described under CLASS.

Example

In this example, three methods of the class c2 must be implemented. The method m1 in c1 is abstract and must not be implemented there.

INTERFACE i1. 
  METHODS m1. 
ENDINTERFACE. 

CLASS c1 DEFINITION ABSTRACT. 
  PROTECTED SECTION. 
    METHODS m1 ABSTRACT. 
ENDCLASS. 

CLASS c2 DEFINITION INHERITING FROM c1. 
  PUBLIC SECTION. 
    INTERFACES i1. 
    METHODS m2. 
  PROTECTED SECTION. 
    METHODS m1 REDEFINITION. 
ENDCLASS. 

CLASS c2 IMPLEMENTATION. 
  METHOD m1. 
    ... 
  ENDMETHOD. 
  METHOD m2. 
    ... 
  ENDMETHOD. 
  METHOD i1~m1. 
    ... 
  ENDMETHOD. 
ENDCLASS.