0% found this document useful (0 votes)
6 views

ooabap

Uploaded by

jahirr893
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

ooabap

Uploaded by

jahirr893
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1) normal cls

2) inheritance from cls


3) abstract cls and inherite in normal cls
4) interface
5) Multiple inheritance using interfaces

Let's go through each concept in Object-Oriented ABAP (OOABAP) with examples.

1. Normal Class
A normal class in ABAP is simply a class that contains methods and attributes
without any special characteristics like inheritance or interfaces.

Example:
abap
CLASS lcl_normal DEFINITION.
PUBLIC SECTION.
DATA: gv_text TYPE string.
METHODS: set_text IMPORTING iv_text TYPE string,
get_text RETURNING VALUE(rv_text) TYPE string.
ENDCLASS.

CLASS lcl_normal IMPLEMENTATION.


METHOD set_text.
gv_text = iv_text.
ENDMETHOD.

METHOD get_text.
rv_text = gv_text.
ENDMETHOD.
ENDCLASS.
2. Inheritance from Class
Inheritance allows a class (subclass) to inherit attributes and methods from
another class (superclass).

Example:
abap
CLASS lcl_super DEFINITION.
PUBLIC SECTION.
METHODS: display.
ENDCLASS.

CLASS lcl_super IMPLEMENTATION.


METHOD display.
WRITE: / 'Superclass Display Method'.
ENDMETHOD.
ENDCLASS.

CLASS lcl_sub DEFINITION INHERITING FROM lcl_super.


PUBLIC SECTION.
METHODS: display.
ENDCLASS.

CLASS lcl_sub IMPLEMENTATION.


METHOD display.
WRITE: / 'Subclass Display Method'.
CALL METHOD super->display.
ENDMETHOD.
ENDCLASS.
3. Abstract Class and Inherit in Normal Class
An abstract class contains at least one abstract method and cannot be instantiated.
A normal class can inherit from an abstract class.

Example:
abap
CLASS lcl_abstract DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: abstract_method ABSTRACT.
ENDCLASS.

CLASS lcl_concrete DEFINITION INHERITING FROM lcl_abstract.


PUBLIC SECTION.
METHODS: abstract_method.
ENDCLASS.

CLASS lcl_concrete IMPLEMENTATION.


METHOD abstract_method.
WRITE: / 'Implemented Abstract Method'.
ENDMETHOD.
ENDCLASS.
4. Interface
An interface is a contract that a class can implement, ensuring that certain
methods are present in the class.

Example:
abap
INTERFACE lif_example.
METHODS: method1,
method2 IMPORTING iv_param TYPE string.
ENDINTERFACE.

CLASS lcl_example DEFINITION.


PUBLIC SECTION.
INTERFACES: lif_example.
ENDCLASS.

CLASS lcl_example IMPLEMENTATION.


METHOD lif_example~method1.
WRITE: / 'Method1 Implementation'.
ENDMETHOD.

METHOD lif_example~method2.
WRITE: / iv_param.
ENDMETHOD.
ENDCLASS.
5. Multiple Inheritance Using Interfaces
ABAP does not support multiple inheritance directly, but you can achieve similar
behavior using interfaces.

Example:
abap
INTERFACE lif_interface1.
METHODS: method1.
ENDINTERFACE.

INTERFACE lif_interface2.
METHODS: method2.
ENDINTERFACE.

CLASS lcl_multi DEFINITION.


PUBLIC SECTION.
INTERFACES: lif_interface1, lif_interface2.
ENDCLASS.

CLASS lcl_multi IMPLEMENTATION.


METHOD lif_interface1~method1.
WRITE: / 'Method1 from Interface1'.
ENDMETHOD.

METHOD lif_interface2~method2.
WRITE: / 'Method2 from Interface2'.
ENDMETHOD.
ENDCLASS.

You might also like