cancel
Showing results for 
Search instead for 
Did you mean: 

Start Routine / End Routine / Expert Routine - which one to use?

Former Member
0 Kudos

Hi,

I have a flat file datasource which I need to add an additional column to as it doesnt contain certain data. This will be based on the file name. for example, if the file name contains USA and then column should contain USA.


The options I have is to

1. Amend the file in the process chain via ABAP to add the column

2. add a start routine to the transformation - i dont think this is an option as the column does not exist in source so cant do a start routine.

3. add a end routine to the transformation to update the value OR use a routine on the actual mapping in the transformation (if no source mapping included it still lets me add a routine. Which option would be best - would the end routine only be called once? if I did the routine in the actual transformation would it go an check the file name for each record which would be an unnecessary overhead?

Views?

Cheers,

Accepted Solutions (1)

Accepted Solutions (1)

arun_purohit
Participant
0 Kudos

Hi Leo,

My recommendation:

1) Using tables RSREQDONE & RSFILENAMEDONE you can derive file name in a variable in start routine.

OR

You may replicate the logic used in infopackage to derive file name in start routine (Check all scenarios here).

2) In Transformation Routine (Mapping), read the variable derived in start routine & based on IF_ELSE assign country name to target field.

You don't need to have a source field to write a routine for target field.

Regards,

Arun Purohit

Former Member
0 Kudos

Hi,

You mentioned


You don't need to have a source field to write a routine for target field.

Are you saying it should be possible to do a start routine for a target field? My understanding was that the start routine amends the data as it comes in. If it does then I need to map that field i have amended to target.

However, I was now thinking maybe i could put a dummy source field in the datasource which is not populated by the flat say called country - then this could be amended by the start routine. I could map this field to target?

I am assuming in this scenario the start routine would only be called for each package?


Cheers,

arun_purohit
Participant
0 Kudos

Hi Leo,

You need not add dummy field in datasource though that can be a possible option.

I meant mapping routine. There you don't need any source field for writing routine.

In start routine you only need to derive file name and use that in mapping routine.

Refer screenshot below-

Regards,

Arun

Former Member
0 Kudos

Hi,

If i derive it in the start routine how do I pass it to the mapping routine? Why not derive it in the mapping routine or is that to avoid multiple checks to find out what the value is?

former_member185132
Active Contributor
0 Kudos

If you have piece of ABAP that tells you the file name, then you'll need either a combination of Start+Field Routine, or write all the code in the End Routine.

Start+Field Routine approach:

  1. Declare a global variable in the 2nd part global
  2. Based upon your logic populate that variable with the filename, in the Start routine
  3. In the field routine, just say RESULT = <<the_global_variable>>.

End Routine approach:

  1. Create a work area of the same structure as <result_fields>.
  2. Populate the "filename" field in the work area with the filename derived by your logic. Don't worry about the rest of the fields.
  3. Update this into the result by the statement MODIFY result_package FROM <<work_area>> TRANSPORTING <<filename_field>>.
Former Member
0 Kudos

Hi,

From a performance perspective which is the most appropriate method?

Start+Field Routine approach or End Routine approach?


Start+Field Routine approach: In this way is the file name code run each package and then written for each row in the field routine?


End Routine approach: In this method is the file name code run each package and then at the end of package the file name written to each row?


If my assumptions are correct the "End routine approach" sounds like slightly a better approach and also the code is all in one place?


Views

arun_purohit
Participant
0 Kudos

Hi Leo,

I don't think that there would be any significant difference in performance between these two approaches.

But yes technical difference is there:

1) End Routine: all code is there at one place, but you will need to write few more lines of code as compared to other approach as you need to do additional looping in code in result package.

2) Start routine + Field Routine: Though code is at different places, fewer lines of code is required. You need not do additional looping manually, as Field routine executes record by record (which is loop only).

I would recommend Start-Routine + Field Routine due to one less Loop.

Thanks

Answers (4)

Answers (4)

former_member214274
Active Participant
0 Kudos

Hi Leo,

As I understand here, you need to write a routine for loading flat file to PSA.

Here how come start routine, end routine or expert routine comes into picture?

Only routine that can be written at this stage is in the infopackage level for selecting files with dynamic names.

or you can write a separate ABAP program and include it in your process chain which will check the file as soon as it comes in application server and loads it to your datasource.

Here you can create multiple datasources (if there are few values for country) and code it in your program which PSA to load depending on your file name.

Thanks,

Akanksha

former_member185132
Active Contributor
0 Kudos

Regardless of start/end/expert routine, how exactly would you get the name of the flat file in your transformation? Are you using a different datasource for each file?

Former Member
0 Kudos

Hi,

I will be using some ABAP to get the name of the file - we have some specific logic to understand which file we need to pick up.

Cheers

oliver_uy2
Active Participant
0 Kudos

Hi

If the plan is just to add the column it to the DSO, I would suggest the ff:

1. on start routine, get the file name and assign in to the global variable.

2. on transformation, create a routine of the infoobject and assign the global variable.

if the plan is just to add a column inside flat file, ABAP would be the best.

Former Member
0 Kudos

Hi Leo,

1. Amend the file in the process chain via ABAP to add the column

This option will be most suitable option. 

3. add a end routine to the transformation to update the value OR use a routine on the actual mapping in the transformation (if no source mapping included it still lets me add a routine. Which option would be best - would the end routine only be called once? if I did the routine in the actual transformation would it go an check the file name for each record which would be an unnecessary overhead?

If you are doing it in end routine then the file name will be called only once for each package but need to update all records using loop statement. Better option will be doing it in file.

Thanks,

Shakthi Raj Natarajan 

Former Member
0 Kudos

Hi,

I could be wrong but don't you have to loop over the whole file in option 1 anyway to populate the field? Plus you then have the added overhead of opening the file and writing to it to then have to reopen it for reading to the PSA?

Personally I'd go for option 3 and use an end routine as you would only need to read the file once, only need to set the value for the new field once (in the end routine) and then do a loop over the result package to assign the value to the field.

Regards,

Gareth