Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

How to achieve multiple inheritance using interface in SAP ?

A class can implement multiple interfaces at once, which allows you to combine functionality from many sources.

Example: 

” First interface
INTERFACE if_flyable.
METHODS: fly.
ENDINTERFACE.

” Second interface
INTERFACE if_swimmable.
METHODS: swim.
ENDINTERFACE.

” A class implementing multiple interfaces
CLASS cl_duck DEFINITION.
PUBLIC SECTION.
INTERFACES: if_flyable,
if_swimmable.
METHODS: display.
ENDCLASS.

CLASS cl_duck IMPLEMENTATION.
METHOD if_flyable~fly.
WRITE: / ‘The duck is flying.’.
ENDMETHOD.

METHOD if_swimmable~swim.
WRITE: / ‘The duck is swimming.’.
ENDMETHOD.

METHOD display.
WRITE: / ‘I am a duck with multiple abilities!’.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(duck) = NEW cl_duck( ).

duck->display( ).
duck->if_flyable~fly( ).
duck->if_swimmable~swim( ).

Output:

I am a duck with multiple abilities!
The duck is flying.
The duck is swimming.

Key Points:
  • CLASS … DEFINITION uses INTERFACES: to include multiple interfaces.

  • Methods from interfaces must be implemented in the class.

  • When calling interface methods, you can:

    • Use fully qualified names: object->if_interface~method( )

    • Or, if redefined explicitly as public methods, call them directly.

  • This is the standard way to achieve “multiple inheritance” in ABAP.

 

Related Questions

Leave an answer

Leave an answer