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

Accepted Solutions (1)

Accepted Solutions (1)

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.

Answers (5)

Answers (5)

JC-Azcoitia
Explorer
0 Kudos

Excellent, thanks Matthew and everyone who answered.

Definitely, building a separate class and instantiating it in the transformation seems to me the most effective way.

snitwipro
Active Participant
0 Kudos

I think the best way of doing this is to create a function module with the code which you don't intend to repeat and then use the function module all the places wherever required.

If both routines are in same transformation, then you can write the code in start routine, fill an internal table and then read that internal table in the field routine.

Regards

Sourav

KamalMehta
Advisor
Advisor
0 Kudos

In order to reuse codes you have to declare them in the include programs and later call them in the respective routines i.e. start , field etc.

Also this would help in tracking the changes done later on as well if using include programs.

Thanks

matt
Active Contributor
0 Kudos

I must point out that from a programming perspective, using includes for re-use is the least desirable method. Use of includes does not provide encapsulation, and so can cause problems with scope. E.g. you have two includes included - what if both declare the same variable? It also obscures functionality.

If you use proper modularisation techniques - classes, function modules or even performs - then you do not have this issue.

Former Member
0 Kudos

Hi Juan,

Please use class and methods which gives you option of reusing the routines.

Please refer document http://scn.sap.com/docs/DOC-12046

Former Member
0 Kudos

Mostly during such such kind of scenarios we go for the OOPs ABAP functionality, where you have a consolidated class containing the codes that need to be implemented in the routine.

You can dynamically call this class from the different transformations to avoid redundancy in coding.

Prathish.