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

The name comp of the component must be on the right of the object component selector. 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.

If an attempt is made to access a data object (access to an instance attribute via an object reference variable or access to a structure component via a data reference variable) using a reference variable that contains the null reference, a non-handleable OBJECTS_OBJREF_NOT_ASSIGNED or DATREF_NOT_ASSIGNED exception is raised. If an attempt is made to access an instance method using a reference variable that contains the null reference, a handleable exception of the class CX_SY_REF_IS_INITIAL is raised.

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->* names the entire data object to which the data reference variable points. The dereferencing operator is the only way to dereference data references. 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 ...