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
Object 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
3
Object Oriented Programming: Functionalities
When Performing the action, it applies to only specific instance
SalesOrder#1
Create Sales Header
Program Flow 101 CUST1 100 US
D
01.01.2019
01.20.2019
30 PRD3 100 EA
… 40 PRD4 400 EA 01.31.2019
…
… Deliver
Obj1->Release
…. Sales Orders#2
…. Sales Header
Block
Obj1->Deliver 102 CUST1 100 US
D
01.01.2019
…. Deliver
Release
Obj2->Get Sales Items
…. 01.01.2019
10 PR51 100 EA
20 PRD9 200 EA 01.08.2019
Get Items
4
Class: Define Class by Observing all the Data and Actions on the Data
Sales Order Data to Sales Order Class 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
5
Data in SAP
Purchase Physical Material Warehouse
Sales Order Work Centre Subcontracting
Order Inventory Master Order
Purchase Purchase
Routing Storage Bins Vendor Master Service Master Cartanization
Order Requisition
Goods Issue Goods Receipt Vendor G/L Accounts Cost Elements Invoice List Capacity
Shipment Invoice JIT Call Inspection Lot Equipment JIT Call Forecasting
6
Class
Class
7
Components 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 to Other
Class
Class. Attributes generally defined in the Private Section to disable direct
Components of a Class
access from outside of the class
Types Attributes Methods Events
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 Outside.
8
Class and Its Consumers
Class
Data and Logic
Component
Accessibilit
Instances Static
Class
Components
y
s
Instance#1 Instance#1 Instance#1
Consum
9
Visibility 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 declare such Sections
11
Accessing 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
Static Attributes and Static Methods
Consumer: Class
Program | Function Module
| Other Class | Subroutine Public Components Private and Protected
Components
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
Accessing Static Attributes and Methods: Syntax and An Example
14
Instance Attributes and Instance Methods
Actions
Instance#1
Create Sales Header
Program Flow 101 PRD1 100 EA 01.01.2019
…
30 PRD3 100 EA 01.20.2019
…. Deliver
…. Release Sales Items
Obj2->Get
…. PR51 100 EA 01.01.2019
10
15
Accessing 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
Create Class and Attributes: An Example
Static and Instance
18
Consume Class and Attributes: An Example
Static and Instance
19
Method 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> |
parameters( Importing | Exporting | Changing ) with full type
specification. EXPORTING <Parameters> |
21
Create Private Method and Implement
Static and Instance:
22
Inheritance: Reusability
Inheritance allows to derive new classes from existing
classes. With the help of inheritance, we can add extra Super Class
functionality in the subclass. Private
Public Protected
Addition INHERITING FROM of the statement CLASS ... Components Components Components
Super Class
Component
s From
Public Private
Components Components
Component
s Declared
Sub Class
Public Protected Private
in the
Components Components Components
Sub Class
23
Inheritance: Reusability
Static Components: With help of Class name Consumer can Public Protected Private
access all the Public Components of the Class Components Components Components
Super Class
Component
s From
Sub Class Consumer Public Private
Components Components
Static Components: With help of Class name Consumer can
access all the Public Components of the Super Class as well
as Sub Class
Component
s Declared
Sub Class
Public Protected Private
in the
Instance Components: With help of Object reference Components Components Components
Consumer can access all the Public Components of the Super
Class as well as Sub Class
Sub Class
24
Components 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…].
PUBLIC SECTION. Types Attributes Methods Events
[Components]
PROTECTED SECTION.
[Components]
PRIVATE SECTION.
[Components]
ENDCLASS.
25