Monday, November 9, 2009

End Routine Parameters

End Routine Parameters
Importing

● REQUEST: Request ID

● DATAPAKID: Number of current data package
Exporting

● MONITOR: Table for user-defined monitoring. This table is filled using row structure MONITOR_REC (the record number of the processed record is inserted automatically from the framework).
Changing

● RESULT_PACKAGE: Contains all data that has been processed by the transformation.
Raising

● CX_RSROUT_ABORT: If a raise exception type cx rsrout_abort is triggered in the routine, the system terminates the entire loading process. The request is highlighted in the extraction monitor as Terminated. The system stops processing the current data package. This can be useful with serious errors.



By default, only fields that have a rule in the transformation are transferred from the end routine. Choose Change Update Behavior of End Routine to set the All Target Fields (Independent of Active Rules) indicator. As a result, fields that are only filled in the end routine are updated and are not lost. This function is only available for standard DataStore objects, DataStore objects for direct writing, and for master data tables.





If only the key fields are updated for master data attributes, all the attributes are initialized anyway, whatever the settings described here. For more information, see SAP Note 1096307.

Routine Parameters for Key Figures or Characteristics

Routine Parameters for Key Figures or Characteristics
Importing

● REQUEST: Request ID

● DATAPAKID: Number of current data package

● SOURCE_FIELDS: Structure with the routine source fields defined on the UI
Exporting

● MONITOR: Table for user-defined monitoring. This table is filled using row structure MONITOR_REC (the record number of the processed record is inserted automatically from the framework).

● RESULT: You have to assign the result of the computed key figure or computed characteristic to the RESULT variables.

● CURRENCY (optional): If the routine has a currency, you have to assign the currency here.

● UNIT (optional): If the routine has a unit, you have to assign the unit here.
Raising

Exception handling using exception classes is used to control what is written to the target:

● CX_RSROUT_SKIP_RECORD: If a raise exception type cx_rsrout_skip_record is triggered in the routine, the system stops processing the current row and continues with the next data record.

● CX_RSROUT_SKIP_VAL: If an exception type cx_rsrout_skip_val is triggered in the routine, the target field is deleted.

● CX_RSROUT_ABORT: If a raise exception type cx rsrout_abort is triggered in the routine, the system terminates the entire load process. The request is highlighted in the extraction monitor as Terminated. The system stops processing the current data package. This can be useful with serious errors.

End Routine

Example: End Routine

In the SAP ERP system, you are loading data using the General Ledger: Transaction Figures DataSource (0FI_GL_1) into the DataStore object FIGL: Transaction Figures (0FIGL_O06).

You want to create an end routine to fill the additional InfoObject Plan/Actual Indicator (ZPLACTUAL). You also want the routine to read field Value Type. If the value is 10 (actual), value A is written to the Plan/Actual Indicator InfoObject; if the value is 20 (plan), value P is written to the Plan/Actual Indicator InfoObject.

...

1. You are in transformation maintenance. Choose Create End Routine. The routine editor opens.

2. You enter the following lines of code:



*----------------------------------------------------------------------*
METHOD end_routine.
*=== Segments ===

FIELD-SYMBOLS:
TYPE _ty_s_TG_1.

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

loop at RESULT_PACKAGE assigning
where vtype eq '010' or vtype eq '020'.
case -vtype.
when '010'.
-/bic/zplactual = 'A'. "Actual
when '020'.
-/bic/zplactual = 'P'. "Plan
endcase.
endloop.
*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD. "end_routine
*----------------------------------------------------------------------*


The code loops through result_package searching for values that have the value type 10 or 20. For these values, the appropriate value is passed on to InfoObject Plan/Actual Indicator (ZPLACTUAL).

3. You exit the routine editor.

4. You save the transformation. An edit icon next to the End Routine indicates that an end routine is available.

Characteristic Routine

Example: Characteristic Routine

In the SAP ERP system, you are loading data using the General Ledger: Transaction Figures DataSource (0FI_GL_1) into the DataStore object FIGL: Transaction Figures(0FIGL_O06).

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

1. You are in transformation maintenance. In the rule group, you double click on InfoObject Debit/Credit Indicator (0FI_DBCRIND). The rule details screen appears.

2. You choose Add Source Fields and add the Total Debit Postings (UMSOL) and Total Credit Postings (UMHAB) fields so that they are available in the routine.

3. You choose Routine as the rule type. The routine editor opens.

