Application Development 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: 

Enhancement of standard class method

former_member610985
Participant
0 Kudos

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.

9 REPLIES 9

matt
Active Contributor
0 Kudos

First, be really careful!

Second, if you want to access private attributes, create enhancement getter methods that return the private attributes.

0 Kudos

Hi,

Could you please explain me what is enhancement getter methods.

Regards,

Arun

matt
Active Contributor
0 Kudos

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

0 Kudos

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.

Private_Member_1084
Active Contributor
0 Kudos

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

0 Kudos

Hi Suhas,

I am working on Release 701.

Regards,

Arun.

0 Kudos

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->....

former_member191728
Active Participant
0 Kudos

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

Former Member
0 Kudos

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.