Skip to content

CX_SY_REF_IS_INITIAL

Raised when a method or attribute is accessed on an object reference that is still initial.

Purpose

CX_SY_REF_IS_INITIAL is the class-based exception behind the OBJECTS_OBJREF_NOT_ASSIGNED runtime error. It fires the moment ABAP evaluates a -> dereference on a reference variable that holds no object.

Inheritance chain: CX_SY_REF_IS_INITIAL → CX_SY_MOVE_CAST_ERROR → CX_DYNAMIC_CHECK → CX_ROOT

Catchable but not a substitute for IS BOUND

CX_SY_REF_IS_INITIAL is a CX_DYNAMIC_CHECK — it can be caught. However, the preferred pattern is to check IS BOUND before dereferencing, so the error never happens in the first place. Catching it should only be a last resort.

How to catch

TRY.
    lo_object->do_something( ).
  CATCH cx_sy_ref_is_initial INTO DATA(lx).
    MESSAGE lx->get_text( ) TYPE 'I'.
ENDTRY.

Preferred fix: check IS BOUND first

IF lo_object IS BOUND.
  lo_object->do_something( ).
ELSE.
  " handle the uninitialised case
ENDIF.

For field-symbols use IS ASSIGNED instead of IS BOUND.

Common triggers

  • A factory method (cl_salv_table=>factory, cl_http_client=>create, etc.) raised an exception that was swallowed, leaving the output reference initial.
  • READ TABLE ... INTO DATA(lo_ref) found no matching row — lo_ref stays initial after the read.
  • An optional importing parameter was not supplied by the caller.
  • An object was explicitly cleared with CLEAR lo_object and then used again.

Key attributes

Attribute Type Notes
TEXTID SOTR_CONC Message text ID
Inherited: get_text( ) string Short message text
Inherited: get_longtext( ) string Long message text

Example: factory call with guard

DATA lo_alv TYPE REF TO cl_salv_table.
DATA lt_data TYPE STANDARD TABLE OF sflight.

SELECT * FROM sflight INTO TABLE @lt_data UP TO 50 ROWS.

TRY.
    cl_salv_table=>factory(
      IMPORTING r_salv_table = lo_alv
      CHANGING  t_table      = lt_data ).
  CATCH cx_salv_msg INTO DATA(lx_salv).
    MESSAGE lx_salv->get_text( ) TYPE 'E'.
    RETURN.
ENDTRY.

" lo_alv IS BOUND here only if factory succeeded
IF lo_alv IS BOUND.
  lo_alv->display( ).
ENDIF.

See also

Comments