100% found this document useful (1 vote)
1K views6 pages

SAP ABAP - OOPS Concept - Classes and Objects

The document discusses classes and objects in SAP ABAP OOPS concepts. A class is a blueprint that defines properties and methods common to all objects of that type. An object is an instance of a class that encapsulates state and behavior. The new operator instantiates objects by allocating memory and invoking the constructor. The code example demonstrates declaring classes and objects, and initializing an object by passing a name to the constructor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views6 pages

SAP ABAP - OOPS Concept - Classes and Objects

The document discusses classes and objects in SAP ABAP OOPS concepts. A class is a blueprint that defines properties and methods common to all objects of that type. An object is an instance of a class that encapsulates state and behavior. The new operator instantiates objects by allocating memory and invoking the constructor. The code example demonstrates declaring classes and objects, and initializing an object by passing a name to the constructor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

4/13/23, 12:32 PM SAP ABAP : OOPS Concept - Classes And Objects

SAP OOPS ABAP

SAP ABAP : OOPS Concept - Classes And Objects


July 22, 2021

 Classes and Objects are basic concepts of Object Oriented Programming


which revolve around the real life entities.

Class

A class is a user defined blueprint or prototype from which objects are


created.  It represents the set of properties or methods that are common to all
objects of one type.

Example :  A blueprint of house .

 Using a blueprint we can make multiple houses using our own name,
color,floor etc .

Example : An animal

An animal is just a blueprint . Animal can be dog , cat , mouse etc .

Class declarations can include these components, in order:  

1. Modifiers: A class can be public or has default access.


2. Class keyword: class keyword is used to create a class.
3. Class name: The name should begin with an lcl for local class and zcl for
Global class.
4. Superclass(if any): The name of the class’s parent (superclass), if any,
preceded by the keyword INHERITING FROM. A class can
only INHERIT (subclass) one parent.
5. Interfaces(if any): A comma-separated list of interfaces implemented by
the class, if any, preceded by the keyword implements. A class can
implement more than one interface.

https://mysapnutsoopsabap.blogspot.com/2021/07/sap-abap-oops-concept-class-and-object.html 1/6
4/13/23, 12:32 PM SAP ABAP : OOPS Concept - Classes And Objects

6. Body: The class body surrounded by Class and Endclass.

Example :

Object
 It is a basic unit of Object-Oriented Programming and represents the real life
entities.  A typical Java program creates many objects, which as you know,
interact by invoking methods.
   An object consists of : 
1. State: It is represented by attributes of an object. It also reflects the
properties of an object.
2. Behavior: It is represented by methods of an object. It also reflects the
response of an object with other objects.
3. Identity: It gives a unique name to an object and enables one object to
interact with other objects.

Example of an object: dog

https://mysapnutsoopsabap.blogspot.com/2021/07/sap-abap-oops-concept-class-and-object.html 2/6
4/13/23, 12:32 PM SAP ABAP : OOPS Concept - Classes And Objects

Code Example :

class lcl_animal DEFINITION. "class declaration
  PUBLIC SECTION. "access modifier
   DATA name TYPE char10."attributes
   METHODS m_eat . "behaviours
ENDCLASS.

DATA lv_obj TYPE REF TO lcl_animal. "declaring object of class

"there is two way to create object of class after release 7.4

CREATE OBJECT lv_obj. "or

https://mysapnutsoopsabap.blogspot.com/2021/07/sap-abap-oops-concept-class-and-object.html 3/6
4/13/23, 12:32 PM SAP ABAP : OOPS Concept - Classes And Objects

DATA(lv_obj1) = NEW lcl_animal( )."incline declaration with New keyword "supported only release
after 7.4 ve

CLASS lcl_animal IMPLEMENTATION.
  METHOD m_eat.
  ENDMETHOD.
ENDCLASS.

Initializing an object

The new operator or create object instantiates a class by allocating memory


for a new object and returning a reference to that memory. The new operator
or create object also invokes the class constructor. 

REPORT ztest_demo_sup.
class lcl_animal DEFINITION. "class declaration
  PUBLIC SECTION. "access modifier
   DATA name TYPE char10."attributes
   METHODS constructor IMPORTING name TYPE char10.
   METHODS m_eat . "behaviours
ENDCLASS.
DATA lv_dog TYPE REF TO lcl_animal. "declaring object of class

"there is two way to create object of class after release 7.4
CREATE OBJECT lv_dog EXPORTING name = 'Milo'. "or

DATA(lv_cat) = NEW lcl_animal( name = 'Kitty')."incline declaration with New keyword "supported only 
release after 7.4 ve

CLASS lcl_animal IMPLEMENTATION.
  METHOD constructor.

    WRITE : / name.

  ENDMETHOD.
  METHOD m_eat.
  ENDMETHOD.
ENDCLASS.

https://mysapnutsoopsabap.blogspot.com/2021/07/sap-abap-oops-concept-class-and-object.html 4/6
4/13/23, 12:32 PM SAP ABAP : OOPS Concept - Classes And Objects

                                             SAP ABAP Supports Two Types of constructor .

Instance constructor 
Static Constructor 

Examples :
   Example 1
   Example 2
   Example 3
   Example 4
   Example 6

  

To leave a comment, click the button below to sign in


with Google.

SIGN IN WITH GOOGLE

Popular posts from this blog

SAP ABAP : OOPS Concept - Method


July 23, 2021

  A method is a collection of statements that perform some specific task and return the
result to the caller. A method can perform some specific task without returning anything.
Methods allow us to  reuse  the code without retyping the code.                                                …

READ MORE

https://mysapnutsoopsabap.blogspot.com/2021/07/sap-abap-oops-concept-class-and-object.html 5/6
4/13/23, 12:32 PM SAP ABAP : OOPS Concept - Classes And Objects

SAP ABAP : OOPS Concept - Inheritance


July 23, 2021

Inheritance is an important pillar of OOP(Object-Oriented Programming).


It is the mechanism in ABAP by which one class is allowed to inherit the
features(fields and methods) of another class.  Important terminology:  …

READ MORE

Powered by Blogger

Theme images by Michael Elkan

BLOGGER

VISIT PROFILE

Archive

Report Abuse

https://mysapnutsoopsabap.blogspot.com/2021/07/sap-abap-oops-concept-class-and-object.html 6/6

You might also like