INHERITANCE :
One of the most important concepts in object oriented programming is that of inheritance(common in all oops programming language). Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application.
One of the most important concepts in object oriented programming is that of inheritance(common in all oops programming language). Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application.
- An object of one class can acquire the properties of another class.
- Derived class inherits the data and methods of a super class. However, they can overwrite methods and also add new methods.
CLASS <subclass> DEFINITION INHERITING FROM <superclass>.
*&---------------------------------------------------------------------* *& Report ZINHERITANCE *& *&------------------------------------------------------------------ REPORT ZINHERITANCE. PARAMETERS: s_matnr type mara-matnr. DATA: wa_mara TYPE mara. DATA: WA_MAKT_TEMP TYPE MAKT. CLASS SUPER_cLA DEFINITION. PUBLIC SECTION. METHODS GET_MATERIAL IMPORTING IM_MATNR TYPE MARA-MATNR EXPORTING EX_MARA TYPE MARA. ENDCLASS. CLASS SUPER_CLA IMPLEMENTATION. METHOD GET_MATERIAL. SELECT SINGLE * FROM MARA INTO EX_MARA WHERE MATNR = IM_MATNR. ENDMETHOD. ENDCLASS. ******* FOR INHERITANCE ALWAYS WRITE INHERITANCE FROM AND
BESIDE METHODS WRITE
REDIFINITION***** CLASS CHILD_CLAS DEFINITION INHERITING FROM SUPER_CLA. PUBLIC SECTION. DATA : wa_makt type makt. METHODS : GET_MATERIAL REDEFINITION. "INHERITANING USING REDEFINTION" ENDCLASS. ********CHILD CLASS IMPLEMENTATION****************** CLASS CHILD_cLAS IMPLEMENTATION. METHOD: GET_MATERIAL. CALL METHOD SUPER->GET_MATERIAL "CALL METHOD TO GET MATERIAL EXPORTING IM_MATNR = S_MATNR IMPORTING EX_MARA = EX_MARA. SELECT SINGLE * from makt INTO WA_MAKT WHERE MATNR = WA_MARA-MATNR.ENDMETHOD. ENDCLASS. START-OF-SELECTION.
DATA: LO_OBJ TYPE REF TO CHILD_CLAS. CREATE OBJECT LO_OBJ. "CREATE OBJECT OF CHILD CLASS" CALL METHOD LO_OBJ->GET_MATERIAL EXPORTING IM_MATNR = S_MATNR IMPORTING EX_MARA = WA_MARA. WA_MAKT_TEMP = LO_OBJ->WA_MAKT. WRITE:/' MATERIAL DETAILS ', WA_MARA-MATNR , WA_MARA-MTART, WA_MARA-MEINS,
WA_MARA-MATKL. WRITE: /'MATERIAL DETAILED DESCRIPTION',WA_MAKT_TEMP-MATNR , WA_MAKT_TEMP-MAKTX.