![]() |
ABAP(Advanced Business Application Programming) is an object-oriented programming language that supports many oops concepts like other programming languages. It supports all the four pillars of oops i.e. Inheritance, Polymorphism, Abstraction, and Encapsulation. The interface is one of the oops concepts that ABAP supports and it plays a very important role in implementing all these oops concepts. Table of Content What is Interface in SAP ABAPThe interface in SAP ABAP is different from the class, it can not have any implementation like the class. It defines a set of method declarations that a class must implement without providing any implementation detail of that method. Interface helps in achieving multiple inheritance. Multiple inheritance can be defined as a class can inherit multiple interfaces. Due to Inheritance interface provides a base for polymorphism because the method declared in the interface behaves differently in different classes. Like class Interface can be defined locally or globally in the ABAP programming language. Syntax for Creating an Interface in SAP ABAPSyntax INTERFACE interface-name Syntax of interface explained: Here INTERFACE is a keyword for declaring interface and interface-name is the name of interface. DATA declaration is declaring the data. METHOD declaration is declaring the method .It is important to note that all the methods declared in interface are Abstract. You can also declare many field like EVENT, CONSTANT etc. At the end of interface we declare ENDINTERFACE. Implementation of Interface Inside Class in SAP ABAPINTERFACE interface_name
Explanation: First we create a class inside that we use above syntax to implement interface. here interface_name means name of interface. Implementing method of an interface inside class in SAP ABAPMETHOD interface_name~interface_method_name Explanation: we use METHOD keyword to implement method of interface inside implementing class, interface_name~interface_method_name refers to the name of interface along with method name declare in interface. Example ProgramHere is an example of interface and a class implementing that interface. * Creating interface Output 15 Program Execution – Creating Objects ‘object1’ and ‘object2’Creating object 1 and calling add method *creating object Output Addition of given number is 15
Here we have created an object object1 of class my_class1 and call the add method of interface my_interface1 implemented in my_class1. After calling the output will be 15. Creating object2 and calling subtract method *creating object2 Output Subtraction of given number is 10
Here we have created an object object2 of class my_class1 and call the subtract method of interface my_interface1 implemented in my_class1. After calling the output will be 10. Benefits and Application of Interface in SAP ABAP
|
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |