SlideShare a Scribd company logo
Object Oriented Concepts
CLASS: Class is a blue print / Template of the object.
Object is a real-world entity and is created based on the class.
A class mainly contains two sections.
1. Class Definition
2. Class Implementation
Class Definition: Class definition contains all declarations of components and visibility sections.
Components of Class:
1. Attributes
2. Methods
3. Events
4. Interfaces
Components of Class:
Attributes:
Under attributes variables/data objects, work areas, Internal tables will come. These attributes are
declared with proper visibility.
Methods:
It contains the actual functionality to be executed.
Events:
Events are used to handle the methods of other classes.
Interfaces:
It is collection of method declarations only. Initially no implementations maintained.
Visibility Sections:
We have totally three visibility sections.
1. Public section
2. Protected Section
3. Private section
Public Section: We can access all the attributes with in the class and outside the class also.
Protected Section: We can access the attributes within the class and in derived classes also.
Private Section: We can access only within the class. Not outside the class.
Note:
1. From the class definition any number of objects can be created.
2. Name of the objects must be different from one another.
Syntax of a class
Class definition:
Class <class_name> definition.
Public/protected/Private section. ---- Visibility Section
Statement1…
Statement 2... Declare the components of the class.
Endclass.
NOTE: We must give a visibility section.
Class Implementation:
All the methods are implemented in the class.
Class <class_name> Implementation.
Logic for methods….
Endclass.
Note:
1. Without object we cannot access the method of a class (In case of Instance methods)
2. We can access the methods with class name (In case of static methods)
Reference variable and object creation:
Syntax for Reference variable of a class:
DATA: < Reference variable> TYPE REF TO <Class name>.
Syntax for creating the object of a class:
Create object <Reference variable>.
Syntax for method declaration:
1. Without parameters:
Methods <Method name>.
2. With parameters:
Methods <Method name> Importing <p1> type …
<p2> type...
…….
exporting <p3> type …
<p4> type...
……
changing <p5> type …
<p6> type...
NOTE:
1. Importing, exporting, and changing are the parameters list. The parameters can be used
in the method implementation.
2. Parameters list is not mandatory.
Syntax for method Implementation:
Without parameters / With parameters:
Method <method name>.
Statements….
Endmethod.
Note:
1. If parameters list is declared at method declaration all of them can be used at method
implementation time. (With in the same class implementation)
2. No need to call the parameter list at implementation time
Method calling:
Without parameter list:
Call method <Object name><method name>
With parameter List:
Call method <Object name><method name> exporting …
Importing ….
Changing …
Note:
1. At the time of calling parameters list of method must be called.
2. Creation of object and reference variable must be after START-OF-SELECTION event.
EXAMPLE:
Addition of two numbers using OOPS
CLASS cl DEFINITION .
PUBLIC SECTION.
DATA : a TYPE i,
b TYPE i,
res TYPE i .
METHODS: add_data IMPORTING v1 TYPE i
v2 TYPE i,
display_data .
ENDCLASS .
CLASS cl IMPLEMENTATION .
METHOD add_data.
a = v1 .
b = v2 .
res = a + b .
ENDMETHOD.
METHOD display_data .
write: 'result is', res .
ENDMethod .
ENDCLASS .
*==Screen declaration
PARAMETERS : p1 TYPE i,
p2 TYPE i .
START-OF-SELECTION .
*=Object Creation(Instance)
DATA o_ref TYPE REF TO cl.
CREATE OBJECT o_ref .
*=Calling Method
call METHOD o_ref->add_data
exporting v1 = p1
v2 = p2 .
call METHOD o_ref->display_data .
Output :
Enter the value and execute.
Class can have mainly two components:
1. Static Components.
2. Instance Components.
static components are declared with “class-data.”
EXAMPLE:
CLASS cl DEFINITION.
PUBLIC SECTION.
DATA a type char20 value 'Instance_variable'.
CLASS-DATA b TYPE char20 value 'static_variable'.
ENDCLASS.
START-OF-SELECTION .
DATA : o_ref TYPE REF TO cl .
create OBJECT o_ref .
WRITE :/ 'Displaying....', o_ref->a .
WRITE : /'Displaying.....', cl=>b .
Output:
After executing we get the following screen.
INHERITANCE:
Derving a new class based on the existing class is called INHERITANCE.
Existing class is called Base class/parent class/super class.
Derving class is called derived class/child class/sub class.
Note:
1. Sub class can access all the components of super class which are under protected and public
sections.
2. Sub class cannot access the private components of super class.
Syntax of defining the sub class:
Class <subclass> definition inheriting from <superclass>.
Public/protected/private section.
…………………
Endclass.
Example:
REPORT Z9AM_INHERITANCE.
PARAMETERS : p_bukrs TYPE bukrs .
CLASS cl DEFINITION .
PUBLIC SECTION.
TYPES :BEGIN OF ty_ekpo,
matnr TYPE matnr,
MATKL TYPE MATKL,
END OF ty_ekpo.
DATA : wa_ekpo TYPE ty_ekpo,
it_ekpo TYPE TABLE OF ty_ekpo.
METHODS get_data IMPORTING m_bukrs TYPE bukrs .
ENDCLASS .
CLASS cl IMPLEMENTATION .
METHOD get_data.
SELECT matnr matkl FROM ekpo INTO TABLE it_ekpo WHERE bukrs eq p_bukrs .
ENDMETHOD .
ENDCLASS .
CLASS cl_2 DEFINITION INHERITING FROM cl .
PUBLIC SECTION.
* METHODs get_data.
METHODS display_data .
ENDCLASS .
CLASS cl_2 IMPLEMENTATION .
METHOD display_data.
LOOP AT it_ekpo INTO wa_ekpo.
WRITE : / wa_ekpo-matnr,
wa_ekpo-matkl.
ENDLOOP.
ENDMETHOD .
ENDCLASS .
START-OF-SELECTION.
DATA : o_ref1 TYPE REF TO cl,
o_ref2 TYPE REF TO cl_2.
CREATE OBJECT: o_ref1, o_ref2.
call METHOD o_ref2->get_data
EXPORTING
m_bukrs = p_bukrs .
CALL METHOD o_ref2->display_data( ).
OUTPUT: Execute and we can see the following screen
Execute, then we get the following output .
INTERFACE:
A method is declared only once and no implementation is maintained.
NOTE:
1. It is just declared once separately and not implemented.
2. In different classes different implementations are different implementations are maintained.
But name of the method is same.
EXAMPLE:
Explanation for the below example:
In the following example Interface (df_interface) is declared and inside only one time method
(Dataflairmethod1.) is maintained. But in class1 and class2 the method (Dataflairmethod1)
is differently implemented in the following example.
Report ZDATAFLAIR_ENCAPSULATION.
Interface df_interface.
Data text1 Type char35.
Methods Dataflairmethod1.
EndInterface.
CLASS DataflairClass1 Definition.
PUBLIC Section.
Interfaces df_interface.
ENDCLASS.
CLASS DataflairClass2 Definition.
PUBLIC Section.
Interfaces df_interface.
ENDCLASS.
CLASS DataflairClass1 Implementation.
Method df_interface~Dataflairmethod1.
df_interface~text1 = 'DataflairClass 1 Interface method'.
Write / df_interface~text1.
EndMethod.
ENDCLASS.
CLASS DataflairClass2 Implementation.
Method df_interface~Dataflairmethod1.
df_interface~text1 = 'DataflairClass 2 Interface method'.
Write / df_interface~text1.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data: DataflairObject1 Type Ref To DataflairClass1,
DataflairObject2 Type Ref To DataflairClass2.
Create Object: DataflairObject1, DataflairObject2.
CALL Method: DataflairObject1 df_interface~Dataflairmethod1,
→
DataflairObject2 df_interface~Dataflairmethod1.
→
OUTPUT:
DataflairClass 1 Interface method
DataflairClass 2 Interface method

