Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  ABAP Syntax →  ABAP Statements →  Operands →  Names for Individual Operands 

Object Component Selector

A component comp of an object is accessed using the 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).

The name comp of the component must be to the right of the object component selector. If an attempt is made to access an object component with a reference variable that contains the null reference, a non-handleable exception is raised. Dereferencing of a data reference in the statement ASSIGN is an exception to this.

The object component selector dereferences the reference variable ref and makes the components of the referenced object accessible.

  • 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.

Other versions: 7.31 | 7.40 | 7.54


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

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 ...


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 ...