Professional Documents
Culture Documents
◦ ABAP programming
◦ ...
Complete integration of a fully featured object
model into the ABAP programming language
100% upward-compatible extension of ABAP/4
◦ Bottom up: use objects in existing ABAP programs (reports,
module- and function-pools)
[ PUBLIC SECTION.
...<definition of public components> ]
[ PROTECTED SECTION.
...<definition of protected components> ]
[ PRIVATE SECTION.
...<definition of private components> ]
ENDCLASS.
PROGRAM xy.
DATA: Parcel TYPE REF TO CParcel,
Truck1 TYPE REF TO CTruck,
Truck2 TYPE REF TO CTruck.
◦ …can be constants
◦ No method-name overloading!
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 … .
METHOD CancelClicked.
… "--- DoubleClick not visible
ENDMETHOD.
ENDCLASS.
Class attributes...
◦ ...are data on class level, independent of object / instance
Class methods...
◦ ...can only access class attributes
PROGRAM xy.
“--- start nested transaction
CALL METHOD TACtrl=>CreateNew.
…
CALL METHOD TACtrl=>Current->Commit.
A class can be derived from another
◦ Only specify what is different / added
ENDCLASS.
Polymorphism on object references
CLASS DrawableObject DEFINITION
PUBLIC SECTION.
DrawableObject
METHODS: Draw.
ENDCLASS.
inheritance
Classes can implement multiple interfaces
Uniform access through interface reference
ArchiveMgr
IArchive
Plan
Customer Material
Interface Definition
Interfaces...
◦ …can define same components as class - without
implementation
ENDINTERFACE.
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
CLASS CArchiveMgr.
ENDMETHOD.
… IArchive
ENDMETHOD.
… Customer
ENDCLASS.
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
◦ 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.
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
ABAP Objects as a strategic SAP technology
Programming with objects, classes, and
interfaces in ABAP
Interoperability with other object systems
Interoperability: DCOM and CORBA
Visual
Basic Component
Connector
DCOM
*Script,
... ABAP
Objects
CORBA
Java
CORBA
Bridge
Transparent two-way mapping between ABAP
Objects and external object models
Location transparency:
◦ CREATE OBJECT obj DESTINATION dest