More Related Content

PPT
Class and object in C++
DOCX
Object oriented basics
PPTX
Application package
PPT
ObjectOrientedSystems intrduction and .ppt
PPT
Data structure and problem solving ch02.ppt
PPTX
VB.net&OOP.pptx
PPT
CHAPTER 1 - OVERVIEW OOP.ppt
PPTX
oopusingc.pptx
Class and object in C++
Object oriented basics
Application package
ObjectOrientedSystems intrduction and .ppt
Data structure and problem solving ch02.ppt
VB.net&OOP.pptx
CHAPTER 1 - OVERVIEW OOP.ppt
oopusingc.pptx

Similar to Object oriented Programming ____ABAP.docx (20)

PPTX
Lecture 2 (1)
PPT
Objectorientedprogrammingmodel1
PPT
ObjectOrientedSystems.ppt
PPTX
3_ObjectOrientedSystems.pptx
PPTX
JAVA-PPT'S-complete-chrome.pptx
PPTX
JAVA-PPT'S.pptx
PPTX
Concept of Object-Oriented in C++
PPT
34. uml
PPT
OOPs Lecture 2
PPT
cpp class unitdfdsfasadfsdASsASass 4.ppt
PPTX
Object Oriented Programming Using C++
PPT
Lecture13 abap on line
PDF
Lab 4 (1).pdf
PPT
c++ lecture 1
PPT
c++ lecture 1
PPT
c++ introduction
PPT
PPT
OO Development 4 - Object Concepts
PPTX
PDF
Implementation of oop concept in c++
Lecture 2 (1)
Objectorientedprogrammingmodel1
ObjectOrientedSystems.ppt
3_ObjectOrientedSystems.pptx
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S.pptx
Concept of Object-Oriented in C++
34. uml
OOPs Lecture 2
cpp class unitdfdsfasadfsdASsASass 4.ppt
Object Oriented Programming Using C++
Lecture13 abap on line
Lab 4 (1).pdf
c++ lecture 1
c++ lecture 1
c++ introduction
OO Development 4 - Object Concepts
Implementation of oop concept in c++
Ad

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PDF
KodekX | Application Modernization Development
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
KodekX | Application Modernization Development
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Ad

