Is it possible in ABAP to catch DATREF_NOT_ASSIGNED using TRY-CATCH clause?
DATREF_NOT_ASSIGNED is of category ABAP programming error, which means: "Errors in the ABAP program, such as a division by zero or a catchable exception that was not caught."
Problem: modify below code to catch the DATREF_NOT_ASSIGNED:
data gv_i type ref to i.
gv_i->*17.
Simple handling of this error is:
data gv_i type ref to i.
if gv_i is initial.
gv_i = new #( ).
endif.
gv_i->*17.
The desired solution will use TRY-CATCH or other construct for handling exceptions/errors. Below code does not work:
data gv_i type ref to i.
try.
gv_i->* = 17.
catch CX_ROOT.
gv_i = new #( ).
endtry.