A component comp of an object is accessed using the following name:
ref->comp
In this case, the character -> is the object component selector. A reference variable ref must be specified on the left of the object component selector as follows:
- Name of a reference variable (can itself be a composite).
- Functional method call or method chaining with reference variable as a result.
- Single or chained table expression whose result is a reference variable.
- Constructor expression with the instance operator NEW or the casting operator CAST.
- 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->* names 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 is only possible in 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
Accesses 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 ...
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 ...
No comments:
Post a Comment