Professional Documents
Culture Documents
ABAP Objects: Andreas Blumenthal Jürgen Heymann
ABAP Objects: Andreas Blumenthal Jürgen Heymann
Andreas Blumenthal
Jürgen Heymann
SAP AG R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 1
ABAP Objects
ABAP Objects as a strategic SAP technology
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 2
Positioning ABAP Objects
Benefits of object orientation
Current situation
External interoperability
ABAP programming
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 3
Benefits of Object Orientation
Encapsulation - outside vs. inside
Explicit interfaces
Maintainability
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 4
Current Interoperability Technology
BOR (Business Object Repository)
Foundation for DCOM/CORBA connection
Fully featured standard object model
Medium level object wrappers for business functionality written
in standard ABAP
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 5
Current ABAP Programming
Complexity reduction by powerful high-level
programming constructs
Procedural abstraction (function library)
Data abstraction (type pools, complex data types)
Logical databases for hierarchical data access
Event-oriented programming with logical databases and
interactive reporting
Fully integrated SQL interface
In-memory tables: fast key access, sorted and/or nested, group
control, ...
...
R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 6
What Are ABAP Objects ?
Complete integration of a fully featured object model
into the ABAP programming language
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 7
Benefits of ABAP Objects
Identical object model for external access and internal
usage
Seamless object model from analysis through design
to implementation
Kernel-embedded foundation for objects
Make OO benefits available for the implementation of the
world’s largest business application
True two-way interoperability: ABAP <=> Java, ABAP <=> VB, ...
Speed, speed, speed !
Enabling technology for GUI programming with
frontend controls (ActiveX, JavaBeans)
R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 8
ABAP Objects
ABAP Objects as a strategic SAP technology
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 9
Fundamentals: Objects vs. Data & Functions
Objects occur 'naturally' in the world. We want to model
our software accordingly
E.g.: Transportation company: trucks (various kinds), loads
(various), etc.
Functions and data
‘Big common data structure’ and some common functions
Lots of CASE statements, sparsely filled data structures
Objects: car, truck, load, …
Various kinds of everything, objects for truck, load, …
Object: data and functions that belong together to model / implement
a specific concept
Fewer CASE statements, densely filled data, cohesion
R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 10
Fundamentals: What Is an Object ?
Objects have…
...state, described by its attributes
...behavior, described by its methods
...identity to distinguish them from other objects
with same state and behavior
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 11
The ABAP Object
Classes…
...specify behavior of ‘same kind of’ objects
...define how objects can be accessed from outside
(public vs. protected vs. private)
...hide implementation details
...may be specialized in subclasses
CLASS class DEFINITION
[ INHERITNG FROM superclass ].
[ PUBLIC SECTION.
...<definition of public components> ]
[ PROTECTED SECTION.
...<definition of protected components> ]
[ PRIVATE SECTION.
...<definition of private components> ]
ENDCLASS.
ENDCLASS.
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 12
An Example
CLASS CTruck DEFINITION.
PUBLIC SECTION.
DATA: VehicleId TYPE I READ-ONLY.
METHODS: LoadParcel IMPORTING Parcel TYPE REF TO CParcel,
UnloadParcel …
PRIVATE SECTION.
DATA: ParcelTab TYPE REF TO CParcel OCCURS 0.
ENDCLASS.
CLASS CTruck IMPLEMENTATION.
METHOD LoadParcel.
APPEND Parcel TO ParcelTab.
“-- do more stuff …
ENDMETHOD.
ENDCLASS.
PROGRAM xy.
DATA: Parcel TYPE REF TO CParcel,
Truck1 TYPE REF TO CTruck,
Truck2 TYPE REF TO CTruck.
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 13
Some Important Points
Objects are created dynamically
Storage management, garbage collection
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 14
Component Definitions
Attributes…
...store the internal state of an object (data)
…can be constants
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 15
Component Definitions
Methods…
…are operations on objects (the ‘functionality’)
No method-name overloading!
{METHODS|CLASS-METHODS} method
[ IMPORTING ...<list of import parameters> ]
[ EXPORTING ...<list of export parameters> ]
[ CHANGING ...<list of import/export parameters> ]
[ EXCEPTIONS ...<list of exceptions> ]
[ RETURNING result TYPE t ]. R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 16
Using Attributes and Methods
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA: v1 TYPE I,
o1 TYPE REF TO c1.
METHODS: m1 IMPORTING a1 TYPE REF TO c1,
m2 IMPORTING a1 TYPE REF TO c1
RETURNING result TYPE I.
PRIVATE SECTION.
DATA: v2 TYPE I.
ENDCLASS.
PROGRAM xy.
DATA o1 TYPE REF TO c1.
…
“--- attribute can occur anywhere a ‘normal variable’ can occur
CREATE OBJECT o1.
x = o1->v1 + sin( o1-> v1 ).
CALL FUNCTION 'abc' EXPORTING p1 = o1->v1 … .
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 17
Component Definitions
Events...
...occur at a particular point in time, e.g. ‘change in state of an
object’
EVENTS event
[ EXPORTING ...<list of export parameters> ].
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 18
Event Handling
Events are handled by classes
General publish-subscribe model
Syntax similar to ‘Visual Basic’ event handling
Event handlers...
...are methods for handling events from other objects
...are declared with reference to the event to be handled
(signature from there)
…must be ‘registered’ explicitly
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 19
Event Handling Example
Sender Handler
CLASS CWindow1 DEFINITION.
PUBLIC SECTION.
"--- handle events by implementing
*---- proxy class for GUI control
"--- event handler methods
CLASS CButton DEFINITION.
METHODS:
PUBLIC SECTION. OKClicked FOR EVENT Clicked OF CButton
METHODS: SetLabel IMPORTING DoubleClick,
IMPORTING Txt TYPE … . CanClicked FOR EVENT Clicked OF CButton.
EVENTS: Clicked DATA: OKBtn TYPE REF TO CButton.
EXPORTING DoubleClick TYPE I. …
ENDCLASS. ENDCLASS.
METHOD CancelClicked.
… "--- DoubleClick not visible
ENDMETHOD. R
ENDCLASS.
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 20
Class Component Definitions
Class attributes...
...are data on class level, independent of object / instance
Class methods...
...can only access class attributes
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 21
Using Class Components
*---- Transaction controller for nested transactions ----
CLASS TACtrl DEFINITION.
PUBLIC SECTION.
“--- class method to create new controller instance
CLASS-METHODS: CreateNew RETURNING TaObj TYPE REF TO TACtrl.
CLASS-DATA: Current TYPE REF TO TACtrl READ-ONLY.
METHODS: Commit, Abort. “-- instance methods
PRIVATE SECTION.
CLASS-DATA: TAStack TYPE REF TO TACtrl OCCURS 0.
ENDCLASS.
PROGRAM xy.
“--- start nested transaction
CALL METHOD TACtrl=>CreateNew.
…
CALL METHOD TACtrl=>Current->Commit. R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 22
Inheritance
A class can be derived from another
Only specify what is different / added
Add attributes and methods
Redefine / override existing methods (in any section) = change
implementation, ‘slight change’ of interface possible
‘Single inheritance’ on class
ENDCLASS.
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 23
Using Inheritance
Polymorphism on object references
ENDCLASS.
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 24
Interfaces
Interfaces define the interaction between different
objects
Polymorphism independent of class / inheritance
Classes can implement multiple interfaces
Uniform access through interface reference
ArchiveMgr
IArchiv e
Plan
Customer Material
R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 25
Interface Definition
Interfaces...
…can define same components as class - without
implementation
INTERFACE interface.
ENDINTERFACE. R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 26
Interfaces
Implementation of interfaces
A class can implement many interfaces
Interfaces are implemented ‘side-by-side’ in a class (like COM)
No name conflicts on the class level
No semantic conflicts at class level and interface composition
Using interfaces
Access by interface reference like object reference
An interface reference only exposes the components of that
interface
Assignment / ‘cast’ to another interface possible
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 27
Interface Example CLASS CArchiveMgr.
ENDMETHOD.
… IArchive
ENDMETHOD.
… Customer
R
ENDCLASS.
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 28
Interfaces and Classes
class 1
Object reference specific
Class 1
Part
Interface 1 Interface 2
if 3
Interface reference specific
Comprising
Interface 3
Interface 3 Interface 4 Interface 5
Interface reference interface
1
Implementing
Class 1 Interface reference interface
2
Inheriting Interface 4
if 4
from Interface reference specific
Class 2
class 2
Object reference specific
Class 2
Part
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 29
Naming and Visibility
Class components...
…share a common name space within the class
...may be
public = visible to all
protected = visible to subclasses and implementation
private = visible to the class implementation only
...depend on instance data or not
Interface components
Separate name space for interface components
Interfaces are visible as a whole (like ‘view’)
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 30
Miscellaneous
Avoid naming conflicts, selectively make components visible
{CLASS … DEFINITION | INTERFACE … }.
INTERFACES i.
...
ALIASES a FOR i~a.
{ENDCLASS|ENDINTERFACE}.
Constructor (Destructor)
CLASS class DEFINITION.
...
METHODS CONSTRUCTOR "--- name / syntax TBD
IMPORTING p TYPE t … .
…
ENDCLASS.
Friends
CLASS c1 DEFINITION CLASS c2 DEFINITION
EXPOSING PRIVATE COMPONENTS ACCESSING PRIVATE COMPONENTS
TO c2. OF c1.
... ...
PRIVATE SECTION. PRIVATE SECTION.
ENDCLASS. ENDCLASS.
R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 31
The ABAP Object Model
Summary
Classes and interfaces
Attributes, methods, and events
Classes can implement interfaces
Interface composition
Single inheritance for classes, multiple composition + aliasing
for interfaces
Event handling
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 32
ABAP Objects
ABAP Objects as a strategic SAP technology
Programming with objects, classes, and interfaces in
ABAP
Interoperability with other object systems
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 33
Interoperability: DCOM and CORBA
Visual
Basic Component
Connector
DCOM
*Script,
... ABAP
Objects
CORBA
Java
CORBA
Bridge
R
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 34
Interoperability Features
Transparent two-way mapping between ABAP Objects
and external object models
Location transparency:
CREATE OBJECT obj DESTINATION dest
SAP AG 1997 C01 Technology Days `97, Karlsruhe (Blumenthal & Heymann) / 35