12-11-2006 2:12 PM
Hy !
Is there in SAP something similar to instanceof in Java ?
Thanks
12-11-2006 2:26 PM
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
12-11-2006 2:26 PM
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
12-11-2006 2:26 PM
Hello Ariana
Please have a look at the static method <b>CL_WDY_WB_REFLECTION_HELPER=>IS_INSTANCE_OF</b> (available on 6.40).
Regards
Uwe
12-11-2006 5:12 PM
Please DONOT use class CL_WDY_WB_REFLECTION_HELPER. It is NOT released for public use. At least with higher levels of release or support package any use will violate package restrictions.
regards,
Klaus