Skip to content

OBJECTS_OBJREF_NOT_ASSIGNED

A method or attribute was accessed on an object reference that is still initial (null).

The reference variable was declared but never pointed at an actual object instance before you called a method or read an attribute on it.

Symptom

ST22 shows:

Runtime Errors         OBJECTS_OBJREF_NOT_ASSIGNED
Exception              CX_SY_REF_IS_INITIAL
Short text             Access via 'NULL' object reference not possible.

The dump line is the -> dereference, not where the variable was declared.

Cause

A variable declared with TYPE REF TO starts as INITIAL — it holds no object. Any -> access on an initial reference dumps immediately.

Common triggers:

  • A factory method returned nothing (e.g. cl_salv_table=>factory( ) raised an exception you swallowed) and you used the output anyway.
  • READ TABLE ... INTO DATA(lo_ref) didn't find a row — lo_ref is still initial after the read.
  • ASSIGN ... TO <fs> on a non-existent component left the field-symbol unassigned, then you dereferenced it.
  • A method parameter typed TYPE REF TO was left unfilled by an optional caller.

Reproduce

DATA lo TYPE REF TO cl_salv_table.

" lo is still initial — no CREATE OBJECT, no factory call
lo->display( ).   " <-- OBJECTS_OBJREF_NOT_ASSIGNED dumps here

Field-symbol variant:

FIELD-SYMBOLS: <fs> TYPE REF TO cl_salv_table.

" <fs> never assigned
<fs>->display( ).   " <-- dumps here

Fix

DATA lo TYPE REF TO cl_salv_table.

" ... factory call or READ TABLE ...

IF lo IS BOUND.
  lo->display( ).
ELSE.
  MESSAGE 'Reference not initialised' TYPE 'I'.
ENDIF.
DATA lo TYPE REF TO cl_salv_table.

IF lo IS NOT INITIAL.
  lo->display( ).
ENDIF.
FIELD-SYMBOLS: <fs> TYPE REF TO cl_salv_table.

ASSIGN lo TO <fs>.

IF <fs> IS ASSIGNED.
  <fs>->display( ).
ENDIF.
TRY.
    lo->display( ).
  CATCH cx_sy_ref_is_initial INTO DATA(lx).
    MESSAGE lx->get_text( ) TYPE 'I'.
ENDTRY.

IS BOUND vs IS INITIAL

For object references IS BOUND is the correct check — it returns false for both initial references and references to objects that have been freed. IS INITIAL also works but does not detect freed objects. For field-symbols use IS ASSIGNED.

Prevention

  • After every factory call (cl_salv_table=>factory, io_context->get_..., etc.) check IS BOUND before proceeding.
  • After READ TABLE ... INTO DATA(lo_ref), always check SY-SUBRC = 0 before using lo_ref.
  • Declare method parameters OPTIONAL only when the caller genuinely does not need to supply them, and guard against the initial case inside the method.
  • Enable extended program check (transaction SLIN) — it flags most unguarded dereferences statically.

See also

  • CX_SY_REF_IS_INITIAL — exception class raised by this dump
  • Transaction ST22 — ABAP runtime error analysis

Comments