Está en la página 1de 5

Performance Optimization in BW

Update Rules

Applies To:
SAP BW 3.5, Package Level 15 (SAPKW35015).

Summary
Performance Optimization in BW Update Rules.

By: Vishvesh Bahirat

Company: Wipro Technologies

Date: 21 March 2006

Optimizing Start Routines


In BW, often the characteristics or key figures that are required in the reports are not directly available from
the source system’s transaction data source. The characteristics might be dependent on values in master
data or on characteristic or key figure values held in other data targets. So the need arises to write ABAP
update routines, to calculate and assign the values according to a determined logic.

We can directly write a SELECT statement in the update routine, to retrieve data from the master data table
or a data target table. But this will cause a SELECT to be run for each record of the data package. Thus for
100,000 records in the data package there will be 100,000 selects on the database table. This will severely
hamper the performance.

A good way to optimize this is to fill the required data from the database tables, into internal tables, using the
start routine of the update rules. These internal tables can then ‘read’ in the update routines. Only one select
on the database table will run for each data package, and all data retrieval in the routines will occur on the
internal table, saving precious system resources.

Sample code is shown below. Please see comments in code for additional information.

Sample Code for Start Routine

Global Declarations

*$*$ begin of global - insert your declaration only below this line *-*
* Begin of global declarations

* Declare the database tables used.


* Below examples are business partner and contract tables.

© 2006 SAP AG The SAP Developer Network: http://sdn.sap.com


1
Performance Optimization in BW
Update Rules

TABLES: /BI0/PBPARTNER,/BI0/PUCCONTRACT.

* Declare structure of internal table.


* Below example is for business partner number and business partner type.
TYPES: BEGIN OF TY_BP_TYPE,
BPARTNER LIKE /BI0/PBPARTNER-BPARTNER,
BP_TYPE LIKE /BI0/PBPARTNER-BP_TYPE,
END OF TY_BP_TYPE.

* Declaring internal table like structure and work-area like line of the
* internal table.
* We should avoid declaring internal table with header line or with OCCURS 0.
DATA: GIT_BP_TYPE TYPE STANDARD TABLE OF TY_BP_TYPE,
WA_GIT_BP_TYPE LIKE LINE OF GIT_BP_TYPE.

* Declare structure of internal table.


* Below example is for contract number, its move out date and last-billed date.
TYPES: BEGIN OF TY_MO_DATE,
UCCONTRACT LIKE /BI0/PUCCONTRACT-UCCONTRACT,
UCMOVEOUTD LIKE /BI0/PUCCONTRACT-UCMOVEOUTD,
/BIC/ZTCLSTBIL LIKE /BI0/PUCCONTRACT-/BIC/ZTCLSTBIL,
END OF TY_MO_DATE.

* Declaring internal table like structure and work-area like line of the
* internal table.
* We should avoid declaring internal table with header line or with OCCURS 0.
DATA: GIT_MO_DATE TYPE STANDARD TABLE OF TY_MO_DATE,
WA_GIT_MO_DATE LIKE LINE OF GIT_MO_DATE.

* End of the global declarations section

*$*$ end of global - insert your declaration only before this line *-*

Actual Start Routine Code

*$*$ begin of routine - insert your code only below this line *-*
* fill the internal tables "MONITOR" and/or "MONITOR_RECNO",
* to make monitor entries
*

**** Start of Routine ****

* We do not need to get all master data records from the database table.
* Get only the required records. For example in below code block we are checking
* if data package has any business partners at all. If present then we set a flag.
* We then retrieve the partner number and its type (if flag got set), for only those
* business partners available in the data package records. This is accomplished by using
© 2006 SAP AG The SAP Developer Network: http://sdn.sap.com
2
Performance Optimization in BW
Update Rules

* ‘FOR ALL ENTRIES’ statement.

* Declare flag for data package check and a constant 'X'.


DATA: LV_FLAG TYPE FLAG.
CONSTANTS: LC_X(1) TYPE C VALUE 'X'.

