Current Poll
You can always use IS BOUND to check if the Variable is instantiated or not. But, if you want to check if any variable is referring to a class or in other words, variable is declared with TYPE REF TO, you use this technique leveraging CASTING.
Check Variable is Object Reference
" Your main variables, which you want to check if its " an object or not DATA: lo_alv TYPE REF TO cl_salv_table, lo_data TYPE REF TO data. FIELD-SYMBOLS: <fs_any> TYPE ANY. * * DATA: lo_temp_obj TYPE REF TO object, lo_root TYPE REF TO cx_root. * Object reference TRY . lo_temp_obj ?= lo_alv. WRITE: /'Is an Object'. CATCH cx_root INTO lo_root. WRITE: /'NOT an object'. ENDTRY. * * Data reference "Complier wont allow it to cast DATA ref to OBJECT ref "so you know at complie time itself if variable is object "or not "lo_temp_obj ?= lo_data. * * Dynamic Data reference GET REFERENCE OF sy-subrc INTO lo_data. ASSIGN lo_data->* TO <fs_any>. TRY . lo_temp_obj ?= <fs_any>. WRITE: /'Is an Object'. CATCH cx_root INTO lo_root. WRITE: /'NOT an object'. ENDTRY. * * Check if the object is instantiated or not IF lo_alv IS BOUND. WRITE: /'Object is instantiated'. ELSE. WRITE: /'Object is not instantited'. ENDIF.
Do you have a Code Snippet which you want to share, Submit Code Snippet here