Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Object problem

Hy !

Is there in SAP something similar to instanceof in Java ?

Thanks

replied

Check this. It is not directly built-in to the language, but you can acheive the same with a little coding.

report ztest.

*---------------------------------------------------------------------*
*       CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app definition.

  public section.
    data: field type string.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.


endclass.

data: o_ref type ref to cl_abap_classdescr,
      o_object type ref to object.

create object o_object type lcl_app.

o_ref ?= cl_abap_typedescr=>describe_by_name( 'LCL_APP' ).

if  o_ref->applies_to( o_object ) = 'X'.
  write / 'This Object is an instance of the class'.
else.
  write / 'This Object is NOT an instance of the class'.
endif.

Regards,

Rich Heilman

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question