‎2009 Jun 10 8:28 AM
Hello there,
is there a better way to discover wether an object implements an interface,
rather than just downcasting it and catching any resulting exception? (i. e. what
is the ABAP code equivalent for the runtime check that the ?= operator performs?).
-- Sebastian
‎2009 Jun 10 9:02 AM
Hello Sebastian
Perhaps the following sample report may be useful:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_INTF_AT_RUNTIME
*&
*&---------------------------------------------------------------------*
*& Thread: Discover interface at runtime
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1371815"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_intf_at_runtime.
DATA:
go_classdescr TYPE REF TO cl_abap_classdescr,
gt_intf TYPE abap_intfdescr_tab,
gs_intf LIKE LINE OF gt_intf,
go_msglist TYPE REF TO if_reca_message_list.
START-OF-SELECTION.
go_msglist = cf_reca_message_list=>create( ).
BREAK-POINT.
go_classdescr ?= cl_abap_classdescr=>describe_by_object_ref( go_msglist ).
LOOP AT go_classdescr->interfaces INTO gs_intf.
WRITE: / gs_intf-name, gs_intf-is_inherited.
ENDLOOP.
END-OF-SELECTION.
Regards
Uwe
‎2009 Jun 10 9:02 AM
Hello Sebastian
Perhaps the following sample report may be useful:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_INTF_AT_RUNTIME
*&
*&---------------------------------------------------------------------*
*& Thread: Discover interface at runtime
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1371815"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_intf_at_runtime.
DATA:
go_classdescr TYPE REF TO cl_abap_classdescr,
gt_intf TYPE abap_intfdescr_tab,
gs_intf LIKE LINE OF gt_intf,
go_msglist TYPE REF TO if_reca_message_list.
START-OF-SELECTION.
go_msglist = cf_reca_message_list=>create( ).
BREAK-POINT.
go_classdescr ?= cl_abap_classdescr=>describe_by_object_ref( go_msglist ).
LOOP AT go_classdescr->interfaces INTO gs_intf.
WRITE: / gs_intf-name, gs_intf-is_inherited.
ENDLOOP.
END-OF-SELECTION.
Regards
Uwe