Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Discover interface at runtime

Former Member
0 Likes
335

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

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
284

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

1 REPLY 1
Read only

uwe_schieferstein
Active Contributor
0 Likes
285

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