SAP ABAP - OOPS Concept - Classes and Objects
SAP ABAP - OOPS Concept - Classes and Objects
Class
Using a blueprint we can make multiple houses using our own name,
color,floor etc .
Example : An animal
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
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.
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
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
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
Instance constructor
Static Constructor
Examples :
Example 1
Example 2
Example 3
Example 4
Example 6
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
READ MORE
Powered by Blogger
BLOGGER
VISIT PROFILE
Archive
Report Abuse
https://mysapnutsoopsabap.blogspot.com/2021/07/sap-abap-oops-concept-class-and-object.html 6/6