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

Use AGENT through dynamic attribute access

matt
Active Contributor
0 Likes
387

I'm working with some persistent objects, but don't know the actual persistent class until runttime. To get the agent, I've coded this

DATA: l_agntclass TYPE classname,
     lr_det_agent TYPE REF TO cl_os_ca_common.

FIELD-SYMBOLS <lr_det_agent> TYPE any.

l_agntclass = me->derive_agent_classname( ).

ASSIGN (l_agntclass)=>agent to <lr_det_agent>.
lr_det_agent ?= <lr_det_agent>.

Now I can call the methods of lr_det_agent. All well and good, and it works, but is this the right way? I tried defining <lr_det_agent> as TYPE REF TO. But that failed in the assign. And I tried CASTING TYPE on the assign, but that doesn't accept classes.

Am I missing something obvious?

Thanks

matt

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
364

Hello Matt

The solution is quite simple (see below):


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_PERSISTENT_CLASS
*&
*&---------------------------------------------------------------------*
*& Thread: Use AGENT through dynamic attribute access
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1143122"></a>
*&---------------------------------------------------------------------*

REPORT  zus_sdn_persistent_class.


DATA: gd_clsname    TYPE classname,
      gd_method     TYPE string,
      gd_attribute  TYPE string.

DATA: go_obj        TYPE REF TO object,  " root object
      go_os_common  TYPE REF TO cl_os_ca_common.

DATA: go_persist    TYPE REF TO cb_alert,
      go_agent      TYPE REF TO ca_alert.

FIELD-SYMBOLS <go_det_agent> TYPE ANY.

START-OF-SELECTION.

  BREAK-POINT.

  gd_attribute = 'CA_ALERT=>AGENT'.
  " In your case: CONCATENATE l_agntclass '=>AGENT' ...
  ASSIGN (gd_attribute) TO <go_det_agent>.

  go_os_common ?= <go_det_agent>.

  BREAK-POINT.

END-OF-SELECTION.

Regards

Uwe

1 REPLY 1
Read only

uwe_schieferstein
Active Contributor
0 Likes
365

Hello Matt

The solution is quite simple (see below):


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_PERSISTENT_CLASS
*&
*&---------------------------------------------------------------------*
*& Thread: Use AGENT through dynamic attribute access
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1143122"></a>
*&---------------------------------------------------------------------*

REPORT  zus_sdn_persistent_class.


DATA: gd_clsname    TYPE classname,
      gd_method     TYPE string,
      gd_attribute  TYPE string.

DATA: go_obj        TYPE REF TO object,  " root object
      go_os_common  TYPE REF TO cl_os_ca_common.

DATA: go_persist    TYPE REF TO cb_alert,
      go_agent      TYPE REF TO ca_alert.

FIELD-SYMBOLS <go_det_agent> TYPE ANY.

START-OF-SELECTION.

  BREAK-POINT.

  gd_attribute = 'CA_ALERT=>AGENT'.
  " In your case: CONCATENATE l_agntclass '=>AGENT' ...
  ASSIGN (gd_attribute) TO <go_det_agent>.

  go_os_common ?= <go_det_agent>.

  BREAK-POINT.

END-OF-SELECTION.

Regards

Uwe