Wednesday 7 September 2016

Global Class : Inheritance

Ex :-

Steps :-

  • Go to Transaction code SE24.
  • Enter the Class name which start's with ZCL_< class name > and click on Create.

  • Pop-up will appear.
  • Enter the Description.
  • Un-check the Final.
  • Click on SAVE.




  • Assign the Package.
  • Enter the Method name , Level , Visibility and Description.
  • Place the cursor on Method name and click on Parameters to assign parameters.
  • Pass the importing , exporting , changing parameters.
  • Click on Methods.
  • Double click on Method name.



  • Enter the logic.
  • Click on Save.
  • Click on Back.
  • Create one more method to display data.
  • Place the cursor on method name and click on Parameters.


  • Pass the parameters and press Enter.
  • Click on Methods.

  • Double click on Method name.
  • Pop-up will appear.
  • Click on Yes.
  • Enter the Logic.
  • Click and SAVE and Back.



  • Save -> Check -> Activate.
  • Copy the parent Class name.
  • Click on Back button.

Class Inheritance Steps :-

  • Enter the Class name which start's with ZCL_< class name > and click on Create.

  • Enter the short description.
  • Click on Create Inheritance.

  • Enter the Super Class name.

  • Click on Save Button.
  • Save it in either Local Package or Package.

  • Child inherit's properties of Parent Class.


To Re-define the Method

  • Select method which to be re-define and click on Redefine.

  • Look like,
  • Enable Super Class method.

  • Pass the parameters and redefine the inherited super class method.

  • Logic.
CALL METHOD SUPER->FETCH_DATA_VBAP
  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-VKORG , WA_VBAK-KUNNR , WA_VBAK-ERDAT.

ENDLOOP.


  • Click on Save .
  • Click on Back.
  • Save -> Check -> Activate.
  • Copy the Child class name.

Main Program :-

  • Go to Transaction Code SE38.

  • Enter the program name which start's with Y or Z < program name > and click on Create.


  • Pop-up will appear.
  • Enter the Title.
  • Select the Attribute Type as Executable Program.
  • Click on SAVE.

  • Source Code




DATA : OBJ TYPE REF TO ZCL_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_VBAP
  EXPORTING
    IM_VBELN =  P_VBELN
  CHANGING
    CH_ITAB  =  IT_VBAP
    .

ULINE.

CALL METHOD OBJ->DISPLAY_VBAP
  EXPORTING
    IM_ITAB = IT_VBAP
    .

  • Save -> Check -> Activate.
  • Execute ( F8 ).


Input

  • Enter the Input.

Output

  • Click on Execute.


No comments:

Post a Comment