Every now and then we will see a thread posted in BW space seeking help in transformation routines.
Start routine, end routine, field routine and expert routine; which one to use, how to use, when to use. These questions can be answered only with respect to the logic that we need to apply in any particular case.
I would like to share here, how I see, approach and write start routine…
In a data transfer process (DTP), start routine runs first. Then it is followed by transformation rules and end routine.
In medium and complex transformations, we will be having set of logic to be implemented. Those logic include exclusions, look ups, conversion, calculation etc.
A plan shall be there with us for what to write in start routine. This will be decided based on the fact that start routines runs first.
When to write;
Scenarios which are good to be written in start routine are,
1. Delete out unwanted data.
Ex: You want to delete a record if its delivery flag is not set to X, in this case you have to use start routine.
2. Populate internal table by Select data from DB table, which will be used during lookups.
Ex: In schedule line Datasource currency field is not filled for some records, you want to fill them with company code currency. For this you have to look up Company code master. In start routine you can fill an internal table with all the company and currency details. The same can be done for transaction data also.
3. Sorting the records. Based on sorting further transformation rules can be written.
In a Goods movement Datasource, if you want to process you inward deliveries against the PO number chronologically, we can sort the source package in start routine and in transformation rules they can be processed serially.
How to write;
DELETE SOURCE_PACKAGE WHERE /BIC/OIFLAG NE ‘X’.
It is better to delete unwanted records in start routine, because it won’t be processed unnecessarily in subsequent steps and reduce the data loading time.
Populating Internal table
SELECT comp_code country currency
INTO CORRESPONDING FIELDS OF TABLE it_compcd(internal table)
FOR ALL ENTRIES IN SOURCE_PACKAGE
WHERE comp_code = SOURCE_PACKAGE–bukrs.
When you write a select in field routine, it means that you are writing a select inside a loop. For an every iteration of loop, SELECT statement will hit DB table. It will result in performance issue. So it is good to write the select statement in start routine and take all possible records from DB table into an internal table.
This internal table can be looked up using READ statement.
SORT SOURCE_PACKAGE BY vendor createon po_number.
This code will sort source package by vendor, date and PO. this mean your oldest PO processed first in transformation rule.