05-21-2013 1:38 PM
Hi Experts,
I need to enhance a standard class method, so i created a overwrite exit for the method. But there raises a problem that i am not able to access private attributes and methods in the enhancement.
So i did a work arround, i created a custom method (public method) where i wrote the code and tried to access this custom method with in my enhancement( with in the Overwrite exit).
Now again i am facing an issue that i could not able to call the custom method in the enhancement. When I used 'me' to call the custom method.
me->init_field( ).
I am getting the following error,
Method "xxx" is unknown or PROTECTED or PRIVATE.
I also tried creating object.
data obj TYPE REF TO /SAPSRM/CL_CH_WD_MAP_HELP_CORE.
create OBJECT obj.
obj->init_field( ).
but i am getting the below error:
'The obligatory parameter "IO_PARENT_XO_MAPPER" had no value assigned to it.'
This parameter is IO_PARENT_XO_MAPPER is used in Constructor method.
Please guid me what is the issue here. How should i have to proceed further.
Regards,
Arun.
05-21-2013 1:41 PM
First, be really careful!
Second, if you want to access private attributes, create enhancement getter methods that return the private attributes.
05-21-2013 2:46 PM
Hi,
Could you please explain me what is enhancement getter methods.
Regards,
Arun
05-21-2013 3:00 PM
Create a method of your own, as an enhancement to the class, that returns the value of the private attribute.
E.g. if attribute is "request", create your own enhancement method of "get_request", which has a returning parameter of the appropriate type, and contains something like
r_request = me->request.
matt
05-21-2013 3:34 PM
ok fine. But my problem is i could not able to call my custom method 'get_request' with in my enhancement. As i explained earlier i am getting the following error:
Method "xxx" is unknown or PROTECTED or PRIVATE.
Regards,
Arun.
05-21-2013 3:39 PM
Hello Arun,
What is the ABAP release you're working on?
I'm working on Release 731 & when i create a pre/post/overwrite exit for a method, the system prompts whether you want to access the private & protected components of the class. If you say "Yes", then in the definition of the overwrite exit the "enhanced" class is defined as a local friend, thus you can access the non-public components as well.
May be this option is not available in previous ABAP releases
BR,
Suhas
05-21-2013 3:43 PM
02-13-2015 5:08 PM
Maybe a bit too late, or not relevant anymore, but at the moment I had the same issue, but Suhas gave me the answer. Although the customer also has Release 701, you can still do the same but then manually, as Suhas suggested, :
In the include, between your enhancement class' definition and implementation, just add
CLASS <sap's class> DEFINITION LOCAL FRIENDS <your class>.
and then you can access everything via core_object->....
05-30-2013 12:04 PM
Hi Arunagiri
if you want to access methods or attributes of the class from your enhanced methods
use core_object->method_name or core_object->attribute
Ex: if the standard class is cl_ex which has static method get_data
now you have written overwrite exit for get_data method
from get_data method you want to access the attribute of cl_ex
you can do it using the syntax is core_object->attribute
in the same way u can call the main class method using core_object
refer to the below document
http://help.sap.com/saphelp_nw04s/helpdata/en/86/b83142680d5c33e10000000a155106/content.htm
10-25-2013 9:04 AM
Alternatively, you can implement the implicit enhancement at the top of the method you want to overwrite, and add a return at the end. Like that the standard code will be skipped. You might have to rename all local variables, however.