05_ABAP Basics - Object Oriented Programming
05_ABAP Basics - Object Oriented Programming
1
Object Oriented
Programming
Class
Visibility Sections
Components of a
Class
Consuming Class
Define Own Class
Decide Accessibility
Reuse existing Class
Redefine
Functionality
Consume Class
before
Implementing
2
ect Oriented Programming: Data Model
Object Oriented Programming allows to segregate the data in the application based on its usage and group the
functionality applying on segregated data
1
er
CUST1 100
r
US 01.01.2019 SalesOrder#1 Sales Orders#2
D Sales
2 CUST1 200 US 01.08.2019 Sales Header
D 10 CUST 100 US 01.01.2019
Header
10 CUST 100 US 01.01.2019
2
1 D
1
1 D Total Gross Blocked
Order Item Product Quantity Uo Delivery Date Total Gross Blocked
M 10000 USD X
1 10 PRD1 100 EA 01.01.2019 10000 USD
20
Delive
1 PRD2 200 EA 01.08.2019
Deliver X r
1 30 PRD1 100 EA 01.01.2019 Sales Items
1 40 PRD2 200 EA 01.08.2019 Sales Items
10 PR51 100 EA 01.01.2019
2 10 PRD1 100 EA 01.01.2019 20 PRD9 200 EA 01.08.2019
10 PRD1 100 EA 01.01.2019
2 20 PRD2 200 EA 01.08.2019
20 PRD2 200 EA 01.08.2019
3
ct Oriented Programming: Functionalities
When Performing the action, it applies to only specific
SalesOrder#1
instance Create Sales
Program Flow Header
10 CUST 100 US 01.01.2019
1
1 D
01.20.2019
30 PRD3 100 EA
… 40 PRD4 400 EA 01.31.2019
…
… Deliver
Obj1->Release
…. Sales Orders#2
…. Sales
Block Header
Obj1->Deliver 10
2
CUST
1
100 US
D
01.01.2019
…. Delive
Release r
Obj2->Get Sales Items
…. 01.01.2019
10 PR51 100 EA
20 PRD9 200 EA 01.08.2019
Get Items
4
Define Class by Observing all the Data and Actions on the Data
Sales Order Data to Sales Order Order No: 121 Order No: 122 Order No: 123 Order No: NNN
Customer: CUST1 Customer: CUST2 Customer: CUST1 Customer: CUSTN
Sales Org: 1000 Sales Org: 1000 Sales Org: 5000 Sales Org: 1000
Currency: USD Currency: USD Currency: USD Currency: USD
Amount: 1000 Amount: 5000 Amount: 5000 Amount: NNNN
Blocked: No Blocked: Yes Blocked: No Blocked: No
Delivered: Yes Delivered: No Delivered: No Delivered: No
Billed: Yes Billed: No Billed: No Billed: Yes
Item|Prod|Qun|UoM Item|Prod|Qun|UoM Item|Prod|Qun|UoM Item|Prod|Qun|UoM
10 |PRD1 |10 |EA 10 |PRD3 |10 |EA 10 |PRD1 |100 |EA 10 |PRDN |90 |EA
20 |PRD2 |20 |EA 20 |PRD4 |20 |EA
Class
Goods Cost
Goods Issue Vendor G/L Accounts Invoice List Capacity
Receipt Elements
Inspection
Shipment Invoice JIT Call Equipment JIT Call Forecasting
Lot
6
Class
7
omponents in the Class
Types
Types can be declared inside the class and can be accessible
with in the class or outside of the Class
Components of Class
Types | Attributes | Methods | Events Attributes
Attribute can be elementary variable, Work area, internal or Ref
Class
to Other Class. Attributes generally defined in the Private
Components of a Class
Section to disable direct access from outside of the class
Attribute
Types Methods Events
s Methods
Methods are actual functionality. Methods work on attributes.
Generally methods can be defined in Public Section then called
from Class Consumers. Method defined in DEFINTION section of
the Class and Implemented in the IMPLEMENTATION Section.
During the definition all the Interface parameters can be
specified
Events
Events generally passing the current status of the class to the 8
ass and Its Consumers
Class
Data and Logic
Componen
Accessibili
Instances Static
Class
ty
Component
ts
Instance#1 Instance#1 Instance#1
s
Consum
Module
9
isibility Sections
Note: Within the class there is no restriction. All components in the class can freely access other components
irrespective of Visibility Section
Visibility Sections
PUBLIC PUBLIC | PROTECTED | PRIVATE
Public components can be accessed from outside of the class Class
Methods generally declared in the Public Section.
Visibility
If any data needs to accessed without need to call method then Sections
11
ccessing Components
Syntax:
Static Components:
Attributes: CLASS_NAME=>ATTRIBUTE_NAME
Methods: CLASS=>METHOD( <Interface Parameters> )
Instance Components:
Attributes: Object_ref->Attribute_Name
Methods: Object_Reference->Method( < Interface Paramters> )
Note: For accessing Instance Components, Prerequisite is Object Reference declared and Class is instantiated
12
ic Attributes and Static Methods
Consumer: Class
Program | Function
Module | Other Class | Public Private and
Subroutine Components Protected
Components
Access Class Level
Static Static
Components( Attribu
Attributes Attributes
tes or Methods ) of
Class with Class
Name
Static Static
Methods Methods
Note: Public Static attributes can be accessed directly. Private Static attributes can be accessed via Public Static
methods of the Class. Private Static methods can’t be accessed from Outside. Private static attributed generally
used for modularization purpose
13
ing Static Attributes and Methods: Syntax and An Example
14
ance Attributes and Instance Methods
Actions
Instance#1
Create Sales
Program Flow Header
10
1
PRD1 100 EA 01.01.2019
…
30 PRD3 100 EA 01.20.2019
…. Delive
…. r
Release Sales Items
Obj2->Get
…. 100 EA 01.01.2019
10 PR51
20 PRD9 200 EA 01.08.2019
15
sing Instance Attributes and Methods: An Example
TBD
16
Define Class
Class can be defined in the Class builder SE24 as well as Locally. Global class can be accessed globally where are
local classes can be accessed within the program where class is defined.
17
ate Class and Attributes: An Example
Static and Instance
18
sume Class and Attributes: An Example
Static and Instance
19
hod Definition and Implementation
Syntax: Static Method
CLASS <Class Name>… DEFINITION…..
Method can be defined in the Definition section of the
…
Class. During the Method definition, all the interface CLASS-METHODS <Method Name> [ IMPORTING
parameters( Importing | Exporting | Changing ) with full <Parameters> |
type specification.
EXPORTING <Parameters> |
If VALUE addition is specified for Parameter then it is Pass
By Value. Else it is Pass by Reference
CHANGING <Parameters> |
Returning parameters always Pass By Value only
RETURNING <Parameters>]
Method can be implemented in the section of the Class. Syntax: Instance Method Definition
During the method Implementation no additions can be METHODS <Method Name> [ IMPORTING <Parameters> |
specified.
EXPORTING <Parameters> |
Syntax: Static Method | Instance Method
Note: CLASS <Class Name> IMPLEMENTATION.
Static Methods can access only Static Attributes CHANGING <Parameters> |
METHOD <Method Name>.
Instance Methods can access both Static and Instance “ Application Logic
RETURNING <Parameters>]
ENDMETHOD. …
Attributes ….
ENDCLASS
ENDCLASS.
20
te Public Method and Implement: An Example
Implement and Consume TBD
21
ate Private Method and Implement
Static and Instance:
22
heritance: Reusability
Inheritance allows to derive new classes from existing
classes. With the help of inheritance, we can add Super Class
extra functionality in the subclass. Private
Public Protected
Addition INHERITING FROM of the Component Component Component
s s s
statement CLASS ... DEFINITION can be used.
The new class adopts or inherits all components of
the existing class from PUBLIC and PROTECTED.
The new class is called a subclass and the existing
class is called a superclass.
Compone
nts From
Super
Class
Public Private
Component Component
s s
Sub Class
Compone
Declared
Public Protected Private
in the
nts
Component Component Component
s s s
Sub Class
23
heritance: Reusability
Compone
Components of the Class
nts From
Super
Class
Sub Class Consumer Public Private
Component Component
Static Components: With help of Class name s s
Consumer can access all the Public Components of the
Super Class as well as Sub Class
Sub Class
Compone
Declared
Public Protected Private
in the
nts
Instance Components: With help of Object Component Component Component
reference Consumer can access all the Public s s s
Components of the Super Class as well as Sub Class
Sub Class
24
omponents in the Class
Syntax:
CLASS <Class Name> DEFINITION INHERITING FROM <Super Class Name>
Components of Class
ABSTRACT FINAL
Types | Attributes | Methods | Events
CREATE [ PUBLIC | PROTECTED |
PRIVATE ] Class
GLOBAL FRIENDS [class1 class2 ….] Components of a Class
[interface1 interface2…].
Attribute
PUBLIC SECTION. Types Methods Events
s
[Components]
PROTECTED SECTION.
[Components]
PRIVATE SECTION.
[Components]
ENDCLASS.
25