Beruflich Dokumente
Kultur Dokumente
ABAP Objects
Objectives
This lecture will
Review the Procedural Programming Model
Introduce the Object Oriented Programming Model
Examine how ABAP has applied OO features to its language
Examine how classes are defined in ABAP Objects
Examine how attributes and methods of a class are defined in ABAP Objects
Examine the objects are created in ABAP Objects
Examine how references are assigned in ABAP Objects
Explain the meaning of a constructor and how it is used in ABAP Objects
Discuss the concept of inheritances and how it is used in ABAP Objects
BCO5647
Data
Data
Data
Data
Data
Function
Function
Function
Function
Function
Function
Function
Function
Type definitions.
Data declarations
Main program
- Calling subroutines
- Calling function modules
Definition of subroutines.
BCO5647
Real world
Model
House
Tree
Data
Method
Method
Method
Data
Method
Method
Method
Crane
Data
Method
Method
Method
Boat
Data
Method
Method
Method
SAP AG 1999
BCO5647
lcl_class
Class
Gives a general description
of objects (blueprint)
Establishes status types
(attributes) and behavior
(methods)
Attribute
Attribute
Attribute
Method
Method
Object
Reflection of real world
Specific instance of a class
BCO5647
counter = counter + 1.
create object . . .
move wa to . . .
BCO5647
9
Sequence diagrams
etc.
10
11
OO Definitions : Objects
The Object (1)
Example: airplane
Attributes
Attributes
Name: LH Berlin
Methods
Weight: 30,000 kg
land
Length: 70 m
fly
Methods
Events
Events
landed
Private access
Encapsulation
As a rule, attributes
Public access
Interface
As a rule,methods, events
SAP AG 1999
The object in the above model has two layers: an outer shell and an
inner core. Users can only see the outer shell, while the inner core
remains hidden.
Public components (outer shell): the outer shell contains the
components of the object that are visible to users.
Private components (inner core): the components of the inner core
(attributes, methods and events) are only visible within the object
itself.
BCO5647
12
OO Definitions : Classes
Classification
Plane
Plane ticket
SAP AG 1999
In the real world, there are objects, such as various airplanes and plane
tickets. Some of these objects are very similar, that is, they can be
described using the same attributes or characteristics and provide the
same functions.
Similar objects are grouped together in classes. A class is therefore a
description of a quantity of objects characterized by the same structure
and the same behavior.
BCO5647
13
Definition Part
The class components (e.g. attributes and methods).
Implementation Part
The method implementations.
The CLASS statement cannot be nested.
BCO5647
14
BCO5647
15
OO Definitions : Attributes
CLASS <classname> DEFINITION.
PRIVATE SECTION.
. . .
types: . . .
constants: . . .
data: variable1
variable2
variable3
type local-type,
type global_type,
like variable1,
variable4
type . . . read-only.
variable5
variable6
16
OO Definitions : Methods
Contain coding
Have an interface
lcl_airplane
Methods :
...
Contain coding
fly
Have an interface
land
SAP AG 1999
BCO5647
17
<methodname>
IMPORTING . . .
EXPORTING . . .
CHANGING . . .
RETURNING . . .
EXCEPTIONS . . .
ENDCLASS.
BCO5647
18
BCO5647
19
Creating Objects
Objects can only be created and addressed using
reference variables
lcl_airplane
name
weight
...
CREATE OBJECT
name:
LH Berlin
weight: 30,000 kg
SAP AG 1999
20
BCO5647
21
Assigning References
BCO5647
22
Constructors
lcl_airplane
name
weight
count
constructor
CREATE
OBJECT
23
Constructors : Example
REPORT EXAMPLE04.
CLASS lcl_airplane DEFINITION.
PUBLIC SECTION.
DATA: name
type string,
weight
type i,
carrier
type string.
METHODS: constructor importing
icarrier type string.
ENDCLASS.
CLASS lcl_airplane IMPLEMENTATION.
METHOD constructor.
Carrier = icarrier.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA : airplane1 TYPE REF to lcl_airplane,
airplane2 TYPE REF to lcl_airplane.
CREATE OBJECT airplane1 exporting
icarrier = LH.
CREATE OBJECT airplane2 exporting
icarrier = QA.
BCO5647
24
Inheritance
25