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 Overwrite-Method: How to call the original

RiccardoEscher
Active Participant
0 Kudos

Hi!

I have the use case that I want to modify an importing parameter of a standard method.

I created in Enhancement Mode an overwrite method, where I move the importing parameter to a local structure, change the relevant field and then call me->core_object->method.

But there is an ugly recursion.

Is there a chance to call the original method directly skipping the replacement?

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

I would call it an endless failing recursion rather than just "ugly".

You can use an implicit source code enhancement at the beginning of the method instead of an overwrite method.

You need to define an attribute CALLED_BY_MYSELF in the class which has the initial value abap_false.

There will be a 2-times recursive call, which I would find the words "ugly recursion" better suited 😉 so I would of course try to find another solution if possible.

METHOD ...
""""""""""""""""""""
ENHANCEMENT ...
  IF called_by_myself = abap_false.
    called_by_myself = abap_true.
    CALL METHOD the_method ... " myself with changed input parameters
    RETURN.
  ENDIF.
  called_by_myself = abap_false.
ENDENHANCEMENT.
2 REPLIES 2

Sandra_Rossi
Active Contributor

I would call it an endless failing recursion rather than just "ugly".

You can use an implicit source code enhancement at the beginning of the method instead of an overwrite method.

You need to define an attribute CALLED_BY_MYSELF in the class which has the initial value abap_false.

There will be a 2-times recursive call, which I would find the words "ugly recursion" better suited 😉 so I would of course try to find another solution if possible.

METHOD ...
""""""""""""""""""""
ENHANCEMENT ...
  IF called_by_myself = abap_false.
    called_by_myself = abap_true.
    CALL METHOD the_method ... " myself with changed input parameters
    RETURN.
  ENDIF.
  called_by_myself = abap_false.
ENDENHANCEMENT.

Thank you! Simple and ingenious! That I had not thought of that...