You are on page 1of 17

Assignment 2 Submission

Master SAP OOPs ABAP

Submitted by - Oscar W. Navarrete


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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?

"1. You have to give the name of the object


DATA: go_demo1 TYPE REF TO zcl_ooabap_demo1.

"2. Allocate the memory for the object


CREATE OBJECT go_demo1.

Q2. What is the keyword to create an object of a class in one go (i.e., using one
statement)?

Using the operator NEW.

DATA(ob_demo1) = NEW zcl_ooabap_demo1( ).

Q3. What are the different types of Inheritance in OOPS programmingand what is supported by
ABAP?

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 1


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

 Multilevel inheritance. – Supported by ABAP.

 Multiple inheritance. – Have to be worked around with Interfaces.

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.

 A large number of subclasses may also indicate an unsuitable level of abstraction.

To prevent unintended reuse of your classes by inheritance, we recommend that you use final classes
to close the paths of inheritance trees.

Note

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 2


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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.

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 3


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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

4. Create the Class ZCL_OOABAP_DEMO_C


 Add the Interfaces:
 ZIF_OOABAP_DEMO1_A
 ZIF_OOABAP_DEMO1_B.

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 4


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

Create two interfaces:

1. ZIF_PURCHASE_ORDER

2. ZIF_SALES_ORDER

As show in the below picture:

ZIF_PURCHASE_ORDER:

Create a method GET_PO_DETAIL with an exporting parameter of type EKKO.

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 5


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

ZIF_SALES_ORDER: Define method GET_SO_DETAIL with exporting parameter of type VBAK.

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 6


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 7


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

Define method ~GET_SO_DETAIL as below:

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.

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 8


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

Define ZIF_PURCHASE_ORDER~GET_PO_DETAIL as below:

METHOD zif_purchase_order~get_po_detail.

NEW zcl_po_order( )->zif_purchase_order~get_po_detail(


IMPORTI
NG
es_po_detail = es_po_detail " Purchasing Document
Item
).

ENDMETHOD.

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 9


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 10


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 11


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

Class Methods

ZCL_O40_MULTIPLE_INTHERITENCE

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 12


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

Test Class - ZCL_O40_MULTIPLE_INTHERITENCE

TestObject->ZIF_O40_PURCHASE_ORDER~

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 13


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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()

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 14


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

20 Days Notes & 20 Days Recordings of Master OOPs ABAP is in this ZAPYard.com Training Page

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 15


Assignment 2 – OOPs
Oscar Navarrete – ID O40ON

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?

 Public: Visible for all user.


 Protected: Visible for all user but cannot be changed.
 Private: Not visible at all.

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:

 Public members of superclass become private members of subclass


 Protected members of superclass become private members of subclass
 Private members of superclass cannot be accessed by subclass

3. Protected Inheritance:

 Public members of superclass become protected members of subclass


 Protected members of superclass become protected members of subclass
 Private members of superclass cannot be accessed by subclass.

Q6. What is the difference between Me and Super Keywords?

 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.

 SUPER Keyword refer to the immediate parent implemented.

WhatsApp +1-251-727-9273 All ZAPYard’s LIVE Training History mail@ZAPYard.com Page 16

You might also like