Professional Documents
Culture Documents
Applies to:
SAP BW 7.0. For more information, visit the Business Intelligence homepage.
Summary
The standard alerting system for process chains can only send alerts in case a process chain has failed. It is not possible to create notifications when a process chain is running too long or is not started at all. Here we discuss a simple automated monitoring approach that can avoid these restrictions without additional tools outside the BW system. Author: Ralf Rastert
Author Bio
Ralf Rastert is an SAP support consultant for BW. He is working for SAP since 2003.
Table of Contents
Introduction ......................................................................................................................................................... 3 Design ................................................................................................................................................................. 3 Preliminary considerations .............................................................................................................................. 3 High level Implementation ............................................................................................................................... 3
Customizing table ........................................................................................................................................................ 3 Background program ................................................................................................................................................... 4
Example Realization ........................................................................................................................................... 5 Necessary Tables ........................................................................................................................................... 5 ABAP Coding .................................................................................................................................................. 6 Related Content ................................................................................................................................................ 13 Disclaimer and Liability Notice ........................................................................... Error! Bookmark not defined.
Introduction
One of the most important tasks for BW monitoring and administration teams is to ensure that data is loaded successfully and in time from the connected source systems. Usually the loads are scheduled within a process chain so this requirement boils down to monitoring the chains and to ensure that they finish within the required time. The process chain framework already offers some tools for this purpose, so it is possible to create an alert in case a chain encounters an error or to send an email if a process has been completed successfully. However, there is no standard functionality available within a BW system for creating an alert if a process chain runs longer than expected or if it is started too late. SAP Solution Manager offers this functionality with its Business Process Monitoring toolset. Sometimes it is however not possible or not wanted to use the Solution Manager, but a simple monitoring is still desirable. In this case the following ideas can help.
Design
Preliminary considerations Before implementing the monitoring we first want to define the requirements it should meet. For my purposes three things were important: Easy to maintain Easy to implement No dependencies to other systems
With these requirements we can now define the technical details Use a customizing table to define the process chains to be monitored Monitor the chains with a Z-program scheduled as background process
High level Implementation Customizing table We first define a customizing table where we can maintain the chains to be monitored
CHAIN_ID technical name of the process chain to be monitored SCHEDULING definition of the expected scheduling MAX_DELAY maximum delay of a process chain start compared with the time defined in SCHEDULING
MAX_RUNTIME maximum runtime of the chain, starting from the time define in SCHEDULING MAIL comma separated list of mail recipients The tricky part here is SCHEDULING as we need a simple format but we still must be able to define rather complex scheduling schemes. Fortunately other people already thought about this problem and a common and well known format is e.g. the one used in crontab. We will use here a simplified version of it. SCHEDULING consists out of 5 space separated fields: field minute hour day of month month day of week allowed values 0-59 0-23 1-31 1-12 1-7 (1 for Monday)
Each field can be filled either with a comma separated list of values or with * for all possible values. Other options known in crontab, like ranges, are not possible. So what would the following entry mean?
The process chain 0TCT_MD_S_FULL_P01 must run every Sunday at 11:10h and at 21:10h. The start delay must be smaller than 10 minutes, i.e. it must start before 11:20h and before 21:20h. The maximum runtime is 60 minutes, i.e. it must end before 12:10h and 22:10h. If the chain fails or if one of the above conditions is not fulfilled emails are send to d.duck@sap.com and to m.mouse@sap.com. Background program The background program is scheduled regularly, e.g. every 15 minutes. During each run it is checking the status and runtime of the chains and is sending an email if a problem was detected. In pseudocode the program has to perform these steps:
LOOP over all chains in customizing table. decode SCHEDULING to last expected start time. IF start time is within last 2 days. read process chain status with function module RSPC_API_CHAIN_GET_RUNS. IF no log found for the specified start interval. send alert delayed start. ELSE. CASE status EQUALS red. send alert process chain failed. CASE status EQUALS green, get end time of chain with function module RSPC_RUNTIME_ANALYSIS. IF end time GREATER THAN maximum runtime. send alert slow execution. ENDIF. CASE status EQUALS yellow.
IF current time GREATER THAN maximum runtime. send alert slow execution. ENDIF. ENDIF. ENDIF. ENDLOOP.
Example Realization
We show here an example realization of the discussed algorithm. For simplicity we did not implement complex error handling or input value validation. The program also has some known issues, like sending alerts twice in case a process chain is started with a delay. Monitoring chains which are running longer than 2 days is also not possible and if the chain is scheduled more often than the program, not all problems are recognized. There is also some useful functionality missing, e.g. there is no history of alerts in the system. To put it short, before implementing the program in a productive environment some adjustments are recommended. Nevertheless, it is working and it should be rather easy to polish it up. Necessary Tables We have to define 2 customer tables in the system, the customizing table zrr_pc_monitor and the ZRR_PC_MONI_ERR table where the old alerts are stored. The definition of these tables is:
and
ABAP Coding The algorithm is implemented in the report ZRR_PC_MONI. It uses some BW 7.0 specific functions so the report does not work in BW 3.x.
*&---------------------------------------------------------------------* *& Report ZRR_PC_MONI *& *&---------------------------------------------------------------------* *& *& Monitor process chains *&---------------------------------------------------------------------*
REPORT ZRR_PC_MONI. DATA: wa_z_pc_monitor type zrr_pc_monitor, it_z_pc_monitor type table of zrr_pc_monitor, wa_z_pc_moni_err type zrr_pc_moni_err. select * from zrr_pc_monitor into table it_z_pc_monitor. loop at it_z_pc_monitor into wa_z_pc_monitor. clear wa_z_pc_moni_err. perform check_chain using wa_z_pc_monitor changing wa_z_pc_moni_err. if wa_z_pc_moni_err-status eq 'R' or wa_z_pc_moni_err-status eq 'D' or wa_z_pc_moni_err-status eq 'E'. select single log_id from ZRR_PC_MONI_ERR into wa_z_pc_moni_err-log_id where CHAIN_ID = wa_z_pc_moni_err-chain_id and LOG_ID = wa_z_pc_moni_err-log_id. if sy-subrc ne 0. " there has been no alert for this log_id perform send_mail using wa_z_pc_moni_err wa_z_pc_monitor-mail. modify zrr_pc_moni_err from wa_z_pc_moni_err. commit work. endif. endif. endloop.
" send the email in case of error *&---------------------------------------------------------------------* *& Form send_mail *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->STATUS text * -->MAIL text *----------------------------------------------------------------------*
FORM send_mail USING status TYPE zrr_pc_moni_err mail like zrr_pc_monitor-mail. DATA: OBJCONT LIKE SOLISTI1 OCCURS 5 WITH HEADER LINE. DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE. DATA: DOC_CHNG LIKE SODOCCHGI1. DATA: ENTRIES LIKE SY-TABIX. DATA: NAME(15). DATA: it_mail type table of string.
DOC_CHNG-OBJ_NAME = 'PC Monitor'. if status-status eq 'R'. concatenate sy-sysid ': Chain failed' into DOC_CHNG-OBJ_DESCR. else. concatenate sy-sysid ': Chain delayed' into DOC_CHNG-OBJ_DESCR. endif. DOC_CHNG-SENSITIVTY = 'O'. concatenate 'Chain: ' status-CHAIN_ID ' Logid: ' status-LOG_ID ' Status: ' status-status into OBJCONT. APPEND OBJCONT. DESCRIBE TABLE OBJCONT LINES ENTRIES. READ TABLE OBJCONT INDEX ENTRIES. DOC_CHNG-DOC_SIZE = ( ENTRIES - 1 ) * 255 + STRLEN( OBJCONT ).
ENDCASE. ENDFORM.
"send_mail
* check one chain " possible status values: " G => ok " U => undefined " R => chain red " D => chain start delayed " E => chain end delayed (chain is green or yellow) " A => chain in status yellow, but within time limit *&---------------------------------------------------------------------* *& Form check_chain *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->PC_ID text * -->STATUS text *----------------------------------------------------------------------*
FORM check_chain USING pc_id TYPE zrr_pc_monitor CHANGING status TYPE zrr_pc_moni_err. DATA: ldatum TYPE SYDATUM, end_ts type timestamp, timestamp_delta type integer, runtime_ts type timestamp, current_ts type timestamp, plan_timestamp TYPE timestamp, time_stamp TYPE timestamp, wa_lt_logs type RSPC_S_LOG_F4, wa_lt_runtime type RSPC_S_RUNTIME, rows type integer, lt_logs type table of RSPC_S_LOG_F4, lt_runtime type table of RSPC_S_RUNTIME. status-status = 'G'. perform calculate_start_time using pc_id-scheduling changing plan_timestamp. if plan_timestamp ne 0. " there was a scheduled run so we return 'G' CONVERT TIME STAMP plan_timestamp TIME ZONE sy-zonlo INTO DATE ldatum. timestamp_delta = 60 * pc_id-max_delay. end_ts = CL_ABAP_TSTMP=>ADD( TSTMP = plan_timestamp SECS = timestamp_delta ). timestamp_delta = 60 * pc_id-max_runtime. runtime_ts = CL_ABAP_TSTMP=>ADD( TSTMP = plan_timestamp SECS = timestamp_delta ).
DESCRIBE TABLE lt_logs lines rows. IF rows > 0. sort lt_logs descending by datum zeit. loop at lt_logs into wa_lt_logs. CONVERT DATE wa_lt_logs-datum TIME wa_lt_logs-zeit INTO TIME STAMP time_stamp TIME ZONE sy-zonlo. if time_stamp le end_ts and time_stamp ge plan_timestamp.
" we change status 'X' to 'R' as we are not interested in details here
status-status = 'R'. endif. exit. endif. endloop. if status-status eq 'U' and current_ts gt end_ts.
"nothing found in time range, i.e. use the last available log
READ TABLE lt_logs INDEX 1 INTO wa_lt_logs. status-log_id = wa_lt_logs-log_id. status-status = 'D'. endif. else. if current_ts gt end_ts. status-status = 'D'. endif. ENDIF. endif. status-chain_id = pc_id-chain_id. ENDFORM. "check_chain
"rows > 0
loop at it_minute into minute_it. if hour_it lt current_hour or minute_it le current_minute. if result-hour lt hour_it or ( result-hour eq hour_it and result-minute le minute_it ). result-year = sy-datum(4). result-month = cmonth_it. result-day = mday_it. result-hour = hour_it. result-minute = minute_it. endif. endif. endloop. endloop. endloop. endloop. endloop. if result-day eq 0. " try yesterday date = sy-datum - 1. mday = date+6(2). cmonth = date+4(2). call function 'DATE_COMPUTE_DAY' EXPORTING date = date IMPORTING day = day. loop at it_day_of_week into day_it where table line eq day. loop at it_day_of_month into mday_it where table line eq mday. loop at it_month into cmonth_it where table line eq cmonth. result-year = date(4). result-month = cmonth_it. result-day = mday_it. result-hour = -1. result-minute = 0. loop at it_hour into hour_it. " find latest valid time for yesterday if result-hour lt hour_it. result-hour = hour_it. endif. endloop. loop at it_minute into minute_it. if result-minute lt minute_it. result-minute = minute_it. endif. endloop. endloop. endloop. endloop. endif. if result-day ne 0. " a PC was scheduled time = 3600 * result-hour + 60 * result-minute. date+6(2) = result-day. date+4(2) = result-month. date(4) = result-year. CONVERT DATE date TIME time INTO TIME STAMP plan_timestamp TIME ZONE sy-zonlo. else. plan_timestamp = 0. endif.
ENDFORM.
"calculate_start_time
*&---------------------------------------------------------------------* *& Form split_time *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->VALUE(I_START) text * -->VALUE(I_END) text * -->S_TIME text * -->IT_RESULT text *----------------------------------------------------------------------*
FORM split_time USING value(i_start) type integer value(i_end) type integer s_time type string CHANGING it_result type table. DATA: counter type integer. if s_time eq '*'. counter = i_start. while counter le i_end. append counter to it_result. counter = counter + 1. endwhile. else. split s_time at ',' into: table it_result. endif. ENDFORM. "split_time
Related Content
https://www.sdn.sap.com/irj/sdn/nw-processmonitoring https://www.sdn.sap.com/irj/sdn/monitoring https://wiki.sdn.sap.com/wiki/display/BI/Process+chains+creation+and+monitoring For more information, visit the Business Intelligence homepage
Copyright
Copyright 2009 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.