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

Access to attribute of outer class instance

Weiskopf
Participant
0 Likes
1,272

Hello together,

I have the following situation: I implemented a badi; in this badi I need to access to an attribute of the instance of the outer class; the badi is called by this outer class:

In the outer class CL_WRF_APC_PURC_LIST_DIALOG the badi EXIT_PLALV_DIALOG is called:

IF mr_exit_plalv_dialog IS NOT INITIAL.
    CALL METHOD mr_exit_plalv_dialog->set_style
      EXPORTING
        i_expanded   = im_exp
        i_level      = im_level
        i_lastline   = im_lastline
        ir_pl_item   = imr_plitem
        ir_plistline = ims_plist
      CHANGING
        ct_style     = et_style.
  ENDIF.

Is there any possibility to access to the instance of CL_WRF_APC_PURC_LIST_DIALOG from badi implementation?

Thank you & best regards,

Kurt.

Hello together,

I have the following situation: I implemented a badi; in this badi I need to access to an attribute of the instance of the outer class; the badi is called by this outer class:

In the outer class CL_WRF_APC_PURC_LIST_DIALOG the badi EXIT_PLALV_DIALOG is called:

IF mr_exit_plalv_dialog IS NOT INITIAL.
    CALL METHOD mr_exit_plalv_dialog->set_style
      EXPORTING
        i_expanded   = im_exp
        i_level      = im_level
        i_lastline   = im_lastline
        ir_pl_item   = imr_plitem
        ir_plistline = ims_plist
      CHANGING
        ct_style     = et_style.
  ENDIF.

Is there any possibility to access to the instance of CL_WRF_APC_PURC_LIST_DIALOG from badi implementation?

Thank you & best regards,

Kurt.

7 REPLIES 7
Read only

Former Member
0 Likes
1,151

Hi,

Inside BADI try below statement,

ME->attribute.

I have not tried but check if it works.

Read only

0 Likes
1,151

Hi,

Thanks for your hint, however ME is the reference of the badi instance; I need to access to the attribute of the class outside badi.

Best regards,

Kurt.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,151

You can try it through call stack.

Check this thread in which Naimesh gives an example

Read only

0 Likes
1,151

Hi,

Thank you very much; I tried the following code, but I got the object not assigend:


  data: ld_class  type string,
        ld_method type string.

  data: lo_obj    type ref to object.
  field-symbols:
    <lo_provider> type any.

  ld_class = 'CL_WRF_APC_ARTICLE_REL'.
  assign (ld_class) to <lo_provider>.
  if sy-subrc eq 0.
    lo_obj ?= <lo_provider>.
  endif.

Do you have any idea?

Thanks & best regards,

Kurt.

Read only

0 Likes
1,151

You need to add the program name where the object was created.

Example:

'(SAPMXXXXXX)CL_WRF_APC_ARTICLE_REL''

Read only

0 Likes
1,151

Hi,

Thank you for your hint.

The program where the class is called is RWRF_APC_POST_ART; but the following is not working:

ld_class =  '(RWRF_APC_POST_ART)CL_WRF_APC_ARTICLE_REL'.
assign (ld_class) to <lo_provider>.

in Program RWRF_APC_POST_ART the instance of the class CL_WRF_APC_ARTICLE_REL is created.

How can I access to the class (e.g. to a public attribute)?

Thank you & best regards,

Kurt.

Read only

0 Likes
1,151

Hi,

obviously it is no more possible to access to an outer class by a u201Cdirtyu201D assign.

I implemented to my class CL_WRF_APC_ARTICLE_REL a factory method in that way that I can get any instance by the article number.

Thanks again for your hints.

Best regards,

Kurt.