+++> 4. How to Create Routines in BW-BI

How to Create Routines in BW/BI

Business Scenario:

You have been tasked to manipulate the data flowing through your data warehouse. You were asked to do the following:

  1. You need to delete selected records with in the data package that Business doesn’t want.
  2. Populate the field based upon values of the other fields being passed in the load process.

In order to accomplish these tasks it has been determined that you have to invoke the Routines with in BI.

With in the BI SAP Net Weaver 2004s there is a new methodology for manipulating data as it moves through our Business Information Warehouse (BIW) this methodology is called Transformation.


Different Rules available in BI 7

 Constants
 Formula
 Reading Master Data
 Unit Conversion
 Initial Value
Routines
Hierarchy Transformation (Not Yet  Implemented)
Return Table
(Not Yet  Implemented)
Time Update  


In this Paper we will be main focus on how these Routines can be used in the Business Warehouse to meet different needs.


Different Types of Routines Available in BI

                                                     BI 7.0                                        

Start Routine
Routine for Updating Key Figure
Routine for Updating Characteristics
End Routine
Expert Routine


Features :

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

  1. You can create function modules, methods or external subprograms if you want to reuse source code in routines. You can call these in the local part of the routine.

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

  1.   Start routines
  2.   Routines for Key Figures
  3.   Routines for Characteristics
  4.   End Routine
  5.   Expert Routine

The following graphic shows the position of these BI 7.0 routines in the data flow:



1. Start Routine:

The start routine is run for each data package at the start of the transformation. The start routine does not have a return value. It is used to perform preliminary calculations and store these in a global data structure or in a table. You can access this structure or table from other routines. You can modify or delete data.

Example:

  1. Deletion of records that are not required for updating
  2. Buffering table into Internal Table that can be used rather than reading the database table one by one.

Sample Code : Delete records  where info objects contains ZISSQTY <= 0 and COMPL_DEL <> SAPCE.

 


2. Routine for Key Figures or Characteristics:

This routine is available as a rule type; you can define the routine as a transformation rule for a key figure or a characteristic. For more information, see the Routine section under Rule Type.

Example : Creation of Rule Details  for Characteristics.

  1. Go to Particular Transformation of 0MAT_PLANT.

  1. Then Select particular info object  PLANT text which we want to write Rule details ( in BW3.5 we called it as Transfer rules / Update Rules )

 

  1. Include Source fields PLANT which we are using in the Rule Details by using the + symbol button

  1. Select Routine in the Rule Type Drop down list and click Change button / Display Button.

 

  1. Here is the sample code to populate the Plant TEXT from master data text table of 0PLANT

           In BI 7.0 the records will come in structure called SOURCE_PACKAGE and will refer the fields
           as SOURCE_FIELDS-plant.

          
 Were as in BW 3.5 will declare the field as COMM_STRUCTURE-PLANT.



3. 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 execute the post processing of data after transformation on a package-by-package basis. For example, you can delete records that are not to be updated, or perform data checks.

Example:

  1. Deletion of records after the transformation that are not required for updating
    (e.g. after determining material category for a particular material, every material   
    of type ‘Refund’ is not updated.
  1. Validation checks of records after transformation ( e.g. Key figures sales values must be bigger than purchase value)

Sample code:
Deleting the records which are having the 0MATL_TYPE (material Type) equals to ‘ZFIN’ and ‘ZSFG’.


In BW 3.5 End Routine is not available so apply this logic in Start Rouitne.

4. Expert Routine:
This type of routine is only intended for use in special cases. You can use the expert routine if there are not sufficient functions to perform a transformation. You can use the expert routine as an interim solution until the necessary functions are available in the standard routine.
If you have already created transformation rules, the system deletes them once you have created an expert routine.

Example:
  1. Reading several database tables can be implemented faster .
  2. Transpose a large data records into several smaller records can be easily implemented using the Expert Routine.