Wonderware Factelligence
Report Designer
Invensys Systems, Inc.
Revision D
Last Revision: 3/6/08
Copyright
2008 Invensys Systems, Inc. All Rights Reserved.
All rights reserved. No part of this documentation shall be reproduced, stored in a
retrieval system, or transmitted by any means, electronic, mechanical,
photocopying, recording, or otherwise, without the prior written permission of
Invensys Systems, Inc. No copyright or patent liability is assumed with respect to
the use of the information contained herein. Although every precaution has been
taken in the preparation of this documentation, the publisher and the author
assume no responsibility for errors or omissions. Neither is any liability assumed
for damages resulting from the use of the information contained herein.
The information in this documentation is subject to change without notice and does
not represent a commitment on the part of Invensys Systems, Inc. The software
described in this documentation is furnished under a license or nondisclosure
agreement. This software may be used or copied only in accordance with the terms
of these agreements.
Invensys Systems, Inc.
26561 Rancho Parkway South
Lake Forest, CA 92630 U.S.A.
(949) 727-3200
[Link]
For comments or suggestions about the product documentation, send an e-mail
message to productdocs@[Link].
Trademarks
All terms mentioned in this documentation that are known to be trademarks or
service marks have been appropriately capitalized. Invensys Systems, Inc. cannot
attest to the accuracy of this information. Use of a term in this documentation
should not be regarded as affecting the validity of any trademark or service mark.
Alarm Logger, ActiveFactory, ArchestrA, Avantis, DBDump, DBLoad, DT Analyst,
Factelligence, FactoryFocus, FactoryOffice, FactorySuite, FactorySuite A2, InBatch,
InControl, IndustrialRAD, IndustrialSQL Server, InTouch, MaintenanceSuite,
MuniSuite, QI Analyst, SCADAlarm, SCADASuite, SuiteLink, SuiteVoyager,
WindowMaker, WindowViewer, Wonderware, Wonderware Factelligence, and
Wonderware Logger are trademarks of Invensys plc, its subsidiaries and affiliates.
All other brands may be trademarks of their respective owners.
Contents
Chapter 1 Introduction ........................................ 5
Aim .......................................................................................5
Content.................................................................................5
Assumptions ........................................................................5
How to Use this Guide ........................................................5
Reference Material ..............................................................6
Chapter 2 Overview............................................ 7
Chapter 3 Report Design ...................................... 9
Chapter 4 Reporting Mechanism........................... 13
Report Designer.................................................................13
Manager .............................................................................14
Configuration.....................................................................15
Chapter 5 Report Preview .................................. 17
Chapter 6 Report Configuration ........................... 19
Chapter 7 Queries ............................................ 25
Query Parameters .............................................................26
Wonderware Factelligence Report Designer
Contents
Chapter 8 Tutorial Exercise .................................31
Overview ............................................................................32
Specification ......................................................................32
Query and Data Design ....................................................33
Report Design and Data Validation .................................36
The Design Tab...............................................................36
Using the Report Template............................................37
Changing Properties ......................................................39
The ADO Data Object and Data Fields.........................40
Grouping .........................................................................42
Formatting......................................................................44
Adding Groups and Data Display Objects ....................46
Complex Data Display Concepts ...................................47
Creating Virtual Data Fields.........................................49
Summation Objects ........................................................50
Scripting Calculations....................................................52
Charting and Testing Using Manager .............................56
Chart Data and Formatting...........................................56
Configuring the Report for Manager.............................60
Scripting Data to a Chart Using Global Arrays ...........62
Adding a Table of Contents ...........................................64
Chapter 9 Scripting and Charts .............................67
General ..............................................................................67
Adding Script.....................................................................68
Simple Report with Chart.................................................68
Virtual Fields..................................................................69
Calculated Fields............................................................70
Formatting Fields...........................................................71
Simple Charting .............................................................71
Displaying the Date .......................................................74
Displaying the Filter Information and Custom
Parameters .................................................................74
Report with Complex Graph.............................................75
Saving Data to Global Variables ...................................76
Applying Global Data to the Chart ...............................77
Previewing Reports with Charts ......................................78
Appendix A Report Spec Sheet...............................79
Wonderware Factelligence Report Designer
Chapter 1
Introduction
Welcome to Factelligence Report Designer.
Aim
This guide will teach you the basics involved in the creation
and configuration of custom reports to run in the
Factelligence MES system, specifically in the Manager
browser reporting and analysis module.
Content
It will cover the reporting mechanism and features of the
Report Designer.
A number of tutorial exercises will help familiarize you with
the functionality and provide the necessary skills to create
powerful custom reports.
Assumptions
The material in this course assumes that you know very little
about Factelligence Report Designer and have not used the
product before, but that you are familiar with the Microsoft
Windows operating system and database concepts.
How to Use this Guide
You can use this guide as a self-paced training tool.
Wonderware Factelligence Report Designer
Chapter 1 Introduction
It is also a facilitation tool for your Factelligence instructor.
The Tutorial Exercise is the same exercise used in the
training course. All topics covered in the training course are
in the guide.
Reference Material
You are encouraged to review the documentation and/or
attend the training course on Factelligence Manager.
Wonderware Factelligence Report Designer
Chapter 2
Overview
Reports are designed using Factelligence Report Designer
and typically viewed using Factelligence Manager, although
reports can also be viewed using Factelligence Operator.
Over 75 pre-configured System reports have been provided
with Factelligence in an attempt to cover most initial
reporting requirements and to provide a base from which to
build many more custom reports.
These reports are built on proven SQL queries designed to
provide comprehensive data in the following areas:
Production & Rejects
Consumption & Waste
Downtime & Utilization
Labor Usage
Traceability
Genealogy
Certification
Specifications
Performance & OEE
Cost
Data Log
Inventory
Yield & Quality
Audit Trail
Lean Manufacturing
Wonderware Factelligence Report Designer
Chapter 2 Overview
The user has many options when creating custom reports for
their specific Factelligence application. These include:
1
Modifying an existing System report
Creating a new report based on an existing system report
Creating a new report based on an existing system query
4 Creating a new report from scratch
The next four sections will introduce you to the features of
the Report Designer. The Tutorial Exercise will then take
you through all the steps required to create a report.
Wonderware Factelligence Report Designer
Chapter 4
Report Design
The Design tab of the Report Designer contains the
designer control and allows you to create and edit report
layouts.
Figure 1 - Design Tab
Wonderware Factelligence Report Designer
10
Chapter 4 Report Design
The Designer has the following features:
Menu: (top left) for basic file and designer operations.
Design Toolbars: (top) for use in the report design and
formatting. Note in particular the View Script icon
which we will use later.
Object Toolbar: (far left side) used for placing all
required graphical objects on the form canvas.
Explorer Window: (left side - top) displays the groups
and objects currently on the report canvas.
Fields Window: (left side - bottom) displays all fields
available from the database as a result of the query used
by the report.
Property Toolbox: used to set the properties of the
report objects. If the toolbox is hidden then right click in
blank section to the right of the Designer Toolbars and
select Property Toolbox to open it.
Clear Button: will clear the currently loaded report file
and present the user with a blank sheet. This should be
invoked before loading a new report for editing. If not
then the application may crash due to a bug in the
designer control which is yet to be sorted by the software
supplier.
Exercise 1 - The Design Tab
Aim: To open a report and examine its features.
Method:
1
Launch Report Designer. If the application is licensed
then you will be prompted with a login dialog requiring
your user name and / or password.
If login is successful then the application will open to the
Design tab. Note that you must have the required
privilege to run the Report Designer.
From the menu select File -> Open and select the report
layout file
Factelligence\Manager\Reports\System\Production\P
[Link]. The designer will appear as in
Figure 1 above.
Note that the report consists of a series of sections
containing graphic objects for the display of data and
visual formatting.
If you are familiar with Visual Basic and other visual
programming languages you will note that the sections
and objects exhibit a number of properties that affect
Wonderware Factelligence Report Designer
11
their behavior and appearance. These can be set via the
Property Toolbox. Take some time to examine some of
these.
Wonderware Factelligence Report Designer
12
Chapter 4 Report Design
Wonderware Factelligence Report Designer
13
Chapter 3
Reporting Mechanism
The reporting tool used with Factelligence is Active Reports
Professional Version 2.0 (by Data Dynamics).
Active Reports provide royalty free components in the form of
a Designer control, that allows the user to create and edit
reports, and a Viewer control to view the report in an
executable or browser based application.
The Report Designer application utilizes both components
while the Manager application uses only the viewer.
A full version of this product may be purchased by the user if
so desired or the help file downloaded from their website at
[Link].
The mechanism for running a report works differently in the
Report Designer and Manager browser applications for
specific reasons as we shall see below.
Report Designer
All report layouts are created with an ADO data object. This
object is configured with the required connection string and
SQL query to gather the data directly from the Factelligence
database. When the report is previewed in Report Designer
the designer runs it as a standalone report. The query
configured in the report is run directly against the database
(bypassing the Factelligence middleware), the retrieved
dataset is applied to the report file for grouping and
formatting, and the result displayed in the viewer.
Wonderware Factelligence Report Designer
14
Chapter 3 Reporting Mechanism
This mechanism requires the Report Designer application to
have references to all the objects required to process the
report and query the database. This is fine for a report design
and configuration application and allows the user to quickly
and efficiently design and test most reports outside of the
Middleware/Manager structure. The exception is when the
reports utilize the external global classes (see the section on
Scripting and Charts).
Manager
Manager uses a feature within the Active Reports framework
that allows you to pass a recordset to a report layout at
runtime. The recordset must include the same fields and
sort order as defined by the query configured in the reports
ADO object, but can be constrained and filtered prior to being
applied to the report.
As a multi-client browser application, Manager makes use
another feature called the Active Reports WebCache Server.
When a report is requested by a Manager client, the
Factelligence Web Server processes the SQL query required
by the report, modified with user selected time period and
filters, via the Factelligence middleware, applies the
resultant recordset to the report, and runs the report. The
resultant formatted report complete with data is cached and
then streamed to the clients browser for viewing via the
viewer object.
Why do we do it this way?
Firstly, the reporting workload of data gathering and report
processing is now handled by the Web Server rather than the
client. The client requires nothing more than the viewer to
view the resultant report. This fits well with the
Factelligence Manager architecture of n-tier and zero client
install.
Secondly, the development effort in creating queries and
report layouts is leveraged by this structure. A single report
file created based on a given query can be used with any
combination of data selection constraints and filters without
alteration. The different record sets are simply generated
and applied to the same report file.
Correspondingly, a number of different report files that
display the data in different formats can be created based on
a common query.
Wonderware Factelligence Report Designer
Configuration
15
Configuration
The trick with this approach is that Factelligence must be
able to regenerate, complete with constraints and filters, the
same SQL query that the report was designed with and run
this via the middleware to create the data required.
So, when a user creates a report layout for running in
Manager they must also configure, test and store in the
database the query required by the report, and configure the
relationship between the report and the query.
Wonderware Factelligence Report Designer
16
Chapter 3 Reporting Mechanism
Wonderware Factelligence Report Designer
17
Chapter 5
Report Preview
The Preview tab of the Report Designer contains the viewer
control and allows you to preview the report you created in
the designer.
Figure 2 - Preview Tab
The viewer contains a toolbar that allows you to perform the
following functions:
Print: opens the standard printer dialog
Zoom: zoom in / out or select the desired scaling
Multi-Page: View multiple pages
Page Select: Move back and forth between the pages or
go to a specific page
Wonderware Factelligence Report Designer
18
Chapter 5 Report Preview
Exercise 2 - The Preview Tab
Aim: To preview a report.
Method:
1
In order to preview a report we must set the connection
string for the embedded ADO object to point to a valid
database. Carrying on from Exercise 1, have the
Production By Period report layout open in the Design
tab.
Find the ADO graphic object in the Detail section of
the report. Right-click on this and select Properties.
Edit the Connection String property to point to your
Factelligence database.
Figure 2.1 - Setting the Connection String
3
Click the OK button.
Click the icon in the top right corner of the Fields list
(bottom left panel of Designer). If the connection string
and query is valid then a list of the fields returned by the
query will be displayed in the list. If there is an error, a
message will be displayed.
Select the Preview tab to preview the report. It should
appear as in Figure 2 above.
Wonderware Factelligence Report Designer
19
Chapter 6
Report Configuration
The Configuration tab of the Report Designer is where we
configure the report to run in Factelligence.
Figure 3 - Configuration Tab
The Configuration tab consists of a number of controls to
allow the setting / selection of the various aspects of a
reports configuration. You can modify an existing report
configuration or create a new one.
In order to configure reports you must have the required
privilege in Factelligence. If you do not then this tab is not
available to you.
Wonderware Factelligence Report Designer
20
Chapter 6 Report Configuration
Important The tab will list all currently configured reports in the
Factelligence database. Altering or deleting these will affect the
way these reports operate. Ensure you are aware of all the
ramifications before making changes.
A reports configuration consists of the following:
Report Category: determines where the report will be
placed in the report tree
Report Name: determines the report name in the tree.
Note that this name is different to the report filename. In
fact you may have different named instances of the same
report file configured differently.
Report Description: for a brief description of the report
Max Pages: puts an upper limit on the number of pages
that will be displayed for the report when it is run to
prevent large reports from clogging the system. This will
default to a preset value (usually 20) for a new report. If
you have the required privilege you can alter the value.
View Level: determines who can access this report at
runtime. A users view level must be greater than or
equal to the value set here to view the report. This will
default to a preset value (usually 1) for a new report. If
you have the required privilege you can alter the value.
Report Type: will default to Manager. Reports may be
run in the Manager client application or be scheduled to
run in the background and the data be exported to files.
This is achieved via the Factelligence Supply Chain
Connector application (refer to the Supply Chain
Connector documentation for further details.). When a
report is run by Supply Chain Connector it cannot
contain references to filters or sorts as there is no user
interface available. Therefore all that need be configured
is the report details and file path. By selecting the SCC
Export type the Query Details section will be hidden.
File Path: must point to the report file that has been
created. This must be the network filepath as required by
the Manager application from the web server.
The path will default to:
%APP_PATH%Reports/System/<Category>/<Name>.rpx
At runtime the defined rootpath for the report files (set via
the Factelligence Configurator application) will be
substituted for %APP_PATH%.
By default the rootpath is installed as
C:\Factelligence\Manager\.
Wonderware Factelligence Report Designer
21
The path can be left as is or an absolute path entered:
<drive>:\Factelligence\Manager\Reports\System\<Cat
egory>\<Name>.rpx
Data Query: specifies which query to run for this report.
Sort Fields: (optional) specifies the sort order for the data
returned by the query for this report.
Filter: (optional) lists all the parameters available in the
query. Selections here determine which filter options are
displayed to the user at runtime to constrain the data.
Custom Filter: (optional) lists all the fields in the query. By
setting descriptions for fields these will be available to the
user at runtime to create a custom SQL filter to apply to the
query.
Exercise 3 - The Configuration Tab
Aim: To examine report configuration.
Method:
1
Open the Configuration tab and in the Report Details
tree select the Production \ Production By Period
report. The controls on the form will display the current
configuration settings for the report. It should appear as
in Figure 3 above.
Wonderware Factelligence Report Designer
22
Chapter 6 Report Configuration
Select the Set button for Sort Fields. The dialog box is
fairly straightforward. It presents a list of fields in the
query for you to use as the sort criteria for the report.
Figure 3.1 - Sort Fields Dialog
Note that when the Sort dialog is opened the SQL query
is examined and the fields are retrieved assuming a
standard syntax of
SELECT [Link] ..FROM .
The parsing of the SQL caters for most common SQL
statements but it may be the case that the retrieved list
of fields is nonsensical or incomplete. To cater for this a
textbox for manual entry of available fields has been
provided.
3
When the Custom filter option is selected for a report
(as it is in this case) then when the report is selected in
Manager a dialog is presented to you so you can construct
a custom filter using the fields in the query. In order to
Wonderware Factelligence Report Designer
23
make this user friendly you assign alias descriptions for
the fields and only include those fields that are relevant
to what the report is trying to achieve.
Select the Set button for the Custom Filter table.
Those fields that the user has access to at runtime have
an associated alias.
Figure 3.2 - Custom Fields Dialog
Wonderware Factelligence Report Designer
24
Chapter 6 Report Configuration
Wonderware Factelligence Report Designer
25
Chapter 7
Queries
The Query tab in Report Designer allows you to design, test
and configure SQL queries to run on Factelligence for use
with your custom reports.
Figure 4 - Query Tab
The Query tab contains of a number of controls to allow the
setting / selection of the various aspects of a querys
configuration. You can modify an existing query or create a
new one.
Wonderware Factelligence Report Designer
26
Chapter 7 Queries
Important The tab will list all currently configured queries in the
Factelligence database. These will be used by existing reports,
status screens or SCC export functions. Altering these queries will
affect the way these features operate. Ensure you are aware of
all the ramifications before making changes.
A query definition consists of the following:
Query Description: the name that will appear in the
queries tree.
Query Type: you can use a SQL statement or an existing
database stored procedure
SQL Statement: type your SQL query here.
Stored Procedure: enter the name of the stored
procedure.
Parameters: define the attributes of any runtime
parameters that you included in your query.
Query Parameters
Parameters may be included in your SQL query or stored
procedure. Those parameters which are then configured to be
available for a given report will be made available for you to
set when running the report in Manager.
Manager provides screens with controls such as calendars,
tree views and text boxes to allow you to enter runtime
parameters. As these screens are hard coded then there are
only a limited number of parameters available to you to
include in a query. These are:
Start Time
End Time
Entity
Item
User
Work Order
Shift
Custom
Wonderware Factelligence Report Designer
Query Parameters
27
Tip None, some or all of these parameters can be included in any
given query and you are encouraged to include as many as
possible to make the query generic. That way the same query may
be used with many different report files. Remember that it is
during the runtime configuration of each individual report that
the parameters relevant to the report are selected from ALL those
available in the query.
When using parameters in a query they must follow a strict
syntax and then be setup correctly in the parameters list.
Available parameter types for reports and their attributes
are as follows:
Parameter Name Parameter TypeDefault Value
Start_Time
Date TimeNULL
End_Time
Date TimeNULL
Entity
String ListNULL
Item
String ListNULL
User
String ListNULL
Work Order
String ListNULL
Shift
String ListNULL
Custom
CustomNULL
The syntax for parameters in the query is dependent on the
parameter type as follows:
Parameter Type
Typical Query Entry
Date Time
(<table>.<field> >= @Start_Time OR
@Start_Time IS NULL)
String List
(<table>.<field> IN @Entity)
Custom
(@Custom)
Exercise 4 - The Query Tab
Aim: To examine query configuration and parameter usage
and create a simple query.
Method:
1
Open the Query tab and in the tree, select the
Production Reports query. The controls on the form will
display the current configuration for the query. It should
appear as in Figure 4 above.
Wonderware Factelligence Report Designer
28
Chapter 7 Queries
Click on the Test button to preview the results of the
query.
Figure 4.1 - Query Test Results Dialog
3
Note how the parameters are used in the query and
defined in the Parameters table. When the query was
tested it used the default values for all these parameters
ie: NULL. This will return all data, unconstrained.
Change the Default Value of the Entity parameter to
reflect a list of ent_id values from the test data returned
eg: 1211,1212. Test the query again and it will return
only those records for the entities listed.
Note Dont forget the quotation marks around the entries.
5
Select the Cancel button to cancel the changes.
Wonderware Factelligence Report Designer
Query Parameters
29
Right-click on the root (topmost) node of the Queries tree
and select Add Query. The controls are now ready to
accept your new query details.
Figure 4.2 - Adding a New Query
7
Change the Query Description to My Query.
Enter the following SQL statement:
SELECT * FROM item
Select the Save button then test your query.
10 Alter the query to be:
SELECT * FROM item WHERE item.item_class_id IN
@Item
11 Right-click on the Parameters table and select Add. Add
the Item parameter as type String List to your query.
Save the query and retest to ensure the syntax is correct.
Wonderware Factelligence Report Designer
30
Chapter 7 Queries
12 Set the default value for the Item parameter to
something meaningful and retest.
Figure 4.3 - Sample Query
Wonderware Factelligence Report Designer
31
Chapter 8
Tutorial Exercise
This exercise will walk you through all the steps involved in
producing a report for use in the Factelligence application.
The report chosen for the exercise is the OEE By Shift Trend
system report included with the Factelligence application.
This report was chosen as it includes all of the common
report design concepts used in the Factelligence reports suite
and those that will most commonly be used in the creation of
custom reports.
Topics covered include:
Preparing the report layout
Creating a query and its parameters
Using the report template to create the report
Placing controls on the report
Grouping of data
Scripting for calculations
Embedding an ActiveX chart control in the report and
scripting to it
Testing the report
Configuring the report to run in Manager
It is impractical to try to cover all aspects of reporting in a
single exercise and should you require a more thorough
understanding of the reporting product then they are
encouraged to either:
Wonderware Factelligence Report Designer
32
Chapter 8 Tutorial Exercise
Attend a training course on the Active Reports package.
These are provided by Data Dynamics, the suppliers of
the product and they can be contacted via their website at
[Link].
Download the full documentation for the product free
from the above website
Overview
The creation of a report can be broken down into a number of
phases:
Specification (layout & requirements)
Query & data design
Design & data validation
Charting & other features
Configuration & final testing
We will cover each of these phases in order.
Specification
It is important to prepare a desired specification for the
report with as much detail as possible re the layout, data
content and how the user is to interact with the report.
The design of the report often is dependent on how the data
needs to be displayed so it is a good idea to have as much of
this done up front as possible.
The report we wish to prepare is described in the spec sheet
OEE By Shift Trend Report located in Appendix A. This spec
sheet is a good template to use in the preparation of report
requirements. Have a look at what is included here.
Tip Start with a basic description and a sketch of the layout of
the report. As the phases of report creation are completed update
the document.
In this report we wish to display the four KPIs associated
with OEE on a per shift basis, in chronological order for the
time period selected. This data will be tabular and grouped
by entity with a chart after the data showing the trends for
the KPIs.
Wonderware Factelligence Report Designer
Query and Data Design
33
Query and Data Design
Now that we know what we wish to display we need to create
a query to get the required data.
Factelligence allows for the creation and use of
parameterized SQL statements or Stored Procedures. The
preferred method is to use a SQL statement as the stored
procedures are more complicated to parameterize. However
stored procedures are faster and more efficient so for very
complex queries or for processing large amounts of data they
may be a better option.
We must decide what data to retrieve and what parameter
selections we wish to make available to the user. Our report
requires the OEE data from the tpm_stat database table
and we wish the user to select the time period and entities.
Wonderware Factelligence Report Designer
34
Chapter 8 Tutorial Exercise
In this case we will be using a standard SQL query that is
included with the Factelligence application. Let us examine
this query. The source for any of the standard queries can be
found in the Factelligence\Manager\SQL directory, in this
case the file OEE [Link].
SELECT tpm_stat.ent_id,
,ent.ent_name
,tpm_stat.wo_id
,wo.wo_desc
,tpm_stat.oper_id
,tpm_stat.seq_no
,job.act_start_time
,job.act_finish_time
,job.batch_size
,tpm_stat.shift_start
,tpm_stat.shift_id
,shift.shift_desc
,tpm_stat.item_id
,item.item_desc
,[Link]
,tpm_stat.qty_good
,tpm_stat.qty_reject
,tpm_stat.std_prod_rate
,tpm_stat.runtime
,tpm_stat.downtime
,tpm_stat.idletime
FROM tpm_stat tpm_stat with (nolock)
INNER JOIN ent ent with (nolock) ON
tpm_stat.ent_id = ent.ent_id
LEFT OUTER JOIN wo wo with (nolock) ON
tpm_stat.wo_id = wo.wo_id
LEFT OUTER JOIN job job with (nolock) ON
tpm_stat.wo_id = job.wo_id AND
tpm_stat.oper_id = job.oper_id AND tpm_stat.seq_no =
job.seq_no
INNER JOIN shift shift with (nolock) ON
tpm_stat.shift_id = shift.shift_id
LEFT OUTER JOIN item item with (nolock) ON
tpm_stat.item_id = item.item_id
WHERE (tpm_stat.shift_start >= @Start_Time OR
Wonderware Factelligence Report Designer
Query and Data Design
35
@Start_Time IS NULL) AND
(tpm_stat.shift_start < @End_Time OR @End_Time
IS NULL) AND
(tpm_stat.ent_id IN @Entity) AND
(tpm_stat.item_id IN @Item) AND
(tpm_stat.wo_id IN @Work_Order) AND
(tpm_stat.shift_id IN @Shift) AND
(@Custom)
This query retrieves all the data from the tpm_stat table
together with some descriptive data from joined tables. Not a
complicated query.
Take note of the WHERE section of the query. This is where
any parameters are scripted. Parameters are those values
that may be entered at runtime by the user to constrain the
data returned. Please refer to the Queries section of this
guide for more detail on query preparation and the use of
parameters.
This is what we would term a Generic query. It retrieves all
data fields from the table and the data is raw (unprocessed).
Furthermore it includes all parameters that are available as
report filters.
In our report we may not use some of these fields and we only
wish the user to select the report period and the entities.
However a generic query may be used by many different
reports of an OEE theme eg: OEE by Work Order, Utilization
By Entity, Performance By Shift, .
Tip If the query is simple and it can be made generic then do so,
thus leveraging your query development to multiple reports. If
the query is complex and specific to one report or accesses large
amounts of data then make it concise and more efficient.
Queries can be written, tested and saved to the database by
using the Report Designer. Start Report Designer and go to
the Query tab. Select the OEE Reports query and you will see
the query text and parameters defined.
Wonderware Factelligence Report Designer
36
Chapter 8 Tutorial Exercise
Figure T1 - OEE Reports Query
Click on the Test button to see the result of the query (with
no parameters applied).
We need do no more with the query so we will move on to
designing the report.
Report Design and Data Validation
Report design should be an iterative process. Create the
report in small steps, testing as you go. The Report Designer
application caters for this by allowing the user to switch
easily between design and preview mode.
The Design Tab
Start Report Designer. It defaults to the Design tab.
Wonderware Factelligence Report Designer
Report Design and Data Validation
37
Figure T2 - Design Tab
Using the Report Template
Factelligence includes a report template to assist in the
creation of custom reports. It is setup with some basic
formatting and script to suit the running of reports in the
Manager module. Alternately we could start with a
completely blank sheet or use one of the existing reports as a
starting point.
We will use the report template. From the menu select File
-> Open and open the file
\Factelligence\ReportDesigner\Samples\ReportTemplate.
rpx.
Wonderware Factelligence Report Designer
38
Chapter 8 Tutorial Exercise
Figure T3 - The Report Template
Let us consider what is included in this template.
Firstly you will note that the report has a number of sections.
Within those sections are placed the objects used to format
the report and display the data. The use of these groups is
the key to how the data is processed and displayed on the
report.
Report Header/Footer: displayed once at the beginning
and end of the report
Page Header/Footer: displayed at the beginning and
end of each page
General Group/Footer: displayed whenever the data
field associated with the group changes.
Detail: displayed for every database record processed.
Most of the objects that exist in the template will remain or
be relocated and adjusted for a custom report. We will look at
some of these in the process of designing the report.
Report Header/Footer: These sections contain objects and
scripts used to display the details of report filters that are
applied when the report is run in Manager.
If you open up the Report Header section you will find a
hidden textbox txtParameters. This is included in all
system reports as Manager has the capability of passing a
text string to the report. The text string can contain anything
but most commonly will contain variable values or text for
display in the report. For example, entity IDs are used in the
query filter string in all reports. However it is more
Wonderware Factelligence Report Designer
Report Design and Data Validation
39
user-friendly to display the associated descriptions in the
filter section so Manager uses the parameter feature to pass
the descriptions.
The Report Footer section contains objects (and script) that
will display the filters that were applied to the report query
ie: entity IDs, item IDs, etc. Manager passes the filter string
to the hidden txtFilters object in a standard syntax for all
reports. If the user desires not to see this information then
this section can be removed or hidden.
For your report nothing needs to be altered in these sections.
Page Header/Footer: The Page Header contains the logo,
some labels, a colored box and text fields for start and end
dates.
The date fields should not be altered as Factelligence will
automatically populate them with the dates selected by the
user when the report is run in Manager. If this particular
report does not require the user to select start and end dates
for the report then these objects and their labels can be
deleted.
Changing Properties
Click on the report title label. In the property toolbox change
the Caption to reflect the title of your new report.
Figure T4 - Changing the Title by using the Property Toolbox
If the logo is to be changed then select it and in the property
toolbox change the Picture property to reference the new
bitmap file.
Wonderware Factelligence Report Designer
40
Chapter 8 Tutorial Exercise
Important The bitmap must be sized correctly for the report and
the SizeMode property must be set to Clip. Using the
SizeMode = Stretch or Zoom properties to resize a bitmap will
cause the report to resize the graphic each time the report is
rendered and can increase report processing time by a factor of
10+.
Using the File -> Save option in the designer menu, save
the report file to its new location eg:
\Factelligence\Manager\Reports\Custom\MyOEEReport.
rpx
Figure T5 - File Save
Remember to save your work frequently.
The ADO Data Object and Data Fields
In the Detail section we find the ADO object. This is used
by the report to access the database for gathering data
during design and preview operations. We need to set this
object up to connect to our database and use the OEE query.
Right-click on the ADO object and select Properties.
Edit the ConnectionString to reflect the connection to your
database
Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=USER;Pwd=PWD;Initial
Catalog=DBASE_NAME;Data Source=SERVER_NAME
Edit the Source (SQL) to be the OEE query above without
the WHERE clause. We cannot include parameters at this
point as we are not running the report within the Manager
Wonderware Factelligence Report Designer
Report Design and Data Validation
41
application and parameter selection is not available. The
query embedded in the report is not used when the report is
run in the Manager application. Rather the query configured
in the Query tab together with its parameters is used (refer
to the Reporting Mechanism section for further details).
Tip If you have a large amount of data to process then adding
constraints to the ADO query (in a WHERE clause) to limit the data
to a manageable and meaningful quantity will make the report
design and testing process more efficient.
Figure T6 - Setting the Connection and Query
We can now do a quick test on the query.
By clicking on the icon in the Fields list (bottom left side of
the Designer) the report will process the query entered in the
ADO object and return a list of available database fields. If
there is an error in either the query or the connection string
then an error will be displayed.
Wonderware Factelligence Report Designer
42
Chapter 8 Tutorial Exercise
Figure T7 - Displaying Query Fields
Grouping
Now it is time to start adding data fields and groups to the
report.
Our primary grouping is to be by Entity. Select the
ghGroup section (this is the group header) and in the
property toolbox set:
Name:
ghEntity
Data Field:
ent_id Causes a new group header to
be displayed each
time this field changes.
KeepTogether: TrueEnsures the section is not split
over a page
boundary.
Select the gfGroup section (this is the group footer) and in
the property toolbox set:
Name:
gfEntity
KeepTogether: True
Note A certain standard for naming of objects as been employed
here but this is entirely a user preference.
Wonderware Factelligence Report Designer
Report Design and Data Validation
43
Figure T8 - Data Field Selection for a Group
From the Fields window, drag the ent_name field into the
ghEntity section. This creates a new Text Field object.
Edit the object properties:
Name:
txtEntName
Set this object at the top of the section and make it cover the
entire width of the section.
Tip The mouse can be used to size and move objects in the usual
manner. For fine adjustments use SHIFT + ARROW KEYS for sizing
and CTRL + ARROW KEYS for movement.
Increase the height of the section using the mouse or set its
property:
Height:
615
Now select the Preview tab to see how the report is
processed. You may see something like that in Figure T9
below.
What is important to note here is how the grouping has
worked. As the report processes the records retrieved by the
query, each time it detects a change in the ent_id field a
new ghEntity/gfEntity section is created. Because the query
does not currently order the data we see repeats of the same
entity. What we need to do is to ensure that the data
retrieved by the query is ordered in the same way that we
create groups on the report.
Wonderware Factelligence Report Designer
44
Chapter 8 Tutorial Exercise
Figure T9 - First Preview
Return to the Design tab and select the ADO object in the
Detail section and right click to open its properties. Edit the
SQL query to include ORDER BY tpm_stat.ent_id at the
end of the query.
Preview the report again and you should now see only one
entry per entity.
Formatting
Now that we have achieved the first stage of the data
processing we will do some formatting.
Firstly, this report will start a new page for each new entity
so the ghEntity section is the logical place to have the column
headers etc.
In the Page Header, delete the blue rectangle and cut and
paste the column header labels into the ghEntity section.
Tip Hold the CTRL key down to select multiple objects. Use
CTRL+X and CTRL+V to cut and paste in the usual manner.
Adjust the properties of the txtEntName:
BackStyle:
Normal
BackColor:
R,G,B = 128,174,200
Font:
Bold
Wonderware Factelligence Report Designer
Report Design and Data Validation
45
Adjust the properties of the 6 column header label objects:
Caption:
% OEE
Date Shift % Util
% Perf% Qual
Width:
1134
2041 2778 1134
1134 1134
Space them across the width of the report and use the
formatting toolbar to set the text alignment to Centered.
Adjust the properties of the sections as follows:
PageHeader
Height: 1300
ghEntity
Detail
Repeat: Every Page Include No
This causes the header to repeat if the data goes
across a page boundary.
gfEntity
NewPage: After
Starts a new page for each new entity.
Figure T10 - Entity Group formatting
There is one more small detail to take care of before we
Preview our report again. Select the PageHeader section
and then View -> View Script from the Designer menu (or
click the View Script icon in the Designer toolbar). This will
open the scripting window.
Delete the Sub OnBeforePrint section. This was used to
hide the column headers that were in this section for the last
report page which displays the filters. We will come back to
discuss scripting later.
Save the report and Preview your results to date.
Wonderware Factelligence Report Designer
46
Chapter 8 Tutorial Exercise
Adding Groups and Data Display Objects
The next stage of the report will involve setting up the
section to display the actual data. We wish to display the
data per shift in descending chronological order so we first
need to group the data by date and then by shift.
Right-click anywhere in the report and select Insert ->
Group Header/Footer. This will create a new group outside
the Detail section.
Set the properties as follows:
Name:
ghShift
DataField:
shift_start
KeepTogether: True
Height:
900
Name:
gfShift
KeepTogether: True
Height:
Edit the SQL statement in the ADO object to read ORDER
BY tpm_stat.ent_id, tpm_stat.shift_start DESC.
From the Fields window drag the shift_start, shift_id and
shift_desc fields into the ghShift section and set the
properties as follows:
Name:
txtShiftStart
OutputFormat: d-mmm-yyyy
Width:
2041
Name:
txtShiftID
Left:
2098
Width:
567
Name:
txtShiftDesc
Left:
2778
Width:
2041
Wonderware Factelligence Report Designer
Report Design and Data Validation
47
Figure T11 - Shift Grouping
Save the report and Preview. You should now see the shift
groupings on the report.
Figure T12 - Preview of Shift Grouping
Complex Data Display Concepts
These include:
Using Virtual fields
Creating Summation objects
Scripting calculations
Wonderware Factelligence Report Designer
48
Chapter 8 Tutorial Exercise
First let us review how OEE is calculated.
OEE = Utilization x Performance x Quality
where all the values are expressed as a percentage figure.
Utilization = runtime vs available time
Performance = production vs (std rate x runtime)
Quality = good production vs total production
Looking at the fields returned by the query we can use the
following calculations:
Utilization =runtime
---------------------------runtime + downtime
Performance =
(qty_good + qty_reject)
-------------------------------------------------------------(batch_size / std_prod_rate) x (runtime / 3600)
Note All times are in seconds and the std_prod_rate is hours per
batch.
Quality =
qty_good
----------------------------qty_good + qty_reject
In our report we wish to do these calculations on a per shift
basis. Easy enough for the Utilization and the Quality as
they are simple summations of existing fields. Not so easy for
the Performance. What would be nice is for there to be a
performance field for each record in the table that we could
then sum in the report over whatever grouping we chose (in
this case by shift).
Mathematics tells us that all we need do is create a weighted
performance field based on runtime and then if we sum the
weighted performance over any timeframe as follows.
If
PW1 = P1 * RT1
runtime
PW = weighted perf, P = perf, RT =
PW2 = P2 * RT2
Then
Ptotal = (PW1 + PW2) / (RT1 + RT2)
We could include a new calculated field in the query for
weighted performance however we will do it in the report for
two reasons. Firstly to demonstrate the concept of virtual
Wonderware Factelligence Report Designer
Report Design and Data Validation
49
report fields and more importantly it keeps the query generic
so different reports may apply different versions of a
performance calculation if required.
Our new field is now calculated as:
Weighted Performance =(qty_good + qty_reject) x
std_prod_rate x 3600
-------------------------------------------------------------batch_size
We will now start editing the report script. The user is
encouraged to review the section on Scripting for a
description on report processing and basic scripting
principles.
Creating Virtual Data Fields
Select the View Script icon in the Designer toolbar to open
the Scripting Editor. From the Object drop down, select
Active Reports Document.
Add the following script:
Sub OnDataInitialize
'Create the required virtual fields
[Link] "weighted_perf"
End Sub
Sub OnFetchData(eof)
'As data is read, populate the virtual fields
'Generate weighted performance field
'
' = Performance * Runtime
'
' = (Qty Good + Qty Rej) * Std Prod Rate *
Runtime
'
-----------------------------------'
Batch Size * (Runtime / 3600)
'
' = (Qty Good + Qty Rej) * Std Prod Rate *
3600
'
------------------------------------------'
Batch Size
'
[Link]("weighted_perf").Value =
([Link]("qty_good").Value +
[Link]("qty_reject").Value) *
[Link]("std_prod_rate").Value * 3600
/[Link]("batch_size").Value
End Sub
Wonderware Factelligence Report Designer
50
Chapter 8 Tutorial Exercise
As the report processes the records returned by the query it
will now add a new virtual field to each record with the
value as calculated above. This field can now be accessed by
report objects for processing and can be displayed like all the
other fields.
Figure T13 - Creating a Virtual Data Field
Summation Objects
We will now add a number of invisible summation objects to
calculate the values needed for the OEE KPIs. Note that
summation objects are more efficient than using script.
Close the Scripting Editor. In the Object Toolbar select the
TextBox icon and use the mouse to create a textbox in the
lower part of the ghShift section. The size of the textbox is
not important as it will be invisible. Set the properties as
follows:
Name:
txtShiftRT
Datafield:
runtime
SummaryGroup:ghShift
SummaryType: SubTotal
Text:
RT
This object will now sum the runtime field values and reset
itself at each change of shift.
Wonderware Factelligence Report Designer
Report Design and Data Validation
51
Repeat this procedure four more times as follows:
Name:
txtShiftDT
Datafield:
downtime
SummaryGroup:ghShift
SummaryType: SubTotal
Text:
DT
Name:
txtShiftGood
Datafield:
qty_good
SummaryGroup:ghShift
SummaryType: SubTotal
Text:
Good
Name:
txtShiftReject
Datafield:
qty_reject
SummaryGroup:ghShift
SummaryType: SubTotal
Text:
Reject
Name:
txtShiftWeightedPerf
Datafield:
weighted_perf
SummaryGroup:ghShift
SummaryType: SubTotal
Text:
Perf
Note You will not be able to select weighted_perf from the
dropdown Datafield property. Simply type it in.
Figure T14 - Hidden Summation Objects
Wonderware Factelligence Report Designer
52
Chapter 8 Tutorial Exercise
Save the report and Preview to check that your data
calculations are correct. Once the data has been validated
then make all the summation objects invisible.
Tip Select all the objects by using the mouse to drag a box
around them or hold the CTRL key down while clicking them. Then
use the Property Toolbox to set their visibility to false.
Figure T14 - Preview Summation Data for Validation
Scripting Calculations
We now have the summations of the fields we need to
calculate our OEE KPIs on a per shift basis. Let us add the
objects to display the data and the required scripting
calculations.
Wonderware Factelligence Report Designer
Report Design and Data Validation
53
Add the following four TextBox objects to the ghShift section
and then use the mouse to drag the bottom margin of the
section up and thus reduce the height of the section to hide
the summation objects.
Name:
txtShiftUtil
Alignment:
Right
OutputFormat: #,##0.0
Text:
Util
Left:
4876
Width:
850
Name:
txtShiftPerf
Alignment:
Right
OutputFormat: #,##0.0
Text:
Perf
Left:
6066
Width:
850
Name:
txtShiftQual
Alignment:
Right
OutputFormat: #,##0.0
Text:
Qual
Left:
7257
Width:
850
Name:
txtShiftOEE
Alignment:
Right
OutputFormat: #,##0.0
Font:
Bold
Text:
OEE
Left:
8447
Width:
850
Wonderware Factelligence Report Designer
54
Chapter 8 Tutorial Exercise
Figure T15 - Final Data Display Objects
Select the ghShift section and open the Scripting Editor.
Add the following script to calculate the OEE KPIs and
populate the textboxes with the results.
Sub OnBeforePrint
'Calculate the OEE KPIs
'Utilization
If [Link] +
[Link] <> 0 Then
[Link] =
[Link] /
([Link] +
[Link]) * 100
Else
[Link] = 0
End If
'Performance
If [Link] <> 0 Then
[Link] =
[Link] /
[Link] * 100
Else
[Link] = 0
End If
'Quality
If [Link] +
[Link] <> 0 Then
[Link] =
[Link] /
([Link] +
[Link]) * 100
Else
[Link] = 0
End If
'OEE
[Link] =
[Link] *
Wonderware Factelligence Report Designer
Report Design and Data Validation
55
[Link] *
[Link] / 10000
End Sub
All we are doing here is using the values in the hidden
summation objects in the standard formula and applying the
results to the textbox objects for formatting and display.
Figure T16 - Script for Calculating the KPIs
The data processing and display phase of the report is now
complete. Save the report and Preview for further data
validation.
Figure 17 - Preview OEE KPI Data
Wonderware Factelligence Report Designer
56
Chapter 8 Tutorial Exercise
Charting and Testing Using Manager
The hard work has been done. Now we will add a chart to
display the KPI trends. Refer to the Scripting and Charts
section for more details on charting.
Increase the height of the gfEntity section to about 6500.
Select the ActiveX Control icon in the Object Toolbar and
from the list of controls select the Tidestone First
Impression 6.0 Chart. Place the chart in the section and size
to suit by using mouse left click and drag. Set its properties
to:
Name:
chtOEE
Figure T18 - Inserting an ActiveX Chart Control
We use this chart in the Factelligence reports as it is simple
to use and has very user-friendly design time editors built in
that allow you to set the look and feel of the chart without
having to run the report.
Chart Data and Formatting
Right-click on the chart and select Edit Chart Data. Enter
the data as shown below.
Wonderware Factelligence Report Designer
Charting and Testing Using Manager
57
Figure T19 - Sample Data to Test the Chart
Select OK and you will see the data displayed in the chart.
Wonderware Factelligence Report Designer
58
Chapter 8 Tutorial Exercise
Right-click on the chart and select Chart Designer. Make
the following settings from the options available:
Chart
Type
Line
Backdrop
FrameStyle = Single Line
Title
Location
Visible = On
Text
OEE Trend Chart
Font
Arial Bold 12
Legend
Location
Visible = On
Font
Arial Bold 10
Category (X) Axis
Axis Title
Text
Date & Shift
Font
Arial Bold 10
Axis Labels
DisplayAutomatic Rotation = Off
LayoutAlignment = Left
Orientation = Vertical
FontArial Regular 10
Value (Y) Axis
Axis Title
TextPercent (%)
FontArial Bold 10
Axis Labels
FontArial Regular 10
Value (2nd Y) Axis
Value Scale
ScaleShow = Off
Series
Utilization / Performance / Quality /
OEE
LinesWidth = 1 Point
ColorChose a different line color if
desired
DataPoint
Wonderware Factelligence Report Designer
Charting and Testing Using Manager
59
MarkersShow Markers = On
Style = Filled Circle
Size = 4pt
Figure T20 - Chart Designer Dialog
Save the report and Preview. You will see the chart object
displayed after each set of entity data. The charts will
display the sample data as we have not scripted any real
data to them yet.
Figure T21 - Formatted Chart
Scripting data to the chart is not a complex task once you
understand how it works. Basically we must script the values
for the OEE KPIs into the DataGrid of the chart where the
rows represent the Shift and the columns represent the KPI
values (one column per KPI). In short we replace the sample
data we entered with actual data at runtime.
As we wish to graph the totals for each shift we need some
way of storing the group totals as they are calculated (for an
initially unknown number of groups) and then applying them
Wonderware Factelligence Report Designer
60
Chapter 8 Tutorial Exercise
to the chart once the report has finished processing the data.
This effectively requires the declaration and use of global
variables (ie: variables that can span all sections).
Unfortunately, global variables cannot be defined inside the
reports scripting environment, however Active Reports
provides a mechanism whereby the report processing engine
can access an external object for use within the reports
scripting. To this effect Factelligence provides a class
containing a number of variant arrays that can be used by
any report. These arrays are referenced by the Web Server
when running the report and appear as global variables to
the report script. The user need only know how to reference
these arrays in the script and nothing more. These arrays
should cater for any foreseeable charting or other
requirements.
Now an important point.
When the Preview tab is selected the report that is in the
Design tab runs directly against the database using the
query in the ADO object to generate the recordset for the
report. It does not access the Factelligence middleware or the
Web Server so therefore the global variable arrays are not
available to any reports previewed in the Report Designer
application.
Important If you are designing a report using the global variables
then you can only test that part of the scripting by using the
Manager application.
Configuring the Report for Manager
So we now need to configure the report to run in Manager in
order to test the chart. Refer to the section on
Configuration for more details on the Configuration tab.
Wonderware Factelligence Report Designer
Charting and Testing Using Manager
61
Select the Configuration tab in the Designer and set the
following:
Report Category:OEE
Report Name:
My OEE Report
Report Description:Data and trend of OEE KPIs by
shift for selected entities and shifts
Report Type:
Manager
File Path:
C:\Factelligence\Manager\Reports\Custom\MyOEERe
[Link]
(or whatever path is relevant to your
report)
Data Query:
From the dropdown list of queries
select the OEE Reports query.
Filter:
In the Filter list select Start_Time,
End_Time, Entity, Shift. These are the parameters that
we wish the user to select at runtime.
Sort Fields:
Open the Sort Fields dialog by
clicking the Set button and select the sort order for the
data to suit the report ie: ent_id, shift_start DESC
Save the configuration.
Figure T22 - Report Configuration
Launch the Manager application and run the report. It
should appear as it did in Report Designer with the charts
showing the sample data.
Wonderware Factelligence Report Designer
62
Chapter 8 Tutorial Exercise
Tip Leave Manager open. Each time you make a change to the
report in Report Designer simply save the report and then reselect
the View button in Manager to test this latest report file with
the same parameters.
Scripting Data to a Chart Using Global Arrays
Now we can add the scripting for the chart and test it.
The external object holding the arrays is always referenced
in script as objReport. The available arrays for use are:
DataArray1(1000,100,10)a 3D variant array
DataArray2(1000,100,10)a 3D variant array
DataArray3(10000,10,10)a 3D variant array
DataIndex(10)a 1D variant array
We will use the last DataArray to store the Shift string, and
KPI values. The DataIndex keeps track of the number of
groups we end up with and maintains a pointer into the
array.
First we need to populate the array.
Select the ghShift section and open the Scripting Editor. Add
the following script to the end of the OnBeforePrint
subroutine:
Dim i
Dim dDate
'Store the date, shift and % OEE to an array for
graphing later
'The array and index are provided as global
variables via an external
class
'
DataArray3(10000,10,10)
use array #3
'
DataIndex(10)
use index #0
i = [Link](0)
dDate = FormatDateTime([Link])
objReport.DataArray3(i,0,0) = Day(dDate) &
MonthName(Month(dDate),True) &
Right(Year(dDate),2) 'ddMmmYY
objReport.DataArray3(i,1,0) =
[Link]
'Shift ID
objReport.DataArray3(i,2,0) =
[Link] 'Utilization
objReport.DataArray3(i,3,0) =
[Link] 'Performance
objReport.DataArray3(i,4,0) =
[Link] 'Quality
objReport.DataArray3(i,5,0) =
[Link]
'OEE
[Link](0) = i + 1
Wonderware Factelligence Report Designer
Charting and Testing Using Manager
63
We now have the data in the array and next we need to add
script to extract this data into the chart.
Select the gfEntity section and open the Scripting Editor.
Add the following script:
Sub OnBeforePrint
Dim i, iSamples
'Process data to chart for display
'First determine how many data entries there are
(X axis)
iSamples = 0
Do While Not
IsEmpty(objReport.DataArray3(iSamples,0,0))
iSamples = iSamples + 1
Loop
'Now setup the chart
With [Link]("gfEntity").Controls("chtOEE")
'Set the chart title to reflect the entity
name
.Title = [Link] & " OEE Trend
Chart"
'Process the array into the graph data grid
.RandomFill = False
'Redimension the data grid to reflect correct
number of rows
.RowCount = iSamples
.ColumnCount = 4
'Add the data
For i = 0 to iSamples - 1
.Row = i + 1
'Create string of shift and date for the
X axis label
.RowLabel = objReport.DataArray3(i,1,0)
& " " &
objReport.DataArray3(i,0,0)
.Column = 1
'Utilization
.Data = objReport.DataArray3(i,2,0)
.Column = 2
'Performance
.Data = objReport.DataArray3(i,3,0)
.Column = 3
'Quality
.Data = objReport.DataArray3(i,4,0)
.Column = 4
'OEE
.Data = objReport.DataArray3(i,5,0)
Next
End With
'Clear the data array ready for the next chart
If iSamples > 0 Then
iSamples = 0
Do While Not
IsEmpty(objReport.DataArray3(iSamples,0,0))
objReport.DataArray3(iSamples,0,0) = Empty
objReport.DataArray3(iSamples,1,0) = Empty
objReport.DataArray3(iSamples,2,0) = Empty
objReport.DataArray3(iSamples,3,0) = Empty
objReport.DataArray3(iSamples,4,0) = Empty
objReport.DataArray3(iSamples,5,0) = Empty
iSamples = iSamples + 1
Wonderware Factelligence Report Designer
64
Chapter 8 Tutorial Exercise
Loop
[Link](0) = 0
End If
End Sub
We will not discuss the scripting contents in any detail as it
is fairly straightforward.
Save the report and run it in Manager. You will now see that
the charts will display the actual data for each entity.
Tip Scripting errors may or may not generate an error message
when the report is run in Manager. Signs of scripting errors may
include charts showing the message Not Enough Data or reports
only displaying the first page (scripting errors can cause the
report to stop processing). Ways to debug script include placing
progress message prompts in the script or to comment out the
script and uncomment sections progressively until the bug is
found.
Adding a Table of Contents
As a finishing touch we will add a Table Of Contents to the
report to allow the user to easily page through the charts.
The TOC is an inbuilt feature of the Active Reports
environment and is easy to script to.
Select the gfEntity section and open the Script Editor. Add
the following script to the end of the OnBeforePrint
subroutine.
'Add a Table of Contents entry for the chart
[Link] "Charts" & "\" & [Link]
For each entity this will add a node to a TOC tree that will
display with the report. The entry will have a root node of
Chart and then a branch named after the entity.
The syntax for adding nodes is:
[Link] ROOTNODE & \ (starts a child branch) &
NODENAME & \ (for another level) and so on
Save the final version of the report and run it in Manager.
Wonderware Factelligence Report Designer
Charting and Testing Using Manager
65
Figure T23 - Finished Report
Wonderware Factelligence Report Designer
66
Chapter 8 Tutorial Exercise
Wonderware Factelligence Report Designer
67
Chapter 9
Scripting and Charts
It is not within the scope of this document to provide an in
depth discussion on scripting. Rather a number of examples
of the use of scripting within the system reports will be
explained here to provide a guide to the user.
You are encouraged to review the tutorials included in the
Active Reports User Manual (downloadable from the website
[Link]).
General
VB Script is available for use within the report to provide for
more complex data manipulation than is available using the
standard properties of text field objects and section grouping.
Script is associated with each defined section within the
report and will run as each section is processed.
During processing, a report will:
Process the records in the applied/generated recordset
one at a time in the order they appear in the recordset (ie:
first to last).
Start with the outermost group header defined in the
report. If the defined group field has changed then create
a new group header at this level.
Populate section objects such as text fields with data.
Run the associated script associated with the section.
Work through the groups to the detail section as
required.
Wonderware Factelligence Report Designer
68
Chapter 9 Scripting and Charts
Format the pages for display.
Display the report.
Adding Script
When in the Report Designer and following the creation of
the basic report (grouping, text fields, etc) you can select the
View Script icon in the menu bar.
The script window that opens is very similar to a standard
VB script window. You select the Object (report section)
and then scripts within the appropriate Event within that
section.
Tip It is always good practice to reuse code that you know works
well. Use the scripting editor to cut and paste code from like
reports.
Figure 5 - Script Editor
Simple Report with Chart
We will now look at examples of scripting and charting using
the Utilization Analysis report. This report file can be
found at
\Factelligence\Manager\Reports\System\Utilization\Util
[Link]
Wonderware Factelligence Report Designer
Simple Report with Chart
69
Virtual Fields
Used to create calculated fields in the records of the recordset
as they are read by the report.
Object : ActiveReports Document
This section contains events for the report as a whole.
Event : OnDataInitialize
This is triggered before the recordset is processed and in
this case is used to define virtual fields that are created
as the data is processed. This allows us to add extra
calculated fields to each record for later display or
grouping.
Here we see the following code:
'Create the virtual fields
[Link] "run_time"
[Link] "down_time"
[Link] "stop_time"
[Link] "total_time"
Event : OnFetchData
This is triggered as each record in the recordset is
processed and in this case is used to set the values of the
virtual fields that were defined.
Here we see the following code:
'As data is read, populate the virtual fields
'Generate runtime field
If [Link]("runtime").Value Then
[Link]("run_time").Value =
[Link]("duration").Value
[Link]("stop_time").Value = "0"
[Link]("down_time").Value = "0"
Else
[Link]("run_time").Value = "0"
'Generate downtime field
If [Link]("downtime").Value Then
[Link]("down_time").Value =
[Link]("duration").Value
[Link]("stop_time").Value = "0"
Else
[Link]("down_time").Value = "0"
'Generate stoptime field
[Link]("stop_time").Value =
[Link]("duration").Value
End If
End If
'Generate totaltime field
[Link]("total_time").Value =
[Link]("duration").Value
As we can see, the database includes the fields
duration, runtime and downtime. The combination
of runtime and downtime flags determines whether the
duration is to be classed as runtime, downtime or stopped
Wonderware Factelligence Report Designer
70
Chapter 9 Scripting and Charts
time. It is easier for reporting to do this classification at
this stage than to do it each time these values are
required to be displayed in the report.
Calculated Fields
Calculating values prior to display using textboxes.
Object : ghTotal
This script executes for the Total group header section.
This section will appear once at the start of the report.
Event : OnBeforePrint
This event fires when all data objects in the section have
been populated and section formatting is complete before
the section is finalized for printing.
The script here creates the report totals for display.
Here we see the following code:
'Calculate the % Utilization
If [Link] + [Link]
<> 0 Then
[Link] =
[Link] / _
([Link] +
[Link])
Else
[Link] = 0
End If
Here we calculate the % Utilization value as per the
standard OEE formula.
If you go to this report section and drag the section border
down you will find 3 hidden text field objects which are
responsible for summing the runtime, downtime and
stoptime virtual fields for this group (ie: the totals of each
field). These objects are then referenced by the script
which calculates the % Utilization and applies it to the
text field object for display.
Wonderware Factelligence Report Designer
Simple Report with Chart
71
Formatting Fields
Changing the format and / or visibility of data based on
calculated values.
Object : ghStateCode
This script executes for the StateCode group header
section. This section will appear once for each unique
state code that exists in the recordset.
Event : OnBeforePrint
The script in this event is used to format values for
display
Here we see the following code:
'Convert times in seconds to hh:mm:ss format
[Link] =
FormatTime([Link])
'Do not display zero values
If [Link] = 0 Then
[Link] = ""
End If
The text field objects on the screen provide the group
summing of the runtime, downtime, stoptime and
totaltime fields for the state code. Here we use scripting
to apply our own custom format to the displayed value.
We take the objects raw data value and format it to
HH:MM:SS and set the objects text value to this, while at
the same time not displaying any zero values.
Simple Charting
The chart object used in the reports was chosen based on
ease of use. It is the First Impressions chart (by Tidestone
Technologies). The user is free to use any charting ActiveX
control in the reports.
To insert the chart control, or any other ActiveX control,
simply click on the ActiveX Control icon on the toolbar on the
left side of the designer, select the control from the list, and
then drag a box in the appropriate report section.
Wonderware Factelligence Report Designer
72
Chapter 9 Scripting and Charts
Figure 6 - Inserting a Chart Control
Prior to writing any report script for the chart, the basic characteristics
should be set up using the Chart Designer and Set Chart Data
property boxes provided with the control. Simply right click on the
chart to select either of these.
Figure 7 - Chart Designer Dialog
The Chart Designer allows the user to set the type and
appearance of the chart. The chart draws its data from an
internal data grid and this can also be populated at design
time using Set Chart Data So by setting these at design
time you can set what the chart will look like and test data
values in the chart.
Wonderware Factelligence Report Designer
Simple Report with Chart
73
Figure 8 - Set Chart Data Dialog
At runtime the chart will, by default, display as it was setup
at design time. Both the appearance and data can then be
changed at runtime via script. Most commonly, as in this
case, we change the data at runtime by re-populating the
rows and columns of the charts data grid.
Object : gfTotal
This script executes for the Total group footer section
where the chart is located. This section will only appear
once at the end of the report.
Event : OnBeforePrint
The script is used to pass the report totals to the chart for
display. The chart could just have easily been put in the
Report Footer section.
Here we see the following code:
'Pass data to the By Category chart
intTotalTime = [Link] +
[Link] _
+ [Link]
intPercRuntime =
([Link]/intTotalTime) *
100
intPercDowntime =
([Link]/intTotalTime) *
100
intPercStoptime =
([Link]/intTotalTime) * 100
With
[Link]("gfTotal").Controls("graFIByCategory")
.[Link] 1, 1, intPercRuntime, False
.[Link] 1, 2, intPercDowntime, False
.[Link] 1, 3, intPercStoptime, False
Wonderware Factelligence Report Designer
74
Chapter 9 Scripting and Charts
End With
Note the way that the graph object is referenced in the
script:
[Link](SectionName).Controls(ControlName)
The required data for the chart is entered by populating
the data grid rows and columns using the method:
.[Link] <row>, <column>,
<value>
Displaying the Date
Used in the Page Footer section of all system reports.
Object : PageFooter
This script executes for the Page group footer section.
This section will appear once at the end of each page.
Event : OnBeforePrint
The script here will apply todays date to a text field
object for display.
Here we see the following code:
'Set the report date
[Link] = Date
Displaying the Filter Information and Custom
Parameters
All the system reports supplied with Factelligence include
this code in the Report Footer section. It is used to display
the filters that were applied to the report when selected to
run in the Manager module.
Each report that wants to display this information must
include the following:
This script as it appears in this section
The display objects as they appear in this section
When the Manager client wishes to run a report is calls a
URL on the Web Server with the required parameters for
that report, including the selected filters. The syntax for this
is:
[Link]
ame2>$<val3>;..
Wonderware Factelligence Report Designer
Report with Complex Graph
75
When the report is run by Factelligence it passes this filter
string to the field txtFilters which is a hidden text field in
the Report Footer section. The script in this section then
parses this string and extracts individual filter values for
display by type.
All system reports also include a hidden text field labeled
txtParameters in the Report Header section. This is
available for the user to pass any additional information they
require to display in the report. The parameter string needs
to be embedded in the call to the URL from the client in a
similar way to the filters.
ie:
[Link]
r string>
When the report is run by Factelligence it passes this
parameter string to the field which can then be processed
using script.
This feature is used by some reports that wish to display
descriptions for filter values rather than the IDs that are
passed in the filter string. These descriptions are appended
to any user specified parameter string with the syntax:
&Parameter=<user defined
string>;Filter=<filtername1>$<desc1>,<desc2>;
The script in the Report Footer section looks for this when it
is displaying the filter information.
Object : ReportFooter
This script executes for the report footer section. This
section will appear once at the end of the report.
Event : OnBeforePrint
The script is used to display the filter information that
was applied to the report.
You are encouraged to inspect the code but as it is a large
section of code it has not been included here.
Report with Complex Graph
We will now look at an example of a more complex graph
using the Downtime Analysis report. Only the graphing
component of this report will be discussed.
This report file can be found at:
\Factelligence\Manager\Reports\System\Downtime\
[Link]
Wonderware Factelligence Report Designer
76
Chapter 9 Scripting and Charts
The graph example discussed in the previous section is fairly
simple. All the required data can be totaled in the section
where the graph is located and then applied to the graph.
If however we had wished to graph the totals for each state
code ie StateTotal then we would need some way of storing
the group totals as they are calculated (for an initially
unknown number of groups) and then applying them to the
chart once the report finished processing the data. This
effectively requires the declaration and use of global
variables (ie: variables that can span all sections).
Unfortunately, global variables cannot be defined inside the
reports scripting environment. However Active Reports
provide a mechanism whereby the report processing engine
can access an external object for use within the reports
scripting. To this effect, Factelligence provides a class
containing a number of variant arrays that can be used by
any report. These arrays are referenced by the Web Server
when running the report and appear as global variables to
the report script. The user need only know how to reference
these arrays in the script and nothing more. These arrays
should cater for any foreseeable charting or other
requirements but can be enhanced if required.
Saving Data to Global Variables
As data is grouped and processed then save it away for later
use.
Object : ghReasGrp
This script executes for the ReasGrp group header
section. This section will appear once for each unique
downtime reason group.
Event : OnBeforePrint
The script in this section is used, among other tasks, to
save the reason group description, duration and
frequency to a global array variable.
Here we see the following code:
'Store the duration value for the reason group to an
array for
graphing later
'The array and index are provided as global
variables via an
external class
'
DataArray1(100,100,100)
use array #1
'
DataIndex(10)
use index #0
intIndex = [Link](0)
objReport.DataArray1(intIndex,0,0) =
[Link]
objReport.DataArray1(intIndex,1,0) =
[Link]
Wonderware Factelligence Report Designer
Report with Complex Graph
77
objReport.DataArray1(intIndex,2,0) =
[Link]
[Link](0) = intIndex + 1
The external object holding the arrays is always
referenced as objReport. The available arrays for use
are:
DataArray1(1000,100,10)a 3D variant array
DataArray2(1000,100,10)a 3D variant array
DataArray3(10000,10,10)a 3D variant array
DataIndex(10)a 1D variant array
In the code above we are using the first array and storing
the reason group description, duration and freq values.
The duration and freq values are summed for the group
by text field objects. The index keeps track of the number
of groups we end up with and maintains a pointer into
the array.
A similar process occurs in the ghReas section for
reason related data. There we use the second data array
and index.
Applying Global Data to the Chart
When data processing is complete apply the saved data to the
chart.
Object : gfTotal
This script executes for the Total group footer section.
This section will only appear once at the end of the
report.
Event : OnBeforePrint
The script is used to pass the report totals to the chart for
display. The chart could just have easily been put in the
Report Footer section.
Here we see the following code:
'Process the reason groups data
'First sort the data in descending order of duration
'as we require a Pareto graph
SortReasGroupData()
'Apply the data to the graph
With
[Link]("gfTotal").Controls("graFIReasGrpDur")
.Column = 1
For i = 0 to 9 'Max of 10 groups
.Row = i + 1
If Not
IsEmpty(objReport.DataArray1(i,0,0)) Then
.RowLabel =
objReport.DataArray1(i,0,0)
Wonderware Factelligence Report Designer
78
Chapter 9 Scripting and Charts
.Data = objReport.DataArray1(i,1,0)
/ 60
'Duration in minutes
intNumGrps = intNumGrps + 1
End If
Next
'If less than 10 groups then delete unused
bargraphs
If intNumGrps < 10 Then
.[Link] intNumGrps + 1, 10 intNumGrps
End If
End With
The concept of this script is similar to the simple chart
example discussed previously. The data from the global
array is used to re-populate the data grid for the chart.
There are a few additional things to note here:
The row labels in the data grid are also populated
with the group descriptions
We are displaying a top ten pareto here so the data
must be sorted in descending order of duration. To
achieve this we use a standard Shell Sort algorithm.
Then we limit the graph to the first ten.
Previewing Reports with Charts
Remember from the Reporting Mechanism section that
when the Preview tab is selected the report that is in the
Design tab runs directly against the database using the
query in the ADO object to generate the recordset for the
report. It does not access the middleware or the Web Server
so therefore the global variable arrays are not available
to any reports previewed in the Report Designer
application.
So, the chart in the Utilization Analysis will display correctly
in the Report
Designer preview as it does not use the global variables.
However, the Downtime Analysis report chart will not run
correctly. It will display the default data it was configured
with and a script error will be displayed when previewed.
If you are designing a report using the global variables then
you can only test it in the Manager application. So, build the
basic report first and then configure the query and the
report. Now use Manager to preview the report each time
modifications are made.
This is not optimal and it is planned to put a Test via
Middleware feature in a future release of Report Designer.
Wonderware Factelligence Report Designer
79
Appendix A
Report Spec Sheet
Created by: Grant Kelly
Last Updated: 28 June 2004
Description
The report will retrieve all OEE data from the tpm_stat table
where shift_start time falls in the selected period and for the
selected entities or shifts (if any are selected else for all
entities and shifts).
Data will be tabular with a section for each entity then
grouped by date and shift. Each row (one row per date/shift)
will show the following data:
Date & shift
% Utilization over the selected period
% Performance over the selected period
% Quality over the selected period
% OEE over the selected period
There will be a chart for each entity of all OEE KPIs vs
Date/shift. The chart will include a table of contents to allow
easy scrolling through the charts.
The report is a generic report in that any time period,
entities or shifts may be selected.
Industrial Application Server Users Guide
80
Appendix A Report Spec Sheet
Configuration
Report Category:OEE
Report Name:
OEE By Shift Trend
Report Description: Data and trend of OEE KPIs by shift
for selected entities and shifts
Report Path: [Link]
Data Query: OEE Reports
Filter: Start_Time, End_Time, Entity, Shift, Custom
Sort Fields: ent_id, shift_start DESC
Custom Filter:
Query
Query Name: OEE Reports
Query:
SELECT tpm_stat.ent_id
,ent.ent_name
,tpm_stat.wo_id
,wo.wo_desc
,tpm_stat.oper_id
,tpm_stat.seq_no
,job.act_start_time
,job.act_finish_time
,job.batch_size
,tpm_stat.shift_start
Industrial Application Server Users Guide
81
,tpm_stat.shift_id
,shift.shift_desc
,tpm_stat.item_id
,item.item_desc
,[Link]
,tpm_stat.qty_good
,tpm_stat.qty_reject
,tpm_stat.std_prod_rate
,tpm_stat.runtime
,tpm_stat.downtime
,tpm_stat.idletime
FROM tpm_stat tpm_stat with (nolock)
INNER JOIN ent ent with (nolock) ON tpm_stat.ent_id =
ent.ent_id
LEFT OUTER JOIN wo wo with (nolock) ON
tpm_stat.wo_id = wo.wo_id
LEFT OUTER JOIN job job with (nolock) ON
tpm_stat.wo_id = job.wo_id AND tpm_stat.oper_id =
job.oper_id AND tpm_stat.seq_no = job.seq_no
INNER JOIN shift shift with (nolock) ON
tpm_stat.shift_id = shift.shift_id
LEFT OUTER JOIN item item with (nolock) ON
tpm_stat.item_id = item.item_id
WHERE (tpm_stat.shift_start >= @Start_Time OR
@Start_Time IS NULL) AND
(tpm_stat.shift_start < @End_Time OR @End_Time IS
NULL) AND
(tpm_stat.ent_id IN @Entity) AND
(tpm_stat.item_id IN @Item) AND
(tpm_stat.wo_id IN @Work_Order) AND
(tpm_stat.shift_id IN @Shift) AND
(@Custom)
Parameters:Start_Time(Datetime)
End_Time(Datetime)
Entity(String List)
Item(String List)
WorkOrder(String List)
Industrial Application Server Users Guide
82
Appendix A Report Spec Sheet
Shift(String List)
Custom(Custom)
Industrial Application Server Users Guide
83
Index
Adding Script 68
Aim 5, 10, 18, 21, 27
Assumptions 5
General 67
C
Charting and Testing Using Manager 56
Adding a Table of Contents 64
Chart Data and Formatting 56
Scripting Data to a Chart Using Global
Arrays 62
Configuration 15
Content 5
Custom Filter 21
D
Data Query 21
H
How to Use this Guide 5
I
Introduction 5
M
Manager 14
Method 10, 18, 21, 27
O
Overview 32
P
Previewing Reports with Charts 78
Exercise 1 - The Design Tab 10
Exercise 2 - The Preview Tab 18
Exercise 3 - The Configuration Tab 21
Exercise 4 - The Query Tab 27
Filter 21
Queries 25
Query and Data Design 33
Query Parameters 26
Reference Material 6
Report Configuration 19
Report Design and Data Validation 36
Wonderware Factelligence Report Designer
84
Index
Adding Groups and Data Display
Objects 46
Changing Properties 39
Complex Data Display Concepts 47
Creating Virtual Data Fields 49
Formatting 44
Grouping 42
Scripting Calculations 52
Summation Objects 50
The ADO Data Object and Data
Fields 40
The Design Tab 36
Using the Report Template 37
Report Designer 13
Report Design 9
Report Preview 17
Report with Complex Graph 75
Applying Global Data to the Chart 77
Wonderware Factelligence Report Designer
Saving Data to Global Variables 76
Report with Complex Graph 75
Reporting Mechanism 13
S
Scripting and Charts 67
Simple Report with Chart 68
Calculated Fields 70
Displaying the Date 74
Displaying the Filter Information and
Custom Parameters 74
Simple Charting 71
Virtual Fields 69
Sort Fields 21
Specification 32
T
Tutorial Exercise 31