Powered By

Free XML Skins for Blogger

Powered by Blogger

Showing posts with label BI Creating Routines. Show all posts
Showing posts with label BI Creating Routines. Show all posts

Wednesday, July 9, 2008

BW BI Transformation Creating Routines

Prerequisites

If you previously worked with the ABAP form routines of the update rules and transfer rules, you have to familiarize yourself with the differences in working with routines in the transformation.

See Differences in Routine Concepts.

Procedure

You are in the routine editor. To create a routine, enter the following:

...

1. Between *$*$ begin of global ... and *$*$ end of global ... you can define the global data declarations 'CLASS DATA'. These are available in all routines. Data declarations with ‘DATA’ can only be accessed in the current package.

This means that you can use intermediate results in other routines, for example, or reuse results when you call a routine again at a later time.

Note

When you perform serial loads, one process instance is used for the entire request. In this case, data with the ‘CLASS DATA’ data declaration can be accessed for the entire request (all packages).

Several process instances are used when you perform parallel loads.

A single process instance can be used a more than once, depending on the number of data packages to be processed and the number of available process instances. This means that with parallel loads, data with the 'CLASS DATA' data declaration is not initialized for each data package and may still contain data from predecessor packages.

For this reason, use 'CLASS DATA' or 'DATA' for the global data, depending on the scenario.

In the routine editor, a maximum of 72 characters per line are currently permitted. Any additional characters are cut off when you save.

2. Enter your program code for the routine between *$*$ begin of routine ... and *$*$ end of routine... . For information about the parameters of the routine, see

○ Start Routine Parameters

○ Routine Parameters for Key Figures or Characteristics

○ End Routine Parameters

Do not use a SAP COMMIT (ABAP statement: COMMIT WORK) in your coding. When this statement is executed, the cursor that is used from the source for reading is lost. Use a DB COMMIT (call function module DB_COMMIT) instead or avoid using such COMMITs altogether.

3. Check the syntax of your routine.

4. Save the routine. You end the maintenance session for the routine by leaving the editor.

More Information:

Example: Start Routine

Example: Characteristic Routines

Example: End Routine

Example: Start Routine BW BI Transformation Creating Routines

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:

This graphic is explained in the accompanying text

*----------------------------------------------------------------------*
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.

Example: Characteristic Routine BW BI Transformation Creating Routines

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 This graphic is explained in the accompanying text 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:

This graphic is explained in the accompanying text

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

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.

Example: End Routine BW BI Transformation Creating Routines

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 This graphic is explained in the accompanying text Create End Routine. The routine editor opens.

2. You enter the following lines of code:

This graphic is explained in the accompanying text

*----------------------------------------------------------------------*
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.

Start Routine Parameters BW BI Transformation Creating Routines

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.

Routine Parameters for Key Figures or Characteristics BW BI Transformation Creating Routines

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 Parameters BW BI Transformation Creating Routines

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

Only fields that have a rule in the transformation are transferred from the end routine

Archives