cancel
Showing results for 
Search instead for 
Did you mean: 

Reuse routine for different transformation routines

JC-Azcoitia
Explorer
0 Kudos

Hi there,

I'm adding some new fields to a cube and would like to use part of the code used by one transformation routine in another routine. So if the existing routine determines whether the employees is eligible for retire, my new routine will calculate something else based on the employee eligibility. Other than repeating the same code in this new routine, which is not very efficient should the criteria change, is there any other way to do this?

Can I create a new method in LCL_TRANSFORM (for which I'd need to modify RS_ROUTINE) that would be called by different transformation routines or this is not possible because trans_routine is regenerated at some point? Before requesting a developer key to do this, I need to know if I can do that. What other options do I have?

thanks so much in advance!

Juan Carlos

View Entire Topic
matt
Active Contributor
0 Kudos

It is always good to move code out of the routines into something more permanent. My routines usually have code something like this:

IF me->r_routine IS NOT BOUND.

  CREATE OBJECT me->r_routine.

ENDIF:

me->routine->do_stuff( ...parameters...).

r_routine is declared above the routine, as an attribute of LCL_TRANSFORM.

e.g. DATA r_routine TYPE REF TO zcl_some_class.

You could equally do this using static methods of classes, function modules, or forms in subroutine pools. The advantages are:

1. You get version management

2. You can change the code without needing to reactivate the object the routine is in

3. You can properly modularise complicated code

4. You can reuse code

In your case, you'd instantiate the object in a start routine, and then call methods for the individual characteristics.