ABAP Objects – Summary of Syntax
Availability: There is a brief comment on availability under each syntax
summary. If there is no specific comment, then these components are available
as of Rel. 4.5A.
Global class definition (in the CLASS-POOL):
CLASS-POOL.
TYPES: … " local types
TYPE-POOLS: … " refer to type-pools (global types)
CLASS c … . " local helper classes
ENDCLASS
CLASS pc DEFINITION PUBLIC. " the public class of the class pool
ENDCLASS.
CLASS pc IMPLEMENTATION.
ENDCLASS.
Availability: all available as of 4.5A
Class definition:
CLASS c DEFINITION
[PUBLIC]
[ABSTRACT]
[FINAL]
[INHERITING FROM superclass]
[CREATE {PUBLIC | PROTECTED | PRIVATE}].
[PUBLIC SECTION.
… <definition of public components>]
[PROTECTED SECTION.
… <definition of protected components>]
[PRIVATE SECTION.
… <definition of private components>]
ENDCLASS.
CLASS c IMPLEMENTATION.
ENDCLASS.
*--- forward definition of class for mutual recursive references
CLASS c DEFINITION DEFERRED.
Availability: all available as of 4.5A
Class components:
CLASS c DEFINITION.
{PUBLIC|PROTECTED|PRIVATE} SECTION.
TYPES … .
CONSTANTS … .
[CLASS-]DATA a TYPE t [READ-ONLY].
METHODS m REDEFINITION.
[CLASS-]METHODS m [ABSTRACT | FINAL]
[IMPORTING …] [EXPORTING …] [CHANGING …]
[RETURNING VALUE(result) TYPE t ] [EXCEPTIONS …] .
[CLASS-]METHODS m [ ABSTRACT | FINAL]
FOR EVENT e OF {c|i}
[IMPORTING fp1 fp2 … fpn] .
[CLASS-]EVENTS e [EXPORTING … ].
ALIASES alias FOR i~a.
INTERFACES i [VALUE a1 = v1 …].
ENDCLASS.
Availability:
as of 4.5A: all components, except
as of 4.6A: METHODS : REDEFINITION , ABSTRACT ,
FINAL
Implementation of classes/methods:
CLASS c IMPLEMENTATION.
"--- implementation of methods for class, interfaces, events:
METHOD m1.
ENDMETHOD.
ENDCLASS.
Interface definition :
INTERFACE i.
* --> like public components of classes <--
ENDINTERFACE.
*--- forward definition of interface
INTERFACE i DEFERRED.
*---
INTERFACE i SUPPORTING REMOTE INVOCATION.
Availability:
as of 4.5A: all components, except
as of 4.6A: compound interfaces
Using OO:
Create objects:
CREATE OBJECT objvar [ TYPE class | TYPE (classname) ]
[ EXPORTING arg = val … ].
Availability:
as of 4.5A: CREATE OBJECT … [ EXPORTING … ]
as of 4.6A: TYPE …
Call methods:
CALL METHOD o->m [EXPORTING …] [IMPORTING …]
[CHANGING …]
[RECEIVING …] [EXCEPTIONS …].
CALL METHOD o->m( … [IMPORTING …] [CHANGING …]
[EXCEPTIONS …]).
a = o->m( [IMPORTING …] ). "functional method call
a = o->m( [arg =] val ). "ditto, with only one parameter
Availability:
as of 4.5A: CALL METHOD …
as of 4.6A: functional method call
Examples of functional method calls:
IF o->m( 4711 ) = TRUE. … ENDIF.
CASE order->status( ). WHEN … WHEN … ENDCASE.
LOOP AT itab WHERE name = o->hostname( ). …
ENDLOOP.
len = strlen( adr1->get_name( ) ) + strlen( adr2-
>get_name ) ).
MOVE o->m( p1 = val1 p2 = val2) TO dest.
Trigger event:
RAISE EVENT e [EXPORTING arg = val … ].
RAISE EVENT I~e [EXPORTING arg = val … ].
Activate/deactivate event handler:
*--- general form
SET HANDLER h1 h2 … FOR … <see below> … [ACTIVATION
cval].
*--- standard registration
SET HANDLER h1 … FOR i|o. "- register instance event for
instance
SET HANDLER h1 … . "- handler for class event
*--- group registration
SET HANDLER h1 … FOR ALL INSTANCES.
"- for "e of C" event: all instances of C
"- for "e OF I" event: all instances of all C implementing I
Availability:
as of 4.5A: all components
Widening Cast:
"--- CAST
i1 ?= o1. "--- does o1 implement interface of i1?
MOVE o1 ?TO i1. "--- same as above
Special compiler statements:
*--- make class definition known to compiler before accessing class
comp.
CLASS ddic_class DEFINITION LOAD.
*--- make interface known to compiler before accessing interface
comp.
INTERFACE LOAD.
Component selection:
Symbol Example Meaning
-> o->a Component access using object or interface
i->a reference
- x-a Component access for structures (and embedded
objects)
~ I~a Compound names for interface components
=> c=>a Access to the static components of class c