Object oriented Programming ____ABAP.docx

  • 1. Object Oriented Concepts CLASS: Class is a blue print / Template of the object. Object is a real-world entity and is created based on the class. A class mainly contains two sections. 1. Class Definition 2. Class Implementation Class Definition: Class definition contains all declarations of components and visibility sections. Components of Class: 1. Attributes 2. Methods 3. Events 4. Interfaces Components of Class: Attributes: Under attributes variables/data objects, work areas, Internal tables will come. These attributes are declared with proper visibility. Methods: It contains the actual functionality to be executed. Events: Events are used to handle the methods of other classes. Interfaces: It is collection of method declarations only. Initially no implementations maintained. Visibility Sections: We have totally three visibility sections. 1. Public section 2. Protected Section 3. Private section Public Section: We can access all the attributes with in the class and outside the class also. Protected Section: We can access the attributes within the class and in derived classes also. Private Section: We can access only within the class. Not outside the class. Note: 1. From the class definition any number of objects can be created. 2. Name of the objects must be different from one another.
  • 2. Syntax of a class Class definition: Class <class_name> definition. Public/protected/Private section. ---- Visibility Section Statement1… Statement 2... Declare the components of the class. Endclass. NOTE: We must give a visibility section. Class Implementation: All the methods are implemented in the class. Class <class_name> Implementation. Logic for methods…. Endclass. Note: 1. Without object we cannot access the method of a class (In case of Instance methods) 2. We can access the methods with class name (In case of static methods) Reference variable and object creation: Syntax for Reference variable of a class: DATA: < Reference variable> TYPE REF TO <Class name>. Syntax for creating the object of a class: Create object <Reference variable>. Syntax for method declaration: 1. Without parameters: Methods <Method name>. 2. With parameters: Methods <Method name> Importing <p1> type … <p2> type... ……. exporting <p3> type … <p4> type... …… changing <p5> type … <p6> type...
  • 3. NOTE: 1. Importing, exporting, and changing are the parameters list. The parameters can be used in the method implementation. 2. Parameters list is not mandatory. Syntax for method Implementation: Without parameters / With parameters: Method <method name>. Statements…. Endmethod. Note: 1. If parameters list is declared at method declaration all of them can be used at method implementation time. (With in the same class implementation) 2. No need to call the parameter list at implementation time Method calling: Without parameter list: Call method <Object name><method name> With parameter List: Call method <Object name><method name> exporting … Importing …. Changing … Note: 1. At the time of calling parameters list of method must be called. 2. Creation of object and reference variable must be after START-OF-SELECTION event. EXAMPLE: Addition of two numbers using OOPS CLASS cl DEFINITION . PUBLIC SECTION. DATA : a TYPE i, b TYPE i, res TYPE i . METHODS: add_data IMPORTING v1 TYPE i v2 TYPE i, display_data . ENDCLASS .
  • 4. CLASS cl IMPLEMENTATION . METHOD add_data. a = v1 . b = v2 . res = a + b . ENDMETHOD. METHOD display_data . write: 'result is', res . ENDMethod . ENDCLASS . *==Screen declaration PARAMETERS : p1 TYPE i, p2 TYPE i . START-OF-SELECTION . *=Object Creation(Instance) DATA o_ref TYPE REF TO cl. CREATE OBJECT o_ref . *=Calling Method call METHOD o_ref->add_data exporting v1 = p1 v2 = p2 . call METHOD o_ref->display_data . Output : Enter the value and execute.
  • 5. Class can have mainly two components: 1. Static Components. 2. Instance Components. static components are declared with “class-data.” EXAMPLE: CLASS cl DEFINITION. PUBLIC SECTION. DATA a type char20 value 'Instance_variable'. CLASS-DATA b TYPE char20 value 'static_variable'. ENDCLASS. START-OF-SELECTION . DATA : o_ref TYPE REF TO cl . create OBJECT o_ref . WRITE :/ 'Displaying....', o_ref->a . WRITE : /'Displaying.....', cl=>b . Output: After executing we get the following screen.
  • 6. INHERITANCE: Derving a new class based on the existing class is called INHERITANCE. Existing class is called Base class/parent class/super class. Derving class is called derived class/child class/sub class. Note: 1. Sub class can access all the components of super class which are under protected and public sections. 2. Sub class cannot access the private components of super class. Syntax of defining the sub class: Class <subclass> definition inheriting from <superclass>. Public/protected/private section. ………………… Endclass. Example:
  • 7. REPORT Z9AM_INHERITANCE. PARAMETERS : p_bukrs TYPE bukrs . CLASS cl DEFINITION . PUBLIC SECTION. TYPES :BEGIN OF ty_ekpo, matnr TYPE matnr, MATKL TYPE MATKL, END OF ty_ekpo. DATA : wa_ekpo TYPE ty_ekpo, it_ekpo TYPE TABLE OF ty_ekpo. METHODS get_data IMPORTING m_bukrs TYPE bukrs . ENDCLASS . CLASS cl IMPLEMENTATION . METHOD get_data. SELECT matnr matkl FROM ekpo INTO TABLE it_ekpo WHERE bukrs eq p_bukrs . ENDMETHOD . ENDCLASS . CLASS cl_2 DEFINITION INHERITING FROM cl . PUBLIC SECTION. * METHODs get_data. METHODS display_data . ENDCLASS . CLASS cl_2 IMPLEMENTATION . METHOD display_data. LOOP AT it_ekpo INTO wa_ekpo. WRITE : / wa_ekpo-matnr, wa_ekpo-matkl. ENDLOOP. ENDMETHOD . ENDCLASS . START-OF-SELECTION. DATA : o_ref1 TYPE REF TO cl, o_ref2 TYPE REF TO cl_2. CREATE OBJECT: o_ref1, o_ref2. call METHOD o_ref2->get_data EXPORTING m_bukrs = p_bukrs . CALL METHOD o_ref2->display_data( ). OUTPUT: Execute and we can see the following screen
  • 8. Execute, then we get the following output . INTERFACE: A method is declared only once and no implementation is maintained. NOTE: 1. It is just declared once separately and not implemented. 2. In different classes different implementations are different implementations are maintained. But name of the method is same. EXAMPLE: Explanation for the below example: In the following example Interface (df_interface) is declared and inside only one time method (Dataflairmethod1.) is maintained. But in class1 and class2 the method (Dataflairmethod1) is differently implemented in the following example. Report ZDATAFLAIR_ENCAPSULATION. Interface df_interface. Data text1 Type char35. Methods Dataflairmethod1. EndInterface. CLASS DataflairClass1 Definition. PUBLIC Section.
  • 9. Interfaces df_interface. ENDCLASS. CLASS DataflairClass2 Definition. PUBLIC Section. Interfaces df_interface. ENDCLASS. CLASS DataflairClass1 Implementation. Method df_interface~Dataflairmethod1. df_interface~text1 = 'DataflairClass 1 Interface method'. Write / df_interface~text1. EndMethod. ENDCLASS. CLASS DataflairClass2 Implementation. Method df_interface~Dataflairmethod1. df_interface~text1 = 'DataflairClass 2 Interface method'. Write / df_interface~text1. EndMethod. ENDCLASS. Start-Of-Selection. Data: DataflairObject1 Type Ref To DataflairClass1, DataflairObject2 Type Ref To DataflairClass2. Create Object: DataflairObject1, DataflairObject2. CALL Method: DataflairObject1 df_interface~Dataflairmethod1, → DataflairObject2 df_interface~Dataflairmethod1. → OUTPUT: DataflairClass 1 Interface method DataflairClass 2 Interface method