- Syntax :
Class Parent Definition.
--------------
----------------
EndClass.
Class Child Definition Inheriting from Parent.
-----------
-----------
------------
EndClass.
Ex :-
Steps :-
Source Code.
CLASS PARENT_VBAP DEFINITION.
PUBLIC SECTION.
METHODS : FETCH_DATA IMPORTING IM_VBELN TYPE VBAP-VBELN
CHANGING CH_ITAB TYPE VBAP_T,
DISPLAY IMPORTING IM_ITAB TYPE VBAP_T.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS PARENT_VBAP IMPLEMENTATION.
METHOD FETCH_DATA.
SELECT * FROM VBAP INTO TABLE CH_ITAB WHERE VBELN = IM_VBELN.
ENDMETHOD.
METHOD DISPLAY .
DATA : WA_VBAP TYPE VBAP.
LOOP AT IM_ITAB INTO WA_VBAP.
WRITE : / WA_VBAP-VBELN , WA_VBAP-POSNR , WA_VBAP-MATNR ,
WA_VBAP-ARKTX , WA_VBAP-NETWR.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
CLASS CHILD_CLASS DEFINITION INHERITING FROM PARENT_VBAP.
PUBLIC SECTION.
METHODS : FETCH_DATA REDEFINITION.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS CHILD_CLASS IMPLEMENTATION.
METHOD FETCH_DATA.
CALL METHOD SUPER->FETCH_DATA " Calling parent Class method
EXPORTING
IM_VBELN = IM_VBELN
CHANGING
CH_ITAB = CH_ITAB.
DATA : IT_VBAK TYPE TABLE OF VBAK,
WA_VBAK TYPE VBAK.
SELECT * FROM VBAK INTO TABLE IT_VBAK FOR ALL ENTRIES IN CH_ITAB
WHERE VBELN = CH_ITAB-VBELN.
LOOP AT IT_VBAK INTO WA_VBAK.
WRITE : / WA_VBAK-VBELN , WA_VBAK-ERDAT , WA_VBAK-ERNAM ,
WA_VBAK-VKORG , WA_VBAK-KUNNR.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
" MAIN PROGRAM.
DATA : OBJ TYPE REF TO CHILD_CLASS.
DATA : IT_VBAP TYPE TABLE OF VBAP.
PARAMETERS : P_VBELN TYPE VBAP-VBELN.
START-OF-SELECTION.
CREATE OBJECT OBJ.
CALL METHOD OBJ->FETCH_DATA
EXPORTING
IM_VBELN = P_VBELN
CHANGING
CH_ITAB = IT_VBAP .
ULINE.
CALL METHOD OBJ->DISPLAY
EXPORTING
IM_ITAB = IT_VBAP.
No comments:
Post a Comment