<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by emrah.keles on Medium]]></title>
        <description><![CDATA[Stories by emrah.keles on Medium]]></description>
        <link>https://medium.com/@emrah.keles?source=rss-3573e9a11e02------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DVNBoNxhGSa7Xeo0muM-Pw.jpeg</url>
            <title>Stories by emrah.keles on Medium</title>
            <link>https://medium.com/@emrah.keles?source=rss-3573e9a11e02------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 11:00:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emrah.keles/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ABAP OOP Explained: Encapsulation, Inheritance, Abstraction, Polymorphism with Simple Code Examples]]></title>
            <link>https://medium.com/@emrah.keles/abap-oop-explained-encapsulation-inheritance-abstraction-polymorphism-with-simple-code-examples-93e3a3b8537a?source=rss-3573e9a11e02------2</link>
            <guid isPermaLink="false">https://medium.com/p/93e3a3b8537a</guid>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[sap-abap]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[emrah.keles]]></dc:creator>
            <pubDate>Sun, 30 Nov 2025 13:03:20 GMT</pubDate>
            <atom:updated>2025-12-01T14:34:46.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tp7V25zFucUvaL61fBVUkg.png" /><figcaption>ABAP OOP Explained: Encapsulation, Inheritance, Abstraction, Polymorphism with Simple Code Examples</figcaption></figure><p>When the ABAP programming language was first created in 1983, it was introduced as a purely procedural language. Thirty-six years later, in 1999, it began supporting Object-Oriented concepts. Since then, these concepts have been used billions of times and continue to meet the daily operational needs of countless enterprises.</p><p>In this article, I will explain the four fundamental object-oriented programming concepts — <strong>Encapsulation, Inheritance, Abstraction, </strong>and<strong> Polymorphism</strong> — from the perspective of the ABAP programming language in the simplest way possible, using clear examples.</p><h3>🔐 Encapsulation in ABAP</h3><p>Encapsulation means <strong>hiding data</strong> inside a class and <strong>controlling access</strong> to it through methods.</p><p>In ABAP, we do this using:</p><ul><li><strong>PRIVATE SECTION</strong> → variables/methods that cannot be accessed from outside the class</li><li><strong>PUBLIC SECTION</strong> → methods that provide controlled access</li></ul><p>It protects data from being changed accidentally</p><p>It forces the programmer to use methods instead of touching variables directly</p><p>It keeps the code clean and secure</p><p><strong>🧩 Simple Encapsulation Example in ABAP</strong></p><p>We create a class that stores a <strong>bank account balance</strong>.<br> The balance is <strong>private</strong> so nobody can change it freely.</p><p>Only the class’s <strong>public methods</strong> can update or display the balance.</p><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Object Oriented Samples in ABAP<br>*&amp;---------------------------------------------------------------------*<br>REPORT zoo_abap.<br><br>TYPES: ty_amount TYPE p LENGTH 8 DECIMALS 2.<br><br>CLASS lcl_account DEFINITION.<br>  PUBLIC SECTION.<br>    METHODS deposit<br>      IMPORTING<br>        iv_amount TYPE ty_amount.<br>    METHODS get_balance<br>      RETURNING<br>        VALUE(rv_balance) TYPE ty_amount.<br>  PRIVATE SECTION.<br>    DATA balance TYPE ty_amount.  &quot;Hidden state<br>ENDCLASS.<br><br>CLASS lcl_account IMPLEMENTATION.<br>  METHOD deposit.<br>    balance = balance + iv_amount.<br>  ENDMETHOD.<br><br>  METHOD get_balance.<br>    rv_balance = balance.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>START-OF-SELECTION.<br>  DATA: lo_acc TYPE REF TO lcl_account,<br>        lv_bal TYPE ty_amount.<br><br>  CREATE OBJECT lo_acc.<br><br>  lo_acc-&gt;deposit( iv_amount = 100 ).<br>  lo_acc-&gt;deposit( iv_amount = 50 ).<br><br>  lv_bal = lo_acc-&gt;get_balance( ).<br><br>  WRITE: / &#39;Balance:&#39;, lv_bal.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*x6ZZ2SBgiWxHez8rAbxqgw.jpeg" /><figcaption>Output of the code</figcaption></figure><p><strong>1.</strong> balanceis in the <strong>PRIVATE SECTION</strong> → nobody can touch it directly.</p><p><strong>2.</strong> If someone wants to add money, they must use the <strong>deposit</strong> method.</p><p><strong>3.</strong> If someone wants to read the balance, they must use the <strong>get_balance</strong> method.</p><p><strong>4.</strong> This protects the data from accidental or harmful changes.</p><p>This is exactly what <em>encapsulation</em> means.</p><h3><strong>🧬 Inheritance in ABAP</strong></h3><p><strong>Inheritance</strong> allows one class (the <em>subclass</em>) to reuse, extend, or modify the behavior of another class (the <em>superclass</em>).</p><p>In ABAP, this means:</p><p>· You define common logic once in a <strong>superclass</strong>.</p><p>· You create <strong>subclasses</strong> that automatically inherit its attributes and methods.</p><p>· Subclasses can:</p><p>o Add new methods</p><p>o Override inherited methods</p><p>o Use everything defined in the superclass</p><p>This helps avoid duplicate code, keeps programs clean, and makes maintenance much easier.</p><p><strong>🧩 Simple Inheritance Example in ABAP</strong></p><p>Below is a tiny and very simple example:<br> We have a <strong>superclass</strong> called lcl_animal and a <strong>subclass</strong> called lcl_dog that inherits from it.</p><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Object Oriented Samples in ABAP<br>*&amp;---------------------------------------------------------------------*<br>REPORT zoo_abap.<br><br>CLASS lcl_animal DEFINITION.<br>  PUBLIC SECTION.<br>    METHODS: make_sound.<br>ENDCLASS.<br><br>CLASS lcl_animal IMPLEMENTATION.<br>  METHOD make_sound.<br>    WRITE: / &#39;The animal makes a sound.&#39;.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>CLASS lcl_dog DEFINITION INHERITING FROM lcl_animal.<br>  PUBLIC SECTION.<br>    METHODS: make_sound REDEFINITION.<br>ENDCLASS.<br><br>CLASS lcl_dog IMPLEMENTATION.<br>  METHOD make_sound.<br>    WRITE: / &#39;The dog barks: Woof Woof!&#39;.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>START-OF-SELECTION.<br><br>  DATA: lo_animal TYPE REF TO lcl_animal,<br>        lo_dog    TYPE REF TO lcl_dog.<br><br>  CREATE OBJECT lo_animal.<br>  CREATE OBJECT lo_dog.<br><br>  lo_animal-&gt;make_sound( ).   &quot;calls parent implementation<br>  lo_dog-&gt;make_sound( ).      &quot;calls child&#39;s overridden method</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*ysFKd12NdS4VBOEyFWTXig.jpeg" /><figcaption>Output of the code</figcaption></figure><p><strong>1. We create a parent class called </strong><strong>lcl_animal.</strong></p><p>This class has one method: make_sound → prints a generic message: <em>“The animal makes a sound.”</em></p><p>So the parent class represents <strong>any animal</strong>.</p><p><strong>2. We create a child class called </strong><strong>lcl_dog that inherits from </strong><strong>lcl_animal.</strong></p><pre>INHERITING FROM lcl_animal</pre><p>This means:lcl_dog automatically gets everything from lcl_animal. Inside the child class, we <strong>override</strong> the method make_sound using:</p><pre>REDEFINITION</pre><p>And we change the behavior to print: <em>“The dog barks: Woof Woof!”</em></p><p><strong>3. We create objects from both classes</strong></p><pre>CREATE OBJECT lo_animal.<br>CREATE OBJECT lo_dog.</pre><ul><li>lo_animal → behaves like a general animal</li><li>lo_dog → behaves like a dog</li></ul><p><strong>4. We call the methods</strong></p><pre>lo_animal-&gt;make_sound( ).<br>lo_dog-&gt;make_sound( ).</pre><p>Result:</p><ul><li>The parent class method prints a generic sound</li><li>The child class method prints the dog’s bark</li></ul><p>The dog class <em>inherits</em> the behavior of the animal class but can <strong>change it</strong> — this is inheritance in the simplest possible form.</p><h3>🎭 Abstraction in ABAP</h3><p>Abstraction means <strong>focusing only on what something does</strong>, not <em>how</em> it does it. In ABAP, we achieve abstraction using:</p><ul><li><strong>ABSTRACT classes</strong></li><li><strong>ABSTRACT methods</strong></li></ul><p>An abstract class:</p><ul><li>Cannot be instantiated directly</li><li>Acts like a blueprint</li><li>Defines <em>what</em> methods must exist, but not their internal logic</li></ul><p>A subclass must implement the abstract methods and provide the actual logic.</p><p>Abstraction helps keep your design clean and forces a consistent structure.</p><p><strong>🧩 Simple Abstraction Example in ABAP</strong></p><p>We will create an abstract class called lcl_shape. It defines a method for calculating area, but does <strong>not</strong> provide the calculation.</p><p>Then we create two subclasses: lcl_circle and lcl_square. Each subclass calculates the area in its own way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*NNeCYFYiAa9VPgwnCIMn-Q.gif" /></figure><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Object Oriented Samples in ABAP<br>*&amp;---------------------------------------------------------------------*<br>REPORT zoo_abap.<br><br>TYPES: ty_result TYPE p LENGTH 8 DECIMALS 2.<br><br>CLASS lcl_shape DEFINITION ABSTRACT.<br>  PUBLIC SECTION.<br>    &quot;Abstract method: subclasses must implement<br>    METHODS get_area ABSTRACT<br>      RETURNING VALUE(rv_area) TYPE ty_result.<br>ENDCLASS.<br><br>CLASS lcl_shape IMPLEMENTATION.<br>  &quot;No implementation needed for ABSTRACT methods<br>ENDCLASS.<br><br>CLASS lcl_circle DEFINITION INHERITING FROM lcl_shape.<br>  PUBLIC SECTION.<br>    METHODS constructor<br>      IMPORTING<br>        radius TYPE ty_result.<br>    METHODS get_area REDEFINITION.<br>  PRIVATE SECTION.<br>    DATA mv_radius TYPE ty_result.<br>    CONSTANTS gc_pi TYPE ty_result VALUE &#39;3.14&#39;.<br>ENDCLASS.<br><br>CLASS lcl_circle IMPLEMENTATION.<br>  METHOD constructor.<br>    &quot;Always call super constructor in subclass constructors<br>    super-&gt;constructor( ).<br>    mv_radius = radius.<br>  ENDMETHOD.<br><br>  METHOD get_area.<br>    rv_area = mv_radius * mv_radius * gc_pi.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>CLASS lcl_square DEFINITION INHERITING FROM lcl_shape.<br>  PUBLIC SECTION.<br>    METHODS constructor<br>      IMPORTING<br>        side TYPE ty_result.<br>    METHODS get_area REDEFINITION.<br>  PRIVATE SECTION.<br>    DATA mv_side TYPE ty_result.<br>ENDCLASS.<br><br>CLASS lcl_square IMPLEMENTATION.<br>  METHOD constructor.<br>    &quot;Always call super constructor in subclass constructors<br>    super-&gt;constructor( ).<br>    mv_side = side.<br>  ENDMETHOD.<br><br>  METHOD get_area.<br>    rv_area = mv_side * mv_side.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>START-OF-SELECTION.<br>  DATA: lo_circle TYPE REF TO lcl_circle,<br>        lo_square TYPE REF TO lcl_square.<br><br>  CREATE OBJECT lo_circle EXPORTING radius = 5.<br>  CREATE OBJECT lo_square EXPORTING side = 4.<br><br>  WRITE: / &#39;Circle area:&#39;, lo_circle-&gt;get_area( ).<br>  WRITE: / &#39;Square area:&#39;, lo_square-&gt;get_area( ).</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*DHNT0SvIBPUrKp7El_Y3qA.jpeg" /><figcaption>Output of the code</figcaption></figure><p>1. lcl_shape is an <em>abstract</em> class → you cannot create objects from it.</p><p>2. It tells all shapes: <strong>“You must have a method called </strong><strong>get_area.”</strong></p><p>But it does not explain <em>how</em> to calculate the area.</p><p>3. Each shape (circle, square) provides its own formula.</p><h3>🔄 Polymorphism in ABAP</h3><p>Polymorphism means: <strong><em>Different objects can respond to the same method call in different ways. </em></strong>In ABAP, polymorphism is achieved when:</p><ul><li>A superclass defines a method</li><li>Subclasses redefine (override) that method</li><li>You call that method using a <strong>reference of the superclass</strong></li></ul><p>This allows ABAP to decide <strong>at runtime</strong> which method implementation to execute.</p><p>Polymorphism is powerful because:</p><ul><li>It reduces IF/ELSE clutter</li><li>It allows you to write generic code</li><li>It makes programs flexible and easy to extend</li></ul><p><strong>🧩 Simple Polymorphism Example in ABAP</strong></p><p>We will reuse the same <strong>Shape</strong> example because polymorphism is easiest to understand here.</p><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Object Oriented Samples in ABAP<br>*&amp;---------------------------------------------------------------------*<br>REPORT zoo_abap.<br><br>TYPES: ty_result TYPE p LENGTH 8 DECIMALS 2.<br><br>CLASS lcl_shape DEFINITION ABSTRACT.<br>  PUBLIC SECTION.<br>    METHODS get_area ABSTRACT RETURNING VALUE(rv_area) TYPE ty_result.<br>ENDCLASS.<br><br>CLASS lcl_shape IMPLEMENTATION.<br>  &quot;No implementation needed<br>ENDCLASS.<br><br>CLASS lcl_circle DEFINITION INHERITING FROM lcl_shape.<br>  PUBLIC SECTION.<br>    METHODS: constructor IMPORTING radius TYPE ty_result,<br>      get_area REDEFINITION.<br>  PRIVATE SECTION.<br>    DATA mv_radius TYPE ty_result.<br>    CONSTANTS gc_pi TYPE ty_result VALUE &#39;3.14&#39;.<br>ENDCLASS.<br><br>CLASS lcl_circle IMPLEMENTATION.<br>  METHOD constructor.<br>    super-&gt;constructor( ).<br>    mv_radius = radius.<br>  ENDMETHOD.<br><br>  METHOD get_area.<br>    rv_area = mv_radius * mv_radius * gc_pi.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>CLASS lcl_square DEFINITION INHERITING FROM lcl_shape.<br>  PUBLIC SECTION.<br>    METHODS: constructor IMPORTING side TYPE ty_result,<br>      get_area REDEFINITION.<br>  PRIVATE SECTION.<br>    DATA mv_side TYPE ty_result.<br>ENDCLASS.<br><br>CLASS lcl_square IMPLEMENTATION.<br>  METHOD constructor.<br>    super-&gt;constructor( ).<br>    mv_side = side.<br>  ENDMETHOD.<br><br>  METHOD get_area.<br>    rv_area = mv_side * mv_side.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>START-OF-SELECTION.<br>  DATA: lo_shape  TYPE REF TO lcl_shape,<br>        lt_shapes TYPE TABLE OF REF TO lcl_shape,<br>        lv_area   TYPE ty_result.<br><br>  APPEND NEW lcl_circle( radius = 5 ) TO lt_shapes.<br>  APPEND NEW lcl_square( side   = 4 ) TO lt_shapes.<br><br>  WRITE:  &#39;Polymorphism example&#39;.<br>  LOOP AT lt_shapes INTO lo_shape.<br>    lv_area = lo_shape-&gt;get_area( ).   &quot;same method call, different behavior<br>    WRITE: / &#39;Area:&#39;, lv_area.<br>  ENDLOOP.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*JSwciB19fhqLlLZ9NbPapA.jpeg" /><figcaption>Output of the code</figcaption></figure><ol><li><strong>You define an abstract “shape” class.</strong> This class says: <strong>“Every shape must have a get_area method.” </strong>But it does <em>not</em> calculate anything itself. It is only a <strong>blueprint</strong>.</li><li><strong>You create a Circle class. </strong>This class: Stores a radius (mv_radius). Has a constructor that sets the radius and calculates the circle’s area. So when you call get_area on a circle → it returns the circle’s area.</li><li><strong>You create a Square class.</strong> This class: Stores the side length (mv_side). Constructor sets the side value and calculates the area of the square. So when you call get_area on a square → it returns the square’s area.</li><li><strong>In START-OF-SELECTION you create two shapes.</strong> The first object is a circle with radius 5. The second object is a square with side length 4. Both are stored in a table of shape references. <strong>This is the key to polymorphism.</strong></li><li>You loop through the shapes and call get_area. Even though the variable type is lcl_shape, ABAP automatically decides:</li></ol><p>If the object is a circle → use circle’s formula</p><p>If the object is a square → use square’s formula</p><p><strong>Same method call → different behavior! </strong>Your program shows how different objects (circle &amp; square) can respond differently to the same method call, thanks to inheritance + abstraction + polymorphism.</p><h3>🏁 Conclusion: Why OOP Matters</h3><p>With encapsulation, inheritance, abstraction, and polymorphism, ABAP gained the ability to structure programs around clean, modular building blocks that mirror how we think about real-world problems.</p><p>Together, these four principles form the foundation of modern object-oriented development in ABAP. They make code more readable, more maintainable, and far easier to extend as business needs grow and change.</p><p>In a world where SAP systems continue to power the daily operations of global enterprises, understanding OOP in ABAP is essential. And the better we understand these fundamentals, the more effectively we can build the next generation of SAP solutions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93e3a3b8537a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>