0% found this document useful (0 votes)
16 views

05 - ABAP Basics - Object Oriented Programming

Uploaded by

sumankr907162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

05 - ABAP Basics - Object Oriented Programming

Uploaded by

sumankr907162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

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

Representing data in Relational Model Representing data in Object Model

Order Customer Amount Curr Delivery Date

1 CUST1 100 USD 01.01.2019 SalesOrder#1 Sales Orders#2


Sales Header
2 CUST1 200 USD 01.08.2019 Sales Header 102 CUST1 100 US 01.01.2019
101 CUST1 100 US 01.01.2019 D
D Total Gross Blocked
Order Item Product Quantity UoM Delivery Date Total Gross Blocked
10000 USD X
1 10 PRD1 100 EA 01.01.2019 10000 USD
20
Deliver
1 PRD2 200 EA 01.08.2019
30 100 EA
Deliver X Sales Items
1 PRD1 01.01.2019

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

30 PRD3 100 EA 01.20.2019

40 PRD4 400 EA 01.31.2019

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

…. Total Gross Blocked


…. 10000 USD
Change
…. Deliver X
Obj1->Block Sales Items
..
.. Get 10 PRD1 100 EA 01.01.2019

Obj2->Block 20 PRD2 200 EA 01.08.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

…. Total Gross Blocked


…. 10000 USD X

…. 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#1 Sales Order#2 Sales Order#3 Sales Order#n

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

Sales Order Class

Data Activity Events

Order No Create Order Order Created


Customer Change Order Order Changed
Sales Org Display Order Order Blocked
Currency Block Order Order Released
Amount Release Order Order Delivered
Blocked Delivery Order Order Billed
Delivered Bill Order
Billed Get Items
Get Item

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

Outbound Request for Customer Transportation


Bill of Material Storage Units Back Orders
Delivery Quotation Master Unit
Data in SAP

Purchasing Purchase Info Customer Business


Inquiry Material Stock Transfer
Contract Records Replenishment Partner

Inbound Accounting Customer Proof of


Quotation Customer Characteristics
Delivery Data Material Delivery

Goods Issue Goods Receipt Vendor G/L Accounts Cost Elements Invoice List Capacity

Shipment Invoice JIT Call Inspection Lot Equipment JIT Call Forecasting

Billing Quality Requisition


Debit Note Control Cycle Control Cycle Profile
Document Notification Note

Shipping Posting Planned Ind


Credit Note Production Lot Cost Estimate Work Order
Document Change Requirement

Scheduling Production Transfer Customer


Sales Order Reservation Wave
Agreement Order Requirement Requirement

Stock Warehouse And Many


Contracts Planned Order Transfer Order Sales Order
Transfers Task More……

6
Class

Class Relation between Classes


A Set of Functionalities on Logically related data Functionalities of each class are independent of other Classes

Class

Data Product Class

Customer Class Vendor Class


Functionality Events

Sales Order Delivery Class Billing Class Purchase Order


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

Program Function Module Other Class


er

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

data in Public Section PRIVATE

 All types generally declared in Public Section


Sub Class PROTECTED
Sub Class can see
PROTECTED PROTECTED and
PUBLIC Components PUBLIC Consumer
 Protected components can be accessed from the Subclass. of Class Consume can see
only PUBLIC
Components
PRIVATE
 Private components can be accessed within the same class only
 If Consumer or Subclass can access the Private Attributes via Public Methods
 Generally all the declared in the Private Section
 Private method generally for Modularizing the Logic
10
Visibility Sections: Screen Shot TBD
Visibility Sections
PUBLIC | PROTECTED | PRIVATE

11
Accessing Components

Consumer: Program | Class


Function Module | Other
Class | Subroutine Public Private and Protected
Components Components

Class Level Components


Class Level Class Level
of Class with Class
Components Components
Name

Instance Level Instance Level Instance Level


Components of Class Components Components
with Object Reference

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

Static Attributes and Static Methods


Accessing Public Static Attributes Accessing Private Static Attributes

Consumer: Class
Program | Function Module
| Other Class | Subroutine Public Components Private and Protected
Components

Access Class Level


Static Static
Components( Attributes
Attributes Attributes
or Methods ) of Class
with Class Name
Static Methods Static 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
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

…. Total Gross Blocked


…. 10000 USD
Change
…. Deliver X
Obj1->Block
Sales Items
..
.. Get 10 PRD1 100 EA 01.01.2019

Obj2->Block 20 PRD2 200 EA 01.08.2019


30 PRD3 100 EA 01.20.2019

40 PRD4 400 EA 01.31.2019



… Deliver
Obj1->Release Instance#2
…. Sales Header
….
Block
102 PRD1 100 EA 01.01.2019

Obj1->Deliver Total Gross Blocked


…. 10000 USD X

…. Deliver
…. Release Sales Items
Obj2->Get
…. PR51 100 EA 01.01.2019
10

20 PRD9 200 EA 01.08.2019

30 PRD7 100 EA 01.20.2019

Get Items 40 PRD6 400 EA 01.31.2019

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.

Syntax: Define Class Syntax: Implement Class


CLASS <Class Name> DEFINITION INHERITING FROM <Super Class Name> CLASS <Class Name> IMPLEMENTATION.
ABSTRACT FINAL “Method Implementations
CREATE [ PUBLIC | PROTECTED | ENDCLASS>
PRIVATE ]
GLOBAL FRIENDS [class1 class2 ….]
[interface1 interface2…].
PUBLIC SECTION.
[Components]
PROTECTED SECTION.
[Components]
PRIVATE SECTION.
[Components]
ENDCLASS.

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> |

 If VALUE addition is specified for Parameter then it is Pass By


CHANGING <Parameters> |
Value. Else it is Pass by Reference
 Returning parameters always Pass By Value only RETURNING <Parameters>]
Syntax: Instance Method Definition
Method can be implemented in the section of the Class. During METHODS <Method Name> [ IMPORTING <Parameters> |

the method Implementation no additions can be specified.


EXPORTING <Parameters> |

Syntax: Static Method | Instance Method


Note: CHANGING <Parameters> |
CLASS <Class Name> IMPLEMENTATION.
 Static Methods can access only Static Attributes METHOD <Method Name>.
RETURNING <Parameters>]
 Instance Methods can access both Static and Instance “ Application Logic
….
ENDMETHOD. …
Attributes ENDCLASS.
ENDCLASS
20
Create Public Method and Implement: An Example
Implement and Consume TBD

21
Create Private Method and Implement
Static and Instance:

Implement and Consume TBD

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

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.

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

Super Class Consumer Super Class

Static Components: With help of Class name Consumer can Public Protected Private
access all the Public Components of the Class Components Components Components

Instance Components: With help of Object reference


Consumer can access all the Public Components of the Class

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

You might also like