OOPS ABAP- ABSTRACT CLASS AND ABSTRACT METHOD



ABSTRACT CLASS AND ABSTRACT METHOD

ABSTRACT METHOD

A method without Implementation is called Abstract method.

ABSTRACT CLASS

A class which contains at least one Abstract method is called Abstract class.
                                                             Or
A class which contains methods with implementation and without implementation is called Abstract Class.
These Abstract classes and Abstract Methods are used in Inheritance, Polymorphism
* We can't create 'objects' to Abstract Class because they are not fully Classes or Fully Implemented.
*Objects are created for fully class, and to Abstract child class.      

                                ABSTRACT CLASS     

STEPS    

1.      Use tcode SE24 to create a Abstract Class ZMY_ABSTRACT.  
   
     
   
1.      Click on create and remove checkbox FINAL.


1.      Define a method VTTK_HEADER


1.      Define a method VTTK_HEADER

1.      Define a method VTTK_HEADER

 

1.      Define a method VTTK_HEADER
 

 

1.      Provide parameters im_tknum and ex_vttk

 


1.      Double click on method and write the logic



Create another method VTTP_ITEM with parameters im_tknum and ex_vttp





Now place the cursor on our method and click on Detail view option




Now select check box ABSTRACT and click on change, now our method will convert into
ABSTRACT METHOD.

 

ZMY_ABSTRACT HAS 2 METHODS.
1.      VTTK_HEADER
2.      VTTP_ITEM (ABSTRACT METHOD).

CREATING INHERITANCE FOR ABSTRACT CLASS
STEPS

1.      Go to tcode and create Abstract child class
2.      ZMY_ABSTRACT_CHILD.
3.      Click on create and click on Create inheritance option and give super class name as ZMY_ABSTRACT.



Now place the cursor on ABSTRACT METHOD (VTTP_ITEM) and click on REDEFINE ICON



 


Write the code as per requirement





USING ABSTRACT CLASS IN PROGRAM SE38 


*DECLARATION FOR PARAMETER
PARAMETERS P_TKNUM TYPE VTTP-TKNUM DEFAULT '1114'.

*WORK ARAEA AND OBJ DECLARATION
DATA:OBJ TYPE REF TO ZMY_ABSTRACT_CHILD,
     EX_VTTP 
TYPE VTTP.
CREATE OBJECT OBJ.
*CALLING METHOD
CALL METHOD OBJ->VTTP_ITEM
  
EXPORTING
    IM_TKNUM 
P_TKNUM
  
IMPORTING
   EX_VTTP  
EX_VTTP
    
.
*DISPLAYING THE DATA
WRITE:/ EX_VTTP-TKNUM,EX_VTTP-TPNUM,
        EX_VTTP
-VBELN,EX_VTTP-TPRFO,
        EX_VTTP
-ERNAM,EX_VTTP-ERDAT.

OUTPUT