Professional Documents
Culture Documents
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Q1. What are two steps need to be performed to create an object of a class?
Q2. What is the keyword to create an object of a class in one go (i.e., using one
statement)?
Q3. What are the different types of Inheritance in OOPS programmingand what is supported by
ABAP?
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Inheritance
Background
Inheritance is the method by which subclasses are derived from a superclass while inheriting the
components of the superclass. A subclass can be made more specific by declaring new components
and redefining instance methods. ABAP Objects supports simple inheritance, in which a class can
have multiple subclasses but only one direct superclass. (Despite this, the interface concept does enable
something like multiple inheritance to take place, at least with regard to attributes and method
declarations. Method implementations, on the other hand, are not inherited when an interface is
included.) This creates an inheritance hierarchy in an inheritance tree, with a unique path running from
each subclass to a root class. In ABAP Objects, all classes are subclasses of the predefined abstract
root class object. Final classes (classes defined using the addition FINAL) close the bottom of a path
in the inheritance tree.
Rule
Avoid using deep inheritance hierarchies
Avoid using deep inheritance hierarchies, since they are often difficult to maintain.
Details
Deep inheritance hierarchies are examples of successful reuse, but are also the source of maintenance
problems, due to the complexity inherent in the large number of classes involved.
The behavior of classes deep down in the inheritance hierarchy is difficult to predict, since they
potentially inherit from a large number of methods.
Classes with a lot of subclasses exert great influence on the system as a whole, making the
consequences of modifications to a superclass hard to predict.
To prevent unintended reuse of your classes by inheritance, we recommend that you use final classes
to close the paths of inheritance trees.
Note
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
If your main aim is to exploit the possibilities of polymorphy, then interfaces are often a preferable
solution to inheritance. If all you want to do is use interfaces, then method interfaces should be used
instead of abstract classes. These can be used to create composite interfaces. In ABAP, on the other
hand, a composite interface is impossible due to the nature of simple inheritance using classes.
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Q4. What is the workaround to achieve multiple inheritance? Explain with an Example.
Hint. We can achieve using the Interfaces to get visibility of Attributes and Methods of two
classes, into a third class.
Steps:
1. Create the interfaces: ZIF_OOABAP_DEMO1_A, and ZIF_OOABAP_DEMO1_B.
2. Add the Interface: ZIF_OOABAP_DEMO1_A, Attributes and Methods into the below class:
Class: ZCL_OOABAP_DEMO_A
Attributes:
o ZIF_OOABAP_DEMO1_A~A1
o ZIF_OOABAP_DEMO1_A~A2
Methods:
o ZIF_OOABAP_DEMO1_A~AM1
o ZIF_OOABAP_DEMO1_A~AM2
3. Add the interface: ZIF_OOABAP_DEMO1_B, Attributes and Methods into the below class:
Class: ZCL_OOABAP_DEMO_B
Attributes:
o ZIF_OOABAP_DEMO1_B~B1
o ZIF_OOABAP_DEMO1_B~B2
Methods:
o ZIF_OOABAP_DEMO1_A~BM1
o ZIF_OOABAP_DEMO1_A~BM2
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
1. ZIF_PURCHASE_ORDER
2. ZIF_SALES_ORDER
ZIF_PURCHASE_ORDER:
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Create the class ZCL_MULTIPLE_INTHERITENCE which will be inheriting both the interfaces.
ZCL_O40_MULTIPLE_INTHERITENCE
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
METHOD zif_sales_order~get_so_detail.
DATA: lo_so_detail TYPE REF TO
zcl_so_order.
CREATE OBJECT lo_so_detail.
lo_so_detail>zif_sales_order~get_so_de
tail( IMPORTING
es_so_detail = es_so_detail " Sales Document: Header Data
).
ENDMETHOD.
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
METHOD zif_purchase_order~get_po_detail.
ENDMETHOD.
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Solution:
Interfaces:
ZIF_O40_PURCHASE_ORDER
ZIF_O40_SALES_ORDER
Methods:
ZIF_O40_SALES_ORDER~GET_SO_DETAIL
ZIF_O40_PURCHASE_ORDER~GET_PO_DETAIL
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Classes:
ZCL_O40_PO_ORDER
ZCL_O40_SO_ORDER
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Class Methods
ZCL_O40_MULTIPLE_INTHERITENCE
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
TestObject->ZIF_O40_PURCHASE_ORDER~
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
TestObject->ZIF_O40_PURCHASE_ORDER~GET_PO_DETAIL()
TestObject->ZIF_O40_SO_ORDER~
TestObject->ZIF_O40_SALES_ORDER~GET_SO_DETAIL()
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page
Q5. What is the difference in the visibility level of Public, Protected and Private?
1. Public Inheritance:
Public data and members of superclass become public data and members of subclass
Protected members of superclass become protected members of subclass
Private members of superclass cannot be accessed by subclass
2. Private Inheritance:
3. Protected Inheritance:
ME Keyword is used when there is a local variable declaration with the same variable
name which is present or declared as a global variable. ME keyword is used to access the
global variable.