Sei sulla pagina 1di 5

Definition

You can use routines to define complex transformation rules for a key figure or a characteristic.

Routines are local ABAP classes that consist of a predefined definition and implementation area. The
TYPES for the inbound and outbound parameters as well as the method signature are stored in the
definition area. The actual routine is created in the implementation area. In the method, you can assign
ABAP objects. At the time of generation, this method is embedded into the transformation program.

Transformation contains the following types of routines:

• Start routine

• Routine for key figures or characteristics

• End routine

• Expert routine: This type of routine is intended only for special cases. You can use the expert
routines if the transformation functions provided are not sufficient for your requirements. You can
use this as an interim solution until the required function is available in the standard system. You
can use this means to program the entire transformation yourself without using the available rule
types. If you do this, you have implement the transfer of messages to the monitor yourself as well.

Procedure
Enter the following information to create a routine:

1. Between *$*$ begin of global ... and *$*$ end of global ... you can
define global data declarations 'CLASS-DATA' that are then available in all routines. You can
access data declarations with 'DATA' in the current package.
This means that you can, for example, use intermediate results in other routines, or if you call the
same routine again, you can reuse the results from the first call.
Note:
During serial loading, data declared with 'CLASS-DATA ' is kept, as long as the process instance
exclusively reserved for this request continues to exist. A process that has been instantiated is also
used more than once during parallel loading, for performance reasons. This means that the data
declared with 'CLASS-DATA' from a process instance is kept.
Therefore, depending on the scenario, use 'CLASS-DATA' or 'DATA' for the global data.
2. Insert your program code for the routine between *$*$ begin of routine ... and
*$*$ end of routine .... Check the syntax of your routine.
3. Save the routine.
Exit the editor to end the maintenance of the routine.

Dependencies
According to the settings in the batch manager, the data is updated either in serial or in parallel.
Use
The start routine is executed for each data package at the start of the transformation. The start routine does
not contain any return values. It is there to perform perliminary calculations and to store these in a global
data structure or table. The system can then access this structure or table in the other routines. They can
change or delete data.

Start Routine Parameters

Importing

REQEUST: Request ID

DATAPAKID: Number of the current data package

Exporting

MONITOR: Table for User-defined monitoring. This table is filled using the MONITOR_REC line structure
(the framework automatically adds the number of the record to be processed).

Changing

SOURCE_PACKAGE: Structure containing the input fields for the routine

Raising

CX_RSROUT_ABORT: If a raise exception of type cx rsrout_abort is triggered within the routine, the entire
loading process is terminated. The request is flagged in the extraction monitor as terminated. Processing of
the current data package is ended. In the event of serious errors, that can be helpful.

Example
You use the General Ledger: Transaction Figures DataSource (FI_GL_1) in the ERP system to load data
into the FIGL: Transaction Figures DataStore object (0FIGL_O06).

You want to create a start routine that deletes all records in the data package for which the debit and credit
postings are zero.

1. You create a transformation. The source of the transformation contains the fields Total Debit
Postings (UMSOL) andTotal Credit Postings (UMHAB), which are assigned to the InfoObjects Total
Debit Postings (0DEBIT) and Total Credit Postings (0CREDIT).
2. You choose Create Start Routine. The routine editor opens.
3. You go to the local part of the routine and insert the following line of coding:

*$*$ begin of routine - insert your code only below this line *-
*

... "insert your code here


DELETE SOURCE_PACKAGE where UMHAB = 0 and UMSOL = 0

*$*$ end of routine - insert your code only before this line *-
*
The Delete statement is the only line that you require to filter debit and credit postings that contain
no values out of the data package.
4. You exit the routine editor.
5. You save the transformation. The pencil icon in front of the start routine indicates that a start
routine exists.

Use
The end routine is a routine with a table in the format of the target structure as input and output parameters.
You can use it to postprocess the data package by package after transformation. For example, you can
delete records that are not to be updated or perform checks on the data.

Parameters in the End Routine

Importing

REQEUST: Request ID

DATAPAKID: Number of the current data package

Exporting

MONITOR: Table for user-specific monitoring. This table is filled using the MONITOR_REC line structure
(the framework automatically adds the number of the record processed).

Changing

RESULT_PACKAGE: Contains all data that gone through transformation

