MAIL: abap.guravarao23@gmail.
com Linkedin: Gurava Rao Sap Abap Fresher
INHERITANCE
Inheritance : - Creating a Sub class from Parent class.
The concept of Inheritance allows us to derive new classes from existing classes.
Mutiple Inheritance is not possible in ABAP, but we can achieve multiple Inheritance
with the help of Interfaces.
This class 1 will be called as a Super class or Parent Class )
Class 1 ( Super Class , Parent Class )
Class 2 ( Sub Class , Child Class )
Class 2 will be called as Sub class or Child Class
So What is inheritance Creating a new class from the existing class is called as
inheritance
FINAL CLASS :
A final class is that class which can not be inherited. A final class can not have sub-
classes.
Final class: if you are created final class after you can’t create any sub classes that class.
that type of classes are final class.
I will go to SE 24 Transaction code for Global class
I will give some name to class ZFINALCLASS_28 , I will click on to create button
I Will give some short Description 'Final Class'
There is check box Final , I am creating a Usual Abap Class only Plus This class will act as
a final class also
I will go to Save button
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]
MAIL: [email protected] Linkedin: Gurava Rao Sap Abap Fresher
I will take a method , method will be instance , I will choose the Visibility as PUBLIC
I Will take some parameters in this class , Suppose one input parameter and Four Out
put parameters
Now What is final class means I can not Achieve the Inheritance using this paticular class
So what I will do , I will go to SE 24 I will try to create a sub class using this Final class
Creation of Sub Class or Parent Class :
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]
MAIL: [email protected] Linkedin: Gurava Rao Sap Abap Fresher
will go to SE 24 Transaction code for Global class
I will give some name to Class 'ZSUBCLASS_28' I Will click on to create button
I will give some Short Description
Now I will go to Properties tab -> Click on to Super Class tab I Will pass Final Class which
we created
Into my sub class I am pressing Enter and we can see i am getting Error that our class is
final
We can not create sub class
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]
MAIL: [email protected] Linkedin: Gurava Rao Sap Abap Fresher
So Whenever we have a final class we can't achieve inheritance with the help of that
final class
Creation of Another Class :
I will create a anthor class which will not be final
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]
MAIL: [email protected] Linkedin: Gurava Rao Sap Abap Fresher
I Will go to SE24 (class builder ) transaction code for Global class
I am creating a class which is not final i will give some Description
I will not select this check box as final Class
I will go for Same Method as Display
I will take same to same parameters
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]
MAIL: [email protected] Linkedin: Gurava Rao Sap Abap Fresher
Now I will try to create a sub class using this class
Go to our sub class , now here i will pass the name of the class , which is not my final
class
Go to Properties tab click on Super class here we need to provide class name
'ZCLASS_28' which is not our Final class
Here we can see there is no Error , And whenever i am activating this class and we can
see , This Display method was in my super class and it automatically came into the sub
class
So this is the main advantage of inheritance but we can not achieve if the class is a final
class
Save ( Ctrl + S ) Check ( Ctrl + F2) And Activate ( Ctrl +F3), I will Execute the class
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]
MAIL: [email protected] Linkedin: Gurava Rao Sap Abap Fresher
CREATION OF LOCAL CLASS :
REPORT ZCLASS_FINAL.
DATA : LV_ERDAT TYPE ERDAT,
LV_ERZET TYPE ERZET,
LV_ERNAM TYPE ERNAM,
LV_VBTYP TYPE VBTYP.
PARAMETERS : P_VBELN TYPE VBELN_VA.
CLASS CLASS1 DEFINITION .
PUBLIC SECTION.
METHODS DISPLAY IMPORTING PVBELN TYPE VBELN_VA
EXPORTING PERDAT TYPE ERDAT
PERZET TYPE ERZET
PERNAM TYPE ERNAM
PVBTYP TYPE VBTYP.
ENDCLASS.
CLASS CLASS1 IMPLEMENTATION.
METHOD DISPLAY.
SELECT SINGLE ERDAT ERZET ERNAM VBTYP
FROM VBAK
INTO ( PERDAT, PERZET, PERNAM, PVBTYP )
WHERE VBELN = PVBELN.
ENDMETHOD.
ENDCLASS.
CLASS CLASS2 DEFINITION INHERITING FROM CLASS1.
ENDCLASS.
START-OF-SELECTION.
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]
MAIL: [email protected] Linkedin: Gurava Rao Sap Abap Fresher
DATA : LO_OBJECT TYPE REF TO CLASS2.
CREATE OBJECT LO_OBJECT.
LO_OBJECT->DISPLAY( EXPORTING PVBELN = P_VBELN
IMPORTING PERDAT = LV_ERDAT
PERZET = LV_ERZET
PERNAM = LV_ERNAM
PVBTYP = LV_VBTYP ).
WRITE : / P_VBELN,
LV_ERDAT,
LV_ERZET,
LV_ERNAM,
LV_VBTYP.
Save ( Ctrl + S ) Check ( Ctrl + F2) And Activate ( Ctrl +F3), I will Execute the class
IF YOU HAVE ANY OPPORTUNITIES ON SAP ABAP AS A FRESHER REFER ME AND SEND ME ,
[email protected]