Professional Documents
Culture Documents
SAP AG 1997
ABAP Objects
ABAP Objects as a strategic SAP technology
SAP AG 1997
Current situation
External interoperability
ABAP programming
SAP AG 1997
Explicit interfaces
Control of complexity and dependencies
Reuse - of components and by inheritance
Maintainability
Interoperability across languages (Java, VB, ...) and
object systems (DCOM/CORBA)
Foundation for patterns and frameworks
R
SAP AG 1997
SAP AG 1997
...
R
SAP AG 1997
SAP AG 1997
True two-way interoperability: ABAP <=> Java, ABAP <=> VB, ...
SAP AG 1997
ABAP Objects
ABAP Objects as a strategic SAP technology
SAP AG 1997
SAP AG 1997
SAP AG 1997
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
Component Definitions
Attributes
can be constants
SAP AG 1997
Component Definitions
Methods
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 ].
SAP AG 1997
y = obj1->m2( x ).
-- result can be used in expressions
SAP AG 1997
Component Definitions
Events...
EVENTS event
[ EXPORTING
SAP AG 1997
Event Handling
Events are handled by classes
Event handlers...
SAP AG 1997
METHOD AnyMethod.
ENDMETHOD.
ENDCLASS.
Handler
CLASS CWindow1 DEFINITION.
PUBLIC SECTION.
"--- handle events by implementing
"--- event handler methods
METHODS:
OKClicked FOR EVENT Clicked OF CButton
IMPORTING DoubleClick,
CanClicked FOR EVENT Clicked OF CButton.
DATA: OKBtn TYPE REF TO CButton.
ENDCLASS.
CLASS CWindow1 IMPLEMENTATION.
METHOD Init.
CREATE OBJECT: OKBtn, CanBtn.
SET HANDLER: OKClicked FOR OKBtn,
CanClicked FOR CanBtn.
ENDMETHOD.
METHOD OKClicked.
IF DoubleClick = 1.
ENDMETHOD.
ENDIF.
METHOD CancelClicked.
Class methods...
SAP AG 1997
SAP AG 1997
Inheritance
A class can be derived from another
ENDCLASS.
SAP AG 1997
Using Inheritance
Polymorphism on object references
CLASS DrawableObject DEFINITION
PUBLIC SECTION.
METHODS: Draw.
ENDCLASS.
CLASS Polygon DEFINITION
INHERITING FROM DrawableObject.
PUBLIC SECTION.
METHODS: AddPoint IMPORTING P TYPE T_Point,
Draw REDEFINITION.
PRIVATE SECTION.
DATA: PointTab TYPE T_Point OCCURS 0.
ENDCLASS.
CLASS Polygon IMPLEMENTATION.
METHOD Draw.
DATA: Point TYPE T_Point.
LOOP AT PointTab INTO Point.
CALL METHOD DrawableObject=>Draw( Point ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
SAP AG 1997
DrawableObject
Point
Polygon
Bitmap
PROGRAM xy.
DATA: DObj TYPE REF TO DrawableObject.
DATA: DObjTab
TYPE REF TO DrawableObject OCCURS 0.
--- create drawable objects
Interfaces
Interfaces define the interaction between different
objects
A rc h iv e M g r
IArchive
P la n
C u s to m e r
M a te ria l
R
SAP AG 1997
Interface Definition
Interfaces...
Components of enclosed interfaces are not visible in the toplevel interface (black boxes); there is a mapping/aliasing
feature
INTERFACE interface.
[ INTERFACES ...<list of comprised interfaces> .]
[ ...<definition of interface components> ]
ENDINTERFACE.
SAP AG 1997
Interfaces
Implementation of interfaces
Using interfaces
SAP AG 1997
Interface Example
INTERFACE IArchive DEFINITION.
DATA: ObjID TYPE T_OID VIRTUAL. -- fast
EVENTS: Saved, .
METHODS: SaveYourself IMPORTING .
ENDINTERFACE.
CLASS Customer DEFINITION.
INTERFACES: IArchive, IWorkflow, .
ENDCLASS.
CLASS Customer IMPLEMENTATION.
METHOD IArchive~GET_ObjID.
CALL FUNCTION Archive_Get_OID
IMPORTING IArchive~objid.
-- no more recompute
SET DIRECT READ ACCESS FOR IArchive~ObjID.
ENDMETHOD.
METHOD IArchive~SaveYourself.
--- save all own data into
ENDCLASS.
SAP AG 1997
CLASS CArchiveMgr.
DATA: IAObj TYPE REF TO IArchive.
DATA: IATab TYPE REF TO IArchive
OCCURS 0.
C A rc h iv e M g r
P lan1
ia T a b
IA r ch ive
P lan2
M aterial
C us tom er
Object reference
class 1
specific
Interface reference
if 3
specific
Interface 2
Comprising
Class 1
Part
Interface 3
Interface 3
Interface 4
Interface 5
Interface reference
interface
1
Interface reference
interface
2
Implementing
Class 1
Interface 4
Inheriting
from
Class 2
SAP AG 1997
Interface reference
if 4
specific
Object reference
class 2
specific
Interface reference
interface
5
Class 2
Part
R
...may be
Interface components
SAP AG 1997
Miscellaneous
Constructor (Destructor)
CLASS class DEFINITION.
...
METHODS CONSTRUCTOR
IMPORTING p TYPE t .
ENDCLASS.
Friends
CLASS c1 DEFINITION
EXPOSING PRIVATE COMPONENTS
TO c2.
...
PRIVATE SECTION.
ENDCLASS.
CLASS c2 DEFINITION
ACCESSING PRIVATE COMPONENTS
OF c1.
...
PRIVATE SECTION.
ENDCLASS.
R
SAP AG 1997
Interface composition
Event handling
SAP AG 1997
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
Client / Server
Visual
Basic
Component
Connector
DCOM
*Script,
...
ABAP
Objects
CORBA
Java
CORBA
Bridge
R
SAP AG 1997
Interoperability Features
Transparent two-way mapping between ABAP Objects
and external object models
Automatic generation of proxies and stubs
Location transparency:
SAP AG 1997