cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing private attribute of a class from its Friend Class

former_member583823
Participant
0 Kudos

Hi Experts ,

Please help me to understand how can i access private attribute of one class from its friend class.

I am coding in Method (DO_SAVE) of class /BOBF/CL_TRA_TRANSACTION_MGR.

I need to access private variable ( MO_BOPF) of class /BOBF/CL_TRA_SERVICE_MGR ( Friend of /BOBF/CL_TRA_TRANSACTION_MGR ).

Regards,

Reny Richard

Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi Reny,

You should be able to access by creating object of friend class.

Sample:


data lo_frnd     TYPE REF TO  /BOBF/CL_TRA_SERVICE_MGR.

data lo_compl  type REF TO /BOBF/IF_TRA_TRANS_MGR_COMPL.

   create OBJECT lo_frnd

     exporting

               iv_bo_key = '111'

               IO_COMPL_TRANSACTION_MANAGER = lo_compl.


"access the private object of friend class

   clear lo_frnd->MO_BOPF.


Note: need to provide iv_bo_key & IO_COMPL_TRANSACTION_MANAGER while creating object.


Hope this helps you.


Regards,

Rama

Answers (1)

Answers (1)

former_member184578
Active Contributor
0 Kudos

Hi,

If it is a static attribute you can access using /BOBF/CL_TRA_SERVICE_MGR=>MO_BOPF

It is is instance attribute, create an object for the class and access it using that object

data lr_srv_mgr type ref to /BOBF/CL_TRA_SERVICE_MGR.

create object lr_srv_mgr.

lv_bopf = lr_srv_mgr->mo_bopf.

Regards,

Kiran