Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

What is Inheritance ? Using Inheritance in SAP ABAP

Inheritance allows one class to reuse the code from another class. In SAP ABAP, this helps in building modular, reusable, and maintainable programs.

Use of Inheritance in SAP

Purpose Explanation
Code Reusability You don’t need to rewrite common logic; it can be inherited from a base class.
Standardization Common functionality can be centralized in a superclass and reused.
Simplifies Maintenance Changes in the parent class reflect automatically in all child classes.
Extensibility Child classes can add or override methods to provide specific functionality.
Polymorphism Support You can treat objects of different subclasses uniformly using references.

Types of Inheritance in SAP ABAP

  1. Single Inheritance – A subclass inherits from only one parent class.
  2. No Multiple Inheritance – SAP ABAP does not support multiple inheritance, but it allows interfaces for similar functionality.
*&---------------------------------------------------------------------*
*& Report  ZREP_LCLCLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zrep_lclclass.

CLASS parent_class DEFINITION.
  PUBLIC SECTION.
    METHODSdisplay.
ENDCLASS.

CLASS parent_class IMPLEMENTATION.
  METHOD display.
    WRITE'This is parent class'.
  ENDMETHOD.
ENDCLASS.

CLASS child_class DEFINITION INHERITING FROM parent_class.
  PUBLIC SECTION.
    METHODSshow.
ENDCLASS.

CLASS child_class IMPLEMENTATION.
  METHOD show.
    WRITE'This is child class'.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA obj TYPE REF TO child_class.
  CREATE OBJECT obj.
  obj->display).   "Inherited method
  skip 2.
  obj->show).      "Own method 

Output:

Related Questions

Leave an answer

Leave an answer