Académique Documents
Professionnel Documents
Culture Documents
Classes
Interfaces
Accordingly, names for operands are either elementary names or names constructed from multiple names
separated by component selectors. An elementary name is used for addressing:
elementary operands
Naming conventions apply to the elementary names. Composite names with component selectors are used for
addressing individual components. A component can itself be a superunit of further components.
Subcomponents can be addressed by chaining multiple names.
If ref is an object reference variable, the components comp of the object (attributes and methods) to
which the object reference variable points are addressed using the object component selector.
If ref is a data reference variable that is typed as a structure, the components comp of the structure to
which the data reference variable points are addressed using the object component selector.
Note
If ref is a data reference variable, the character * can be specified after the object component selector ->.
This creates the general dereferencing operator ->*. The expression ref->* labels the entire data object to
which the data reference variable points. The dereferencing operator is the only way to dereference data
references. In the case of untyped data reference variables, this was only possible using the statement
ASSIGN. The dereferencing operator cannot be specified after object reference variables. The instance
components of classes can only be accessed using the expression ref->comp.
Example
Access to the public attribute a1 of a class c1 by using the object reference variable oref.
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA a1 TYPE string READ-ONLY.
ENDCLASS.
...
DATA oref TYPE REF TO c1.
... oref->a1 ...
Example
The data reference variable dref is typed as a structure and the component carrid of the referenced
structure is accessed using the object component selector. The expression dref->carrid has the same
meaning as the chaining dref->*-carrid.
DATA dref TYPE REF TO sflight.
...
... dref->carrid ...
In this case, the character ~ is the interface component selector. The name intf of an interface must be to the
left of the interface component selector. The name comp of the component must be to the right of the object
component selector.
The name intf~comp identifies the components of interfaces in classes or component interfaces in composite
interfaces.
Note
An interface contains each component exactly once, regardless of how it is composed of component interfaces.
All the interface components are at the same hierarchical level. The name of an interface component is
uniquely defined using intf~comp. intf is always the interface in which the component is declared. A direct
chaining of interface names intf1~...~intfn~comp is not possible.
Example
Declaration of interfaces and access to their components.
INTERFACE i1.
TYPES t1 TYPE string.
ENDINTERFACE.
INTERFACE i2.
INTERFACES i1.
METHODS m2 IMPORTING p1 TYPE i1~t1.
ENDINTERFACE.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i2.
ENDCLASS.
...
DATA oref TYPE REF TO c1.
oref->i2~m2( ... ).
...
CLASS c1 IMPLEMENTATION.
METHOD i2~m2.
...
ENDMETHOD.
ENDCLASS.
Chainings
Whenever operands are grouped together from components, which themselves contain components, the
names of these components are composed from chains with multiple component selectors. The following rules
apply to these chained names:
The names to the left of each structure component selector must, as a combined group, address a
structured data type or a structure.
The names to the left of each object component selector must, as a combined group, address a
reference variable.
The class component selector can occur in a name exactly once as the first selector.
The interface component selector can only occur more than once in a label if other component
selectors are listed between the individual interface component selectors.
Example
Declaration of a nested structured data type struc2 in struc1 and a structure struc3 in an interface i1.
The component comp of struc3 is a data reference variable of the static type struc1. The i1 interface is the
component interface of i2 and the latter is implemented in c1. In c2, a static attribute is declared as the object
reference of the static type c1. The expression in the last line can be at an operand position that expects a data
object, and labels the component comp of the structure struc2 in a chaining that starts at class c2. A
prerequisite for use of the expression is that both reference variables, oref and dref, point to the respective
instances.
INTERFACE i1.
TYPES: BEGIN OF struc1,
...
BEGIN OF struc2,
...,
comp TYPE ...,
...,
END OF struc2,
...
END OF struc1.
DATA: BEGIN OF struc3,
...
dref TYPE REF TO struc1,
...
END OF struc3.
ENDINTERFACE.
INTERFACE i2.
INTERFACES i1.
ENDINTERFACE.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i2.
ENDCLASS.
CLASS c2 DEFINITION.
PUBLIC SECTION.
CLASS-DATA oref TYPE REF TO c1.
ENDCLASS.
...
... c2=>oref->i1~struc3-dref->struc2-comp ...
Note
The escape character may be required on rare occasions in which the compiler cannot tell the difference
between an operand and a reserved word of the same name. Otherwise, it can be used for the documentation
of operands in the source code.
Example
Without the escape character ! before CHANGING after USING, the following program extract would have
incorrect syntax, because a formal parameter must be entered after USING. Although the second escape
character is not necessary, it serves to document USING after CHANGING as a formal parameter.
FORM test USING !CHANGING
CHANGING !USING.
using = changing.
ENDFORM.