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

Editing private methods

Former Member
0 Likes
3,293

Hi

Is is possible to add custom code to a private method of a SAP standard class? We are prototyping an upgrade of our Erec system and I have an error which is an issue with the ' add_role_to_bupa' method of the class CL_HRRCF_CANDIDATE. A SAP note meant to fix the issue has already been applied but the code is different from our current system hence the need to edit the private method.

I've been reading about enhancement options but so far nothing I've found seems to provide me with the option that I'm after.

Cheers

Jon

1 ACCEPTED SOLUTION
Read only

kay_streubel
Participant
0 Likes
2,488

Hi Jon,

you could implement an enhancemant for the class and use an overwrite-exit for the private method as shown in this document: http://wiki.scn.sap.com/wiki/display/ABAP/Enhancement+Framework+-+Class+Enhancements+-+Pre-exit,+Pos...

Regards,

Kay

12 REPLIES 12
Read only

Former Member
0 Likes
2,488

Can you write the installed oss number?

thanks

Read only

0 Likes
2,488

Note 1228153

Read only

Former Member
0 Likes
2,488

Hi,

You can do this by implementing Implicit Enhancement Point.

Follow these steps :

  1. Go to SE24 and open the method you want to add custom code to.
  2. Enable Enhacement Mode ( Shift + F4 ).
  3. Go to Menu->Edit -> Enhancement Operations -> Show Implicit Enhancement Options.
  4. Now, you will be able to see two Implicit enhancement points, 1st just below METHOD statement and 2nd just before ENDMETHOD statement.
  5. Right Click on the 2nd enhancement point, Goto Enhancement Operations -> Create Implementation.
  6. Specifiy a Zname for the enhancement.
  7. A block will appear with the zname that you provided.
  8. You can add your custom code inside this block and can use any parameters or global data available in the method.

Regards,

Ashish

Read only

0 Likes
2,488

Thanks for that Ashish.

So basically I can't alter the existing code or overwrite a private method?

So far I'm not getting he option to Goto Enhancement Operations -> Create Implementation

Read only

0 Likes
2,488

Hi,

You need access key to change the standard code which is not recommended as it will void SAP support for that object. But you can add custom code using implicit enhancement point with no such disadvantages.

You need to be in enhancement mode with implicit enhancement points visible.

  1. Go to the source code window of the method.
  2. Click on the spiral icon ( Shift + F4 ) on the application toolbar which will change the screen to enhancement mode.
  3. Now go to Edit menu button -> Enhancement operations -> Show Implicit Enhancement points.
  4. A line with quotes """"""""""""""""""" will appear just above the ENDMETHOD statement. This is the enhancement point.
  5. Place the cursor on this line and right click, a menu will appear. Then Go to Enhancement Operations -> Create Implementation.

Regards,

Ashish

Read only

0 Likes
2,488

Cheers Ashish.

I've got that now. If I now write my custom code how will that overwrite what's happening in the existing code which is causing the error?

Thanks again

Jon.

Read only

0 Likes
2,488

Hi,

Like the enhancement point you found at the end of method, similarly there is 1 at the start of the method.

So what you can do is :

  1. In the 1st enhancement point declare local data objects of same type as of the ones that are being changed in the standard code.
  2. Copy all those variables, internal tables into your local variables.
  3. Now, in the 2nd enhancement point, reallocate those variables and internal table values from your local ones to the standard ones, so this will create an effect as if the standard code inside the method has not been executed.
  4. Now add your custom code to the 2nd enhancement point.

Regards,

Ashish

Read only

0 Likes
2,488

Oh my days!! Sometimes coding with ABAP is like trying to play snooker with a piece of string!!

Thanks Ashish.

Read only

kay_streubel
Participant
0 Likes
2,489

Hi Jon,

you could implement an enhancemant for the class and use an overwrite-exit for the private method as shown in this document: http://wiki.scn.sap.com/wiki/display/ABAP/Enhancement+Framework+-+Class+Enhancements+-+Pre-exit,+Pos...

Regards,

Kay

Read only

0 Likes
2,488

Thanks Kay.

That definitely looks promising. I'll have to evaluate which option is the most suitable for my needs.

Regards

Jon

Read only

0 Likes
2,488

That is a useful tip by Kay. Use that if you want to overwrite the standard code completely.

Read only

Former Member
0 Likes
2,488

Thanks Kay and Ashish.

I chose to go with Kay's suggestion in this instance as it suited my scenario best.

Thanks for your help and guidance.

Regards

Jon