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

Read Protected Attributes from another class reference

Former Member
0 Likes
4,409

Hi,

I'm using BADI_RECN_CONTRACT to check the condition currencies in the contract. When I use the reference if_recd_condition_mngr and call the method get_currency, it gives me only first condition currency.

I want all the condition currencies to be checked.

I see in the class cl_recn_condition_mngr_cn, there is an protected attribute MTO_CONDITION where I get all the condition values. But I'm not able to read as it is protected attribute. I've shown my code below.

DATA: ld_contract TYPE REF TO cl_recn_contract,
        lo_condition TYPE REF TO if_recd_condition_mngr,
        lc_condition TYPE REF TO cl_recn_condition_mngr_cn.
  DATA: lt_cond TYPE re_t_recd_condition,
        lt_condref TYPE REF TO RE_T_IF_RECD_CONDITION.
* additional check
  ld_contract ?= io_object.
  l_curr = ld_contract->get_recncncurr( ).
  lo_condition = ld_contract->mo_condition_mngr.
  lc_condition ?= lo_condition.
*  lt_condref = lc_condition->MTO_CONDITION.
  l_condcurr = lo_condition->get_currency( ).

Can anyone please tell me how can I access protected attribute ?

Regards,

JMB

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,990

Hello JMB

You have to use the method which returns you all condition objects:


DATA: ld_contract TYPE REF TO cl_recn_contract,
        lo_cond_mngr      TYPE REF TO if_recd_condition_mngr,
        lo_cond_mngr_cn TYPE REF TO cl_recn_condition_mngr_cn.
  DATA: lt_cond TYPE re_t_recd_condition,
        lt_condref TYPE REF TO RE_T_IF_RECD_CONDITION.
* additional check
  ld_contract ?= io_object.
  l_curr = ld_contract->get_recncncurr( ).

  lo_cond_mngr = ld_contract->mo_condition_mngr.
"  lo_cond_mngr_cn ?= lo_cond_mngr.

  DATA: lto_conditions     TYPE RE_T_IF_RECD_CONDITION.

  CALL METHOD lo_cond_mngr->GET_LIST
    EXPORTING
      eto_condition = lto_conditions.

" Now LOOP over these instances
...

Regards

Uwe

4 REPLIES 4
Read only

Former Member
0 Likes
1,990

hi,

Protected data members are accessible from within members of their base-class; from within members of the friends of their base-class; and from within members and friends of any classes derived from that base-class.

so you can access the protected data of the class only by the member functions of that class or the member functions

of the friend class. and inherited classes

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,991

Hello JMB

You have to use the method which returns you all condition objects:


DATA: ld_contract TYPE REF TO cl_recn_contract,
        lo_cond_mngr      TYPE REF TO if_recd_condition_mngr,
        lo_cond_mngr_cn TYPE REF TO cl_recn_condition_mngr_cn.
  DATA: lt_cond TYPE re_t_recd_condition,
        lt_condref TYPE REF TO RE_T_IF_RECD_CONDITION.
* additional check
  ld_contract ?= io_object.
  l_curr = ld_contract->get_recncncurr( ).

  lo_cond_mngr = ld_contract->mo_condition_mngr.
"  lo_cond_mngr_cn ?= lo_cond_mngr.

  DATA: lto_conditions     TYPE RE_T_IF_RECD_CONDITION.

  CALL METHOD lo_cond_mngr->GET_LIST
    EXPORTING
      eto_condition = lto_conditions.

" Now LOOP over these instances
...

Regards

Uwe

Read only

0 Likes
1,990

Hi,

Thank u very much. I dont know how did I miss that method.

Regards,

JMB

Read only

0 Likes
1,990

Hello JMB

For me it clear why you missed this method - because you did not clearly distinguish between an "object" and its corresponding "object manager" (see coding below).

Every manager object has a method to retrieve its collection of "sub-ordinated" objects:

- Condition Manager => conditions

- Resubmission Manager => resubmissons

- Partner Manager => partners

- ...

Thus, my recommendation is to use naming conventions for these clearly distinct objects.


DATA: ld_contract TYPE REF TO cl_recn_contract,
        lo_condition TYPE REF TO if_recd_condition_mngr,
        lc_condition TYPE REF TO cl_recn_condition_mngr_cn.
  DATA: lt_cond TYPE re_t_recd_condition,
        lt_condref TYPE REF TO RE_T_IF_RECD_CONDITION.

...

Regards

Uwe