Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Update Rules
Applies To:
SAP BW 3.5, Package Level 15 (SAPKW35015).
Summary
Performance Optimization in BW Update Rules.
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.
Global Declarations
*$*$ begin of global - insert your declaration only below this line *-*
* Begin of global declarations
TABLES: /BI0/PBPARTNER,/BI0/PUCCONTRACT.
* 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.
* 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 global - insert your declaration only before this line *-*
*$*$ begin of routine - insert your code only below this line *-*
* fill the internal tables "MONITOR" and/or "MONITOR_RECNO",
* to make monitor entries
*
* 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
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.
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
ENDIF.
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).
* 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.
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.
* 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.
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.
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.