4. You enter the following lines of code. They return either D or a C as the result value:



*---------------------------------------------------------------------*

METHOD compute_0FI_DBCRIND.

DATA:
MONITOR_REC TYPE rsmonitor.

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

* result value of the routine
if SOURCE_FIELDS-umhab ne 0 and SOURCE_FIELDS-umsol eq 0.

RESULT = 'D'.

elseif SOURCE_FIELDS-umhab eq 0 and SOURCE_FIELDS-umsol ne 0.

RESULT = 'C'.

else.

monitor_rec-msgid = 'ZMESSAGE'.

monitor_rec-msgty = 'E'.

monitor_rec-msgno = '001'.

monitor_rec-msgv1 = 'ERROR, D/C Indicator'.

monitor_rec-msgv2 = SOURCE_FIELDS-umhab.

monitor_rec-msgv3 = SOURCE_FIELDS-umsol.

append monitor_rec to monitor.

RAISE EXCEPTION TYPE CX_RSROUT_ABORT.

endif.

*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD. "compute_0FI_DBCRIND
*---------------------------------------------------------------------*

The system checks if the debit and credit postings contain values:

○ If the debit posting has values that are not equal to zero and the credit posting is equal to zero, the system assigns the value D.

○ If the credit posting has values that are not equal to zero and the debit posting is equal to zero, the system assigns the value C.

○ If both the debit and credit postings contain values, the system outputs an error in the monitor and terminates the loading process.

5. You exit the routine editor.

6. In the Rule Details dialog box, you choose Transfer Values.

7. You save the transformation.

http://help.sap.com/saphelp_nw2004s/helpdata/en/43/c3963dfbde4dede10000000a422035/frameset.htm

Start Routine Parameters

Importing

● REQUEST: Request ID

● DATAPAKID: Number of current data package
Exporting

● MONITOR: Table for user-defined monitoring. This table is filled by means of row structure MONITOR_REC (the record number of the processed record is inserted automatically from the framework).
Changing

● SOURCE_PACKAGE: Structure that contains the inbound fields of the routine.
Raising

● CX_RSROUT_ABORT: If a raise exception type cx rsrout_abort is triggered in the routine, the system terminates the entire load process. The request is highlighted in the extraction monitor as having been terminated. The system stops processing the current data package. This can be useful with serious errors.

Start Routine

Example: Start Routine

In the SAP ERP system, you are loading data using the General Ledger: Transaction Figures DataSource (FI_GL_1) into the DataStore object FIGL: Transaction Figures (0FIGL_O06).

You want to create a start routine that deletes all the records from a data package that have debit and credit postings that are equal to zero.

...

1. Create a transformation. The source of the transformation has the Total Debit Postings (UMSOL) and Total Credit Postings (UMHAB) fields. They are assigned to the InfoObjects Total Debit Postings (0DEBIT) and Total Credit Postings (0CREDIT).

2. Choose Create Start Routine. The routine editor opens.

3. You go to the local part of the routine. You enter the following lines of code:



*----------------------------------------------------------------------*
METHOD start_routine.
*=== Segments ===

FIELD-SYMBOLS:
TYPE _ty_s_SC_1.

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

DELETE SOURCE_PACKAGE where UMHAB = 0 and UMSOL = 0

*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD. "start_routine
*----------------------------------------------------------------------*


The delete statement is the only line you require in order to filter debit and credit postings without values out of the data package.

4. You exit the routine editor.

5. You save the transformation. An edit icon next to the Start Routine indicates that a start routine is available.

http://help.sap.com/saphelp_nw2004s/helpdata/en/43/c3963dfbde4dede10000000a422035/frameset.htm

Routines in Transformations

You can use routines to define complex transformation rules.

Routines are local ABAP classes that consist of a predefined definition area and an implementation area. The TYPES for the inbound and outbound parameters and the signature of the routine (ABAP method) are stored in the definition area. The actual routine is created in the implementation area. ABAP object statements are available in the coding of the routine. Upon generation, the coding is embedded in the local class of the transformation program as the method.

The routine has a global part and a local part. In the global part you define global data declarations 'CLASS DATA'. These are available in all routines.

You can create function modules, methods or external subprograms in the ABAP Workbench if you want to reuse source code in routines. You can call these in the local part of the routine. If you want to transport a routine that includes calls of this type, the routine and the object called should be included in the same transport request.

Transformations include different types of routine:
Start routines
Routines for Key Figures or Characteristics
End routines and
Expert routine.