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

What is an Interface in SAP ABAP?

An interface in ABAP defines a contract that any implementing class must follow. It contains only declarations of:

  • Methods (without implementation)
  • Constants
  • Types
  • Attributes

Interfaces do not contain implementation. Any class that implements an interface must provide the logic for all its methods.

Feature Description
No implementation Only method signatures are defined.
Multiple interfaces A class can implement more than one interface.
Full implementation required All interface methods must be implemented in the class.
Promotes loose coupling Ideal for modular, testable, flexible code.

 

Code:

REPORT zrep_lclclass.

INTERFACE if_animal.
  METHODS:
    speak,
    move.
ENDINTERFACE.

" Class that implements the interface
CLASS lcl_dog DEFINITION.
  PUBLIC SECTION.
    INTERFACESif_animal.
ENDCLASS.

CLASS lcl_dog IMPLEMENTATION.
  METHOD if_animal~speak.
    WRITE'Woof!'.
  ENDMETHOD.

  METHOD if_animal~move.
    WRITE'Dog is running'.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA(lo_dogNEW lcl_dog).
  lo_dog->if_animal~speak).
  lo_dog->if_animal~move). 

Output:

Related Questions

Leave an answer

Leave an answer