‎2008 Mar 05 11:19 AM
Hi All,
I have an interface zintf_1. I getting the list of classes that implemented the zintf_1.
There are some cases where the class wont have implemented the interface.
ZDEMO_AA class has not implemented the interface zintf_1.
data: lr_intf_1 type ref to zintf_1,
lv_clsname type SEOCLSNAME.
lv_clsname = 'ZDEMO_AAA'.
try.
create object lr_intf_1 type (lv_clsname).
catch cx_sy_create_object_error.
.....
endtry.
In that case i m getting the dump "Type conflict with allocation of References".
Please help me to resolve the issue.
thanks
Vimalraj
‎2008 Mar 05 3:54 PM
I'm assuming that you're trying to trap the case the class lv_clsname doesn't actually implement the interface.
Well, the interface not being there is NOT a catchable error. So you have to find out whether the interface is implemented first.
DATA: lr_intf_1 TYPE REF TO zintf_1,
lv_clsname TYPE seoclsname,
lr_object TYPE REF TO cl_oo_class,
lt_intf TYPE seo_relkeys.
lv_clsname = 'ZDEMO_AAA'.
lr_object ?= cl_oo_object=>get_instance( lv_clsname ).
lt_intf = lr_object->get_implemented_interfaces( ).
READ TABLE lt_intf TRANSPORTING NO FIELDS WITH KEY refclsname = 'ZINTF_1'.
IF sy-subrc IS INITIAL.
CREATE OBJECT lr_intf_1
TYPE
(lv_clsname).
WRITE: 'it worked'.
ELSE.
WRITE / 'it failed'.
ENDIF.matt