Академический Документы
Профессиональный Документы
Культура Документы
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
External interoperability
ABAP programming
SAP AG 1997
SAP AG 1997
SAP AG 1997
...
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
Programming with objects, classes, and interfaces in
ABAP
Interoperability with other object systems
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
Truck1
Truck2
TYPE
TYPE
TYPE
REF
REF
REF
TO
TO
TO
CParcel,
CTruck,
CTruck.
--CALL
CALL
SAP AG 1997
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
TO c1,
TO c1
I.
PROGRAM xy.
DATA o1 TYPE REF TO c1.
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
PROGRAM xy.
--- start nested transaction
CALL METHOD TACtrl=>CreateNew.
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
Polymorphism independent of class / inheritance
Classes can implement multiple interfaces
Uniform access through interface reference
ArchiveMgr
IArchive
Plan
Customer
Material
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.
CArchiveMgr
Plan1
iaTab
IArchive
Plan2
Material
Customer
class 1
specific
Interface reference
if 3
specific
Interface 2
Comprising
Interface 3
Object reference
Interface 4
Interface 5
Class 1
Part
Interface 3
Interface reference
interface
1
Interface reference
interface
2
Implementing
Class 1
Inheriting
from
SAP AG 1997
Interface 4
Class 2
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.
SAP AG 1997
CLASS c2 DEFINITION
ACCESSING PRIVATE COMPONENTS
OF c1.
...
PRIVATE SECTION.
ENDCLASS.
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
*Script,
...
Component
Connector
DCOM
ABAP
Objects
CORBA
Java
CORBA
Bridge
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