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

Accesing attribute from caller class

former_member425121
Participant
0 Likes
636

Hi experts

I need to acces in some class wich i enhanced the attribute from other class wich is some levels up in the executing route.

I mean:

CLASS_A calls CLASS_B calls MY_ENHANCED_CLASS->methodX.

CLASS_A is wich has the attribute i need.

So in MY_ENHANCED_CLASS->methodX i need to acces the CLASS_A->attribute (but it's a instance private attribute).

Is there any way to make this acces in code ? or because the attribute is private this is not possible ?

Any help will be usefull.

Thanks & Regards

Frank

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
606

>

> So in MY_ENHANCED_CLASS->methodX i need to acces the CLASS_A->attribute (but it's a instance private attribute).

> Is there any way to make this acces in code ? or because the attribute is private this is not possible ?

I think this is a continuation to your previous question

As you must be knowing cannot access the pvt attribute directly so need some "dirty" workaround.

Something like exporting the value of this attribute to ABAP memory by enhancing the class & accessing the ABAP memory in your method!

BR,

Suhas

PS: I say "dirty" workaround because Private attributes are not meant to be shared outside of the classes. Of course "Friend" classes can access the pvt elements as well

>

> So in MY_ENHANCED_CLASS->methodX i need to acces the CLASS_A->attribute (but it's a instance private attribute).

> Is there any way to make this acces in code ? or because the attribute is private this is not possible ?

I think this is a continuation to your previous question

As you must be knowing cannot access the pvt attribute directly so need some "dirty" workaround.

Something like exporting the value of this attribute to ABAP memory by enhancing the class & accessing the ABAP memory in your method!

BR,

Suhas

PS: I say "dirty" workaround because Private attributes are not meant to be shared outside of the classes. Of course "Friend" classes can access the pvt elements as well

3 REPLIES 3
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
607

>

> So in MY_ENHANCED_CLASS->methodX i need to acces the CLASS_A->attribute (but it's a instance private attribute).

> Is there any way to make this acces in code ? or because the attribute is private this is not possible ?

I think this is a continuation to your previous question

As you must be knowing cannot access the pvt attribute directly so need some "dirty" workaround.

Something like exporting the value of this attribute to ABAP memory by enhancing the class & accessing the ABAP memory in your method!

BR,

Suhas

PS: I say "dirty" workaround because Private attributes are not meant to be shared outside of the classes. Of course "Friend" classes can access the pvt elements as well

Read only

Former Member
0 Likes
606

Hello,

the other way to work this around is to create a method in Class A, which will return the desired attribute. Then, you just call it in the place, you want to have the attribute value.

You might need to pass the instance of Class A to the method, so it isn't the nicest solution though.

Read only

0 Likes
606

Thanks Suhas, Piotrzym

With your tips i know now just what i needed.

Best regards

Frank