Raising

CX_RSROUT_ABORT: If a raise exception type cx rsrout_abort is triggered at any point in the routine, the
entire loading process is terminated. The request is flagged in the extraction monitor as terminated.
Processing of the current package ends. In the case of serious errors, this can be helpful.

Example
You use the General Ledger: Transaction Figures (FI_GL_1) DataSource in the ERP system to load data to
the FIGL: Transaction Figures (0FIGL_O06) DataStore object.

You want to create an end routine that fills the additional Planned/Actual Indicator (ZPLACTUAL) InfoObject.
To do this, the routine is to read the Value Type field. If the value is 10 (Actual), the system writes the value A
to the Planned/Actual Indicator (ZPLACTUAL) InfoObject; If the value is 20 (Planned), the system writes the
value P to the Planned/Actual Indicator (ZPLACTUAL) InfoObject.

1. You are in the transformation maintenance transaction. You choose Create End Routine. The
routine editor opens.
2. You insert the following lines of coding:

*$*$ begin of routine - insert your code only below this line *-*

... "insert your code here


loop at RESULT_PACKAGE assigning <RESULT_FIELDS>
where vtype eq '010' or vtype eq '020'.
case <RESULT_FIELDS>-vtype.
when '010'.
<RESULT_FIELDS>-/bic/zplactual = 'A'. "Actual
when '020'.
<RESULT_FIELDS>-/bic/zplactual = 'P'. "Plan endcase.
endloop.

*$*$ end of routine - insert your code only before this line *-*

The coding loops at the result_package and searches for values that have the value type 10 or 20.
The system then passes on the corresponding value to the Planned/Actual Indicator (ZPLACTUAL)
InfoObject for these values.
3. You exit the routine editor.
4. You save the transformation. You can recognize that there is an end routine by the pencil icon in
front of the end routine.

Use
The Routine for Key Figures or Characteristics is available as a rule type, that is, you can define a routine as
a transformation rule for a key figure or a characteristic.

In the case of InfoCubes, you can also choose Routine with Unit. This results in the routine also containing
the return parameter 'UNIT', which allows you to store the required unit for the key figure, for example, 'PC'.
For example, you can use this option to convert the unit available in the source, kilograms, to tonnes in the
target.

Parameters in the Routine for Key Figures or Characteristics

Importing

REQEUST: Request ID

DATAPAKID: Number of the current data package

SOURCE_FIELDS: Structure with the input fields defined on the UI for the routine

Exporting

MONITOR: Table for user-specific monitoring. This table is filled using the MONITOR_REC line structure
(the framework automatically adds the number of the record processed).

RESULT: You have to assign the results of the calculated key figure or characteristic to the RESULT
variable.

CURRENCY (optional): In routines involving currencies, you must assign the currency here.

UNIT(optional): In routines involving units, you must assign the unit here.

Raising
To control what is written to the target, the system uses exception handling with exception classes:

CX_RSROUT_SKIP_RECORD: If a raise expection type cx_rsrout_skip_record is


triggered at any point in the routine, the system terminates processing of the current line and continues with
the next data record.

CX_RSROUT_ABORT: If a raise exception type cx rsrout_abort is triggered at any point


in the routine, the entire loading process is terminated. The request is flagged in the extraction monitor as
terminated. Processing of the current package ends. In the case of serious errors, this can be helpful.

Example
Example of a Characteristic Routine:

You use the General Ledger: Transaction Figures (FI_GL_1) DataSource in the ERP system to load data to
the FIGL: Transaction Figures (0FIGL_O06) DataStore object.

You want to create a routine for the Debit/Credit Indicator characteristic (0FI_DBCRIND) in the target
system, which assigns the value D for debit postings and the value C for credit postings.

1. You are in the transformation maintenance transaction. To display the rule details, double-click
the Debit/Credit Indicator (0FI_DBCRIND) InfoObject in the rule group.
2. Choose Add Source Fields to add the fields Total Debit Postings (UMSOL) and Total Credit
Postings (UMHAB), so that these are available in your routine.
3. You choose Routine as the rule type. The routine editor opens.
4. You insert the following lines of coding, which return either a D or a C as the result value:

*$*$ begin of routine - insert your code only below this line *-*

Potrebbero piacerti anche