* Check if data package has any business partners filled in.


* Only then fill the internal table with records.

LOOP AT DATA_PACKAGE WHERE BPARTNER IS NOT INITIAL.


LV_FLAG = LC_X.
EXIT. "exit the loop
ENDLOOP.

IF LV_FLAG = LC_X.

* Fill the internal table with records from Business Partner MD table.
SELECT BPARTNER BP_TYPE
FROM /BI0/PBPARTNER
INTO TABLE GIT_BP_TYPE
FOR ALL ENTRIES IN DATA_PACKAGE
WHERE BPARTNER = DATA_PACKAGE-BPARTNER.

ENDIF.

* It is important to clear the flag at this step because it will be reused by further
* code.

CLEAR LV_FLAG. "clear the flag used.

* Similar code and explanation as above for contract master data.

* Check if data package has any contract numbers filled in.


* Only then fill the internal table with records.

LOOP AT DATA_PACKAGE WHERE UCCONTRACT IS NOT INITIAL.


LV_FLAG = LC_X.
EXIT. "exit the loop
ENDLOOP.

IF LV_FLAG = LC_X.

* Fill the internal table with records from Contract Number MD table.
SELECT UCCONTRACT UCMOVEOUTD /BIC/ZTCLSTBIL
FROM /BI0/PUCCONTRACT
INTO TABLE GIT_MO_DATE
FOR ALL ENTRIES IN DATA_PACKAGE
© 2006 SAP AG The SAP Developer Network: http://sdn.sap.com
3
Performance Optimization in BW
Update Rules

WHERE UCCONTRACT = DATA_PACKAGE-UCCONTRACT.

ENDIF.

CLEAR LV_FLAG. "clear the flag used.

* It is important to sort the internal tables by the key fields.


* Because the routines read the tables by using a binary search.
* Binary search can run successfully only when table is sorted by all key fields.
SORT GIT_BP_TYPE BY BPARTNER.
SORT GIT_MO_DATE BY UCCONTRACT.

Sample Code for Update Routine

Update Routine to determine the account status. Account Status depends on whether move out date is
populated for a contract, in master data for Contract Number (0UCCONTRACT).

**** Start of Routine ****


* Author : Vishvesh Bahirat
* Description : To derive the account status.

* Read the i.table into work-area,for key value uccontract from the comm
* structure.
* The internal table should be read using a binary search to optimize performance
READ TABLE GIT_MO_DATE INTO WA_GIT_MO_DATE
WITH KEY UCCONTRACT = COMM_STRUCTURE-UCCONTRACT BINARY SEARCH.

* check whether ucmoveoutd field holds a value.


* if yes,the result is 'F' else the result is 'L'.

IF SY-SUBRC EQ 0.
IF NOT WA_GIT_MO_DATE-UCCONTRACT IS INITIAL.
IF NOT WA_GIT_MO_DATE-UCMOVEOUTD IS INITIAL.
RESULT = 'F'.
ELSE.
RESULT = 'L'.
ENDIF.
ENDIF.
ENDIF.

CLEAR WA_GIT_MO_DATE. "clear the work area

* if the returncode is not equal zero, the result will not be updated
RETURNCODE = 0.
* if abort is not equal zero, the update process will be canceled
© 2006 SAP AG The SAP Developer Network: http://sdn.sap.com
4
Performance Optimization in BW
Update Rules

ABORT = 0.

**** End of Routine ****

Author Bio

Vishvesh Bahirat has been working as a SAP-BW Consultant in Wipro Technologies since more
than 2 years. He has experience of working on both implementation and support projects.

Disclaimer & Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces
and therefore is not supported by SAP. Changes made based on this information are not supported and can
be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content
within this document and the materials and services offered by SAP. You agree that you will not hold, or seek
to hold, SAP responsible or liable with respect to the content of this document.

© 2006 SAP AG The SAP Developer Network: http://sdn.sap.com


5

También podría gustarte