Using Start Routine, End Routine and Expert Routine

Objective

After completing this lesson, you will be able to use start routine, end routine and expert routine

Start Routine, End Routine and Expert Routine

Routines

You can use routines to define complex transformation rules. Depending on the selected runtime (ABAP runtime or HANA runtime), you can use ABAP Routines or SAP HANA SQLScript Routines in a Transformation.

ABAP Routines

ABAP 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 routines.

SAP HANA SQLScript Routines

In SAP HANA Runtime, you can create SAP HANA SQL Script routines. They are then created as a SAP HANA procedure that is implemented as a method in an AMDP (ABAP managed database procedure) class. The AMDP class is generated by the BW framework and can only be edited in the ABAP Development tools for SAP NetWeaver (ADT). This function is intended for experts only. You need to be registered as a developer, in order to use this function.

Start Routine

The start routine is run for each data package at the start of the transformation. The start routine has a table in the format of the source structure as input and output parameters. It is used to perform preliminary calculations and store these in a global data structure or in a table. This structure or table can be accessed from other routines. You can modify or delete data in the data package.

The following list shows the 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 the 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 is useful for serious errors.

End Routine

An end routine is a routine with a table in the target structure format as an inbound parameter, and an outbound parameter. You can use an end routine to post-process data, package-by-package, after transformation. For example, you can delete records that are not to be updated, or perform data checks.

Note

If the target of the transformation is a Standard DataStore Object, Key Figures are updated by default with the Overwrite (MOVE) aggregation behavior. You have to use a dummy rule to override this.

For example, you load data from an SAP source system 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.

In transformation maintenance, choose Create End Routine. In the routine editor, enter the following lines of code:

Code Snippet
12345678910111213141516171819202122
*----------------------------------------------------------------------*  METHOD end_routine. *=== Segments === FIELD-SYMBOLS: <RESULT_FIELDS> TYPE _ty_s_TG_1. *$*$ begin of routine - insert your code only below this line *-* 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 *-*   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).

Once the code is entered, you can exit the editor and save the transformation. An edit icon next to the End Routine indicates that an end routine is available.

The following list shows the 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 the 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 if serious errors occur.

Note

In the default setting, 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. Fields that are only filled in the end routine are then updated, and not lost. This function is only available for Standard DataStore Objects, Direct Update DataStore Objects and for master data tables. If only the key fields are updated for master data attributes, all the attributes are initialized, regardless of the settings described here. For more information, see SAP Note 1096307.

Expert Routine

An expert routine is intended for use in special scenarios. You can use the expert routine if the other transformation functions are not sufficient. You can use the expert routine as an interim solution until the necessary functions are available in the standard routine. You can use this to program the transformation yourself without using the existing rule types. You must transfer the messages to the monitor yourself. If you have already created transformation rules, the system deletes them once you have created an expert routine. Navigation attributes of the source of the transformation are not available in the expert routine.

Note

If the target of the transformation is a Standard DataStore Object, Key Figures are updated by default with the Overwrite (MOVE) aggregation behavior.

Log in to track your progress & complete quizzes