Ibm Redbook - Db2 Web Query
Ibm Redbook - Db2 Web Query
Hernando Bedoya Robert Andrews Gene Cobb Tyler Even Jackie Jansen Linda Swan
ibm.com/redbooks
7214edno.fm
International Technical Support Organization Getting Started with DB2 Web Query for i December 2009
SG24-7214-01
7214edno.fm
Note: Before using this information and the product it supports, read the information in Notices on page xi.
Second Edition (December 2009) This edition applies to IBM i 6.1 (product number 5761-SS1). This document created or updated on December 17, 2009.
Copyright International Business Machines Corporation 2009. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
7214edno.fm
iii
7214edno.fm
iv
7214TOC.fm
Contents
Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The team that wrote this IBM Redbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Become a published author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comments welcome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii xiv xvi xvi
Summary of changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix December 2009, Second Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Part 1. Background, installation, and setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1. Product architecture and overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 Query/400: A product history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2 Introduction to DB2 Web Query for i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.3 Synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 DB2 Web Query features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.4.1 Base features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.4.2 Optional features available from IBM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.4.3 Companion products available from IBM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.5 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.5.1 Web browser clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.5.2 Web server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.5.3 Application server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.5.4 Reporting Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.5.5 Data adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.6 DB2 Web Query Developer Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.7 DB2 Web Query product positioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.8 Request for changes on Web Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Chapter 2. Installation and server operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1 Installation and setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Installing DB2 Web Query. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Authorizing and verifying users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.3 License keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.4 Dynamic Language Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.5 Sample Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.1 PC requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.2 System i requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.3 Developer Workbench requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Web Query Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 DB2 Web Query server jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3. DB2 Web Query fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.1 Types of DB2 Web Query users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Licensing DB2 Web Query users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.1 Comparing the licensing options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 18 18 19 19 20 20 20 20 21 21 22 22 25 25 26 26
7214TOC.fm
3.3 Registering named users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.1 Adding a New User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.2 Removing a DB2 Web Query registered User . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.3 Displaying registered users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4 Logging in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5 Administrator tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5.1 DB2 Web Query domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5.2 Creating subfolders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5.3 Assigning authority to users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.6 Developer tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.6.1 Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.6.2 Setting up a cross-system join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.6.3 Segmenting and securing Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.7 Basic user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28 29 29 29 29 31 31 34 35 43 45 72 79 85
Part 2. Tutorials for DB2 Web Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Chapter 4. Getting started with the tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Chapter 5. Report Assistant. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.1 Tutorial overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.2 Report creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.2.1 Creating a summary report (RA1_Revenue). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.2.2 Defining a report layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.2.3 Sum and detail reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5.2.4 Date formatting (RA2_XTab). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 5.2.5 Selection criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 5.2.6 Cross-tab report (RA2_XTab) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 5.2.7 Creating a sample detail report (RA3_GP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 5.2.8 Conditional styling (traffic lighting) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 5.2.9 Using variables in report headings and footings . . . . . . . . . . . . . . . . . . . . . . . . . 120 5.2.10 Generating subtotals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 5.2.11 Sorting by an aggregate field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 5.2.12 Adding ranking columns (RA4_Advanced) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 5.3 Output options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 5.3.1 On-demand paging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 5.3.2 PDF output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 5.3.3 Excel output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 5.3.4 DB2 database file output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 5.4 Additional report types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 5.4.1 Parameterized reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 5.4.2 Drill-down reports: Parent report (RA5_Child) . . . . . . . . . . . . . . . . . . . . . . . . . . 138 5.4.3 Report properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 5.5 Joining tables (reference only) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 5.6 Creating a report over a stored procedure synonym. . . . . . . . . . . . . . . . . . . . . . . . . . 144 5.7 Report Assistant summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Chapter 6. Graph Assistant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1 Tutorial overview: Bar chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Creating a simple bar chart with drill-down capabilities (GA1_Bar) . . . . . . . . . . . . . . 6.2.1 Adding multiple bars to one chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.2 Adding a drill down to a chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3 Creating a dual axis bar and line chart (GA2_Parm) . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.1 Adding a second Y axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi
Getting Started with DB2 Web Query for i
7214TOC.fm
6.4 Creating a revenue trend over time chart (GA3_Line) . . . . . . . . . . . . . . . . . . . . . . . . 6.5 Creating a line graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.5.1 Adding a date range filter to a line graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.5.2 Adding a user-specified date range parameter . . . . . . . . . . . . . . . . . . . . . . . . . . 6.6 Working with pie charts (GA4_Pie) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.7 Creating a product type pie chart for each year . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.8 Conditional styling or traffic lighting a graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 7. Power Painter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1 Tutorial overview (PP1_PDF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Launching Power Painter and tailoring the main window . . . . . . . . . . . . . . . . . . . . . . 7.3 Building a graph with Power Painter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4 Building a report with Power Painter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5 Adding an image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.6 Building a gauge chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
167 169 176 181 184 184 190 197 198 198 201 209 218 220
Part 3. Tutorials for DB2 Web Query optional features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Chapter 8. Active Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.1 Overview and highlights of Active Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2 Creating a report with Active Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.3 Using an Active Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 230 231 235 247
Chapter 9. Developer Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 9.1 Configuring Developer Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 9.2 Setting Developer Workbench default options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Chapter 10. Online analytical processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1 OLAP terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2 Defining OLAP metadata using Developer Workbench . . . . . . . . . . . . . . . . . . . . . . 10.3 Enabling an OLAP report (OL1_Revenue) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.4 Working with an OLAP-enabled report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.4.1 Slicing, dicing, and drilling down for more details . . . . . . . . . . . . . . . . . . . . . . . 10.4.2 Manipulating the data using the OLAP Control Panel. . . . . . . . . . . . . . . . . . . . 10.4.3 Grouping data into percentiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 11. HTML Composer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1 Compound parameterized report (HTML1_KPI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1.1 Adding parameters to existing reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1.2 Designing the layout for the HTML report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Highly parameterized report (HTML2_Parm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.1 Creating the report in HTML Composer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.2 Additional parameter tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 12. Additional features of Developer Workbench . . . . . . . . . . . . . . . . . . . . . 12.1 Synonym Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.1 Date Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.2 Additional date manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.3 Creating filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.4 Joining tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.5 Business View. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.6 Impact Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.7 Data profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2 SQL Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents
257 258 259 266 268 268 279 286 289 290 290 296 305 308 327 343 344 348 350 352 354 361 363 366 369 vii
7214TOC.fm
12.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 Chapter 13. DB2 Web Query Spreadsheet Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2.1 Predefined Server configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.3 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.3.1 Report Assistant mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.3.2 Structured Ad-Hoc Form mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.4 Dashboards in Excel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.5 Data Range Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.6 Spreadsheet Client Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 14. Adapter for Microsoft SQL Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.2 Establishing a connection to your MS SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . 14.3 Creating Metadata. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.4 Additional SQL Server Adapter information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 378 378 378 379 379 380 381 382 382 383 384 384 387 390
Part 4. Companion products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 Chapter 15. Report Broker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.1 Tutorial Overview and preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.2 Installing and Configuring Report Broker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3 Schedule an existing report. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.4 Scheduling Frequency options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.5 Creating a Report Broker distribution list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.6 Busting a Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.7 Viewing the Distribution log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.8 Report Broker and Highly Parametrized reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.9 Report Broker Administrator functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.10 Report Broker and Active Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.11 Report Broker and RunTime User Enablement . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.12 Event driven distribution request via RUNBRSCHED . . . . . . . . . . . . . . . . . . . . . . . 15.13 Report Broker Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 16. Software Development Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.1 Overview of the Software Development Kit (SDK) . . . . . . . . . . . . . . . . . . . . . . . . . . 16.2 Uses of the Web Query SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.3 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.4 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.4.1 Core APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.4.2 Report Broker APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.4.3 Sample code path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16.4.4 Samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 394 394 397 402 405 407 410 411 412 415 415 416 416 417 418 418 419 419 419 420 420 420
Part 5. Miscellaneous or additional topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 Chapter 17. Using DB2 Web Query to run existing Query/400 reports . . . . . . . . . . . 17.1 Query/400: A reliable reporting tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.2 DB2 Web Query versus Query/400: Function similarities . . . . . . . . . . . . . . . . . . . . . 17.3 DB2 Web Query versus Query/400: Function differences . . . . . . . . . . . . . . . . . . . . 17.4 Creating metadata from Query/400 objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.5 Using DB2 Web Query to edit a QRYDFN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 428 428 429 430 433
viii
7214TOC.fm
Chapter 18. Performance considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1 Performance basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2 DB2 CLI adapter performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2.1 Report request process flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2.2 Adapter processing and optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2.3 Remote database access considerations (including cross-system joining) . . . 18.3 Query/400 adapter performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4 DB2 for i optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.1 Database design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.2 Query Engine used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.3 Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.4 Available hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.5 Concurrent users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.5 Performance case study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.5.1 Identifying a long running report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.5.2 Performing analysis and looking for optimization disablers . . . . . . . . . . . . . . . 18.5.3 Determining report tuning options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.5.4 Creating an SQL view and synonym. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.5.5 Creating a new report based on the SQL view . . . . . . . . . . . . . . . . . . . . . . . . . 18.5.6 Performing additional database analysis and tuning. . . . . . . . . . . . . . . . . . . . . 18.6 Performance benchmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.6.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.6.2 Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.6.3 Database and system configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.6.4 Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.6.5 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 19. Frequently Asked Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.1 General announcement or product information questions . . . . . . . . . . . . . . . . . . . . 19.2 Installation and setup questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.3 Security-related questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.4 Named-user question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.5 Metadata questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.6 Query/400 migration questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.7 Report development questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.8 Excel spreadsheet integration questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.9 Add-on product questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.10 Save and restore questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.11 Education questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
435 436 436 436 438 448 450 451 451 452 461 462 465 466 466 466 468 468 470 472 474 474 474 475 475 478 479 480 484 484 486 486 489 490 499 501 504 506
Part 6. Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 Appendix A. Metadata in the integrated file system . . . . . . . . . . . . . . . . . . . . . . . . . . 511 Appendix B. ate and time functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Date and time system variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Date format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Date format display options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Controlling the date separator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using date fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Date fields in arithmetic expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Converting date fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Changing the usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using DB2 Web Query functions to convert to dates . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents
513 514 514 514 516 516 516 517 518 521 ix
7214TOC.fm
Using date conversion table to convert to dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using SQL Views and functions to convert to dates . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparing the date conversion techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Converting date fields in Oracles JD Edwards World application . . . . . . . . . . . . . . . . Converting other common legacy date formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DB2 Web Query date built-in functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DATEADD: Adding or subtracting a date unit to or from a date . . . . . . . . . . . . . . . . . . DATEDIFF: Calculating the difference between two dates . . . . . . . . . . . . . . . . . . . . . . DATEMOV: Moving the date to a significant point . . . . . . . . . . . . . . . . . . . . . . . . . . . . Example: Dynamic Date Range report. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
526 548 551 552 554 555 555 556 556 557
Appendix C. Processing differences between the define and compute fields . . . . . 563 Appendix D. Change Management considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 565 Developer Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566 Without Developer Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566 Appendix E. Additional material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Locating the Web material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the Web material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System requirements for downloading the Web material . . . . . . . . . . . . . . . . . . . . . . . How to use the Web material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Related publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IBM Redbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Online resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to get IBM Redbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Help from IBM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569 569 569 569 570 571 571 571 571 572
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
7214spec.fm
Notices
This information was developed for products and services offered in the U.S.A. IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to evaluate and verify the operation of any non-IBM product, program, or service. IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to: IBM Director of Licensing, IBM Corporation, North Castle Drive, Armonk, NY 10504-1785 U.S.A. The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk. IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you. Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental. COPYRIGHT LICENSE: This information contains sample application programs in source language, which illustrate programming techniques on various operating platforms. You may copy, modify, and distribute these sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.
xi
7214spec.fm
Trademarks
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both. These and other IBM trademarked terms are marked on their first occurrence in this information with the appropriate symbol ( or ), indicating US registered or common law trademarks owned by IBM at the time this information was published. Such trademarks may also be registered or common law trademarks in other countries. A current list of IBM trademarks is available on the Web at http://www.ibm.com/legal/copytrade.shtml The following terms are trademarks of the International Business Machines Corporation in the United States, other countries, or both:
AS/400 DB2 developerWorks Domino i5/OS IBM iSeries Lotus OmniFind Rational Redbooks Redpaper Redpapers Redbooks (logo) System i5 System i WebSphere
The following terms are trademarks of other companies: Acrobat, Adobe Reader, Adobe, PostScript, and Portable Document Format (PDF) are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, other countries, or both. Oracle, JD Edwards, PeopleSoft, Siebel, and TopLink are registered trademarks of Oracle Corporation and/or its affiliates. J2EE, Java, JavaScript, JavaServer, JDBC, JVM, and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. ActiveX, Excel, Expression, Internet Explorer, Microsoft, MS, PowerPoint, SQL Server, Windows Vista, Windows, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. Pentium, Intel logo, Intel Inside logo, and Intel Centrino logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
xii
7214pref.fm
Preface
The DB2 Web Query for i product is a Web-based query and report writing product that offers enhanced capabilities over the IBM Query for iSeries (also commonly known as Query/400) product. IBM DB2 Web Query for i includes Query for iSeries technology to assist customers in their transition to DB2 Web Query. It offers a more modernized, Java-based solution for a more robust, extensible, and productive reporting solution. DB2 Web Query provides Report Assistant, Graph Assistant, and Power Painter. Using these tools, customers can modernize existing Query for iSeries reports while providing a foundation for building more complex business intelligence applications, such as online analytical processing (OLAP), data mining, dash boarding, or data warehouse implementations. DB2 Web Query provides capabilities to query or build reports against data that is stored in DB2 call-level interface (CLI) databases through the latest browser-based user interface technologies. It enables you to build new reports with ease through the Power Painter or Report Assistant and Graph Assistant components. It simplifies the management of reports by allowing you to leverage parameterized reporting. It delivers data to users in many different formats, including spreadsheets, PDF, HTML or through browser support of the Java-based thin client interface. DB2 Web Query offers features to import Query/400 definitions and enhance their look and functionality with Power Painter or Graph Assistant. It enables you to add OLAP-like slicing and dicing to the reports or to view reports in disconnected mode for users on the go. It provides an interface to all data in IBM i5/OS through either DB2 or Open Query File native adapters that automatically identify the files to be accessed and import the metadata into DB2 Web Query. This IBM Redbook publication gives a broad understanding of the new DB2 Web Query product. It entails a group of self-explanatory tutorials to help you get up to speed quickly. Overall this book is designed for IT users. You can extract and use Part 2, Tutorials for DB2 Web Query on page 87, and Part 3, Tutorials for DB2 Web Query optional features on page 227, as stand-alone tutorials for anyone who is developing their own queries. Much of Chapter 8, Active Reports on page 229, is appropriate for those who work disconnected from the System i environment. In addition, you can use much of Chapter 10, Online analytical processing on page 257, if you will simply be running OLAP-enabled reports.
xiii
7214pref.fm
Gene Cobb is a DB2 for i technology specialist in the IBM Systems Software DB2 for i Development team. He joined IBM in 1988 and spent over 10 years as an application consultant in the IBM STG Lab Services group, formerly the Client Technology Center (CTC) in Rochester, Minnesota. His current responsibilities include the promotion, education, enablement, and technical support of IBM DB2 Web Query, the strategic query and reporting solution for the IBM i platform. He speaks and writes regularly about DB2 for i and DB2 Web Query topics, and was a co-author of the IBM Redbook Getting Started with DB2 Web Query for IBM i He can be reached at [email protected].
Robert Andrews is an Advisory Software Engineer working for the STG Lab Services team in the DB2 for i Center of Excellence. He was the technical head for support for the DB2 Web Query product and currently provides custom consulting services helping clients make the most of DB2 Web Query and DB2 for i. Since joining IBM in 2001, Robert has been published in many Redbooks and trade publications with a focus on SQL, journaling, and communications. Robert can be reached at [email protected].
xiv
7214pref.fm
Linda Swan is a software developer on the DB2 for i Query Optimization component. In addition, she has spent the past year working with DB2 Web Query for IBM i. Her current responsibilities include SQE query engine optimization technique and performance on IBM i. She can be reached at [email protected].
Tyler Even is a DB2 for i5/OS Technology Specialist in STG Lab Services System i group. He currently assists customers with application/database design and development using DB2 Web Query for IBM i, DB2 for IBM i, Java/VB, WebSphere, and Lotus Domino. His current responsibilities include providing consulting services to IBM i customers with a special emphasis in DB2 Web Query for IBM i and Business Intelligence practices for IBM i. He can be reached at [email protected].
Thanks to the authors of the previous editions of this book. Authors of the first edition, Getting Started with DB2 Web Query for i, published in November 2007, were: Renee Mason Jackie Jansen Gene Cobb Thanks to the following people for their contributions to this project: Thomas Gray James Hansen Joanna Pohl-Miszczyk Jenifer Servais ITSO, Poughkeepsie Center Robert Andrews Michael Cain Fernando Echeveste Tyler Even Doug Mack Jarek Miszczyk Scott Moore Brian Muras Chuck Pence Sandy Ryan Rick Saltness Dan Toft
Preface
xv
7214pref.fm
Eric Will IBM Rochester Wilfried Blankertz IBM Germany Julie Maw IBM UK Simona Pacchiarini Francesca Zoccheddu IBM Italy Larry Eiss Robert Fricano Gary Goldberg Pat Powers Terry Schwarz Information Builders Inc. Eric J. Songy EJS IT Consulting Rosemarie Pembleton Unique Industries
Comments welcome
Your comments are important to us! We want our Redbooks to be as helpful as possible. Send us your comments about this book or other Redbooks in one of the following ways: Use the online Contact us review Redbooks form found at: ibm.com/redbooks
xvi
7214pref.fm
Send your comments in an e-mail to: [email protected] Mail your comments to: IBM Corporation, International Technical Support Organization Dept. HYTD Mail Station P099 2455 South Road Poughkeepsie, NY 12601-5400
Preface
xvii
7214pref.fm
xviii
7214chang.fm
Summary of changes
This section describes the technical changes made in this edition of the book and in previous editions. This edition may also include minor corrections and editorial changes that are not identified. Summary of Changes for SG24-7214-01 for Getting Started with DB2 Web Query for i as created or updated on December 17, 2009.
New information
Spread Sheet Client Report Broker Adapter for Microsoft SQL Server Software Development Kit
Changed information
Updated information to latest release of products More examples have been added
xix
7214chang.fm
xx
7214p01.fm
Part 1
Part
7214p01.fm
7214ch01.fm
Chapter 1.
7214ch01.fm
7214ch01.fm
Does not use the new SQL Query Engine (SQE) SQE was introduced in V5R2 of i5/OS and offers algorithms and features that give it distinct advantages over its predecessor, the Classic Query Engine (CQE). SQE is the strategic database engine, thus will receive all future enhancements. Although CQE will still be supported and maintained, IBM will not incorporate any new features into this engine. Only pure SQL requests are processed by the new engine. Because Query/400 is not an SQL interface, its query requests must be handled by the older CQE technology. For more information about SQE including its advantages over CQE, see the Preparing for and Tuning the SQL Query Engine on DB2 for i5/OS, SG24-6598. Over the years, thousands or perhaps millions of custom reports have been created using IBM Query for System i (also known as Query/400). As a result, businesses have a significant amount of investment contained throughout their systems in the query objects. Because so much has been invested in these objects, System i businesses need a way to leverage or repurpose them using a more modern reporting tool.
1.3 Synonyms
DB2 Web Query employs a data description language (DDL) that describes the necessary data elements for many types of data sources, including relational structures. Using this language, DB2 Web Query can describe i5/OS tables (physical files) or views (logical files) that have been established within the relational database system on the System i platform.
7214ch01.fm
This view of the data is a layer of abstraction that is used by DB2 Web Query for reporting and is known as synonyms or metadata. You can learn more about metadata in Creating metadata on page 47. Metadata and synonyms: The terms metadata and synonyms are used interchangeably throughout this book. They both refer to the DB2 Web Query data abstraction layer.
In addition, you can direct your DB2 Web Query report output to the traditional spooled file and database file formats. Graph Assistant: Easy report graph generation Graph Assistant is an HTML-based tool that guides you step by step through the creation of a graph. The Graph Assistant enables you to create and style your graphs. 6
Getting Started with DB2 Web Query for i
7214ch01.fm
Power Painter: What You See Is What You Get (WYSIWYG) report building Power Painter is a Web layout and report creation tool that is built by using Asynchronous JavaScript and XML (AJAX) technology. This tool enables you to create output and page layout formats. It combines reporting, graphs, and page layout design in a single tool. The framework makes Power Painter a thin-client tool that looks, responds, and performs like a Microsoft Windows-based facility. Data adapters Data adapters manage the communication between DB2 Web Query and the DB2 for i5/OS database through the use of SQL statements or other data access methods. Three adapters are provided with the base product: DB2 CLI DB2 Heritage files Query/400 For more information about each of these adapters, refer to 1.5.5, Data adapters on page 13. Runs natively on the System i platform Each server side component of the DB2 Web Query solution runs natively on the System i platform. This integrated environment equates to a more simplified environment; there are fewer servers and operating systems to set up, administer, secure, backup, and maintain. Ability to use matrix reporting, ranking, color coding, drill-down and font customization to enhance the visualization of DB2 data Federated DB2 for i5/OS data access Customers with multiple System i machines or i5/OS partitions will value the federated query capabilities of DB2 Web Query. This feature provides the ability to develop a single report against multiple DB2 for i5/OS databases. For more information about the base component of 5733-QU2, see 2.1, Installation and setup on page 18.
7214ch01.fm
While you do not need Developer Workbench to create DB2 Web Query reports, there are compelling reasons to consider using it as your report development tool. The following list includes reasons to consider such an upgrade: Dimension tool Defines hierarchies to be stored in the metadata Is a prerequisite for OLAP module Includes meaningful field names Includes multilingual titles
SQL Wizard that allows the developer to type or copy and paste SQL statements directly into the tool HTML Composer tool The powerful HTM Layout Painter tool allows you to combine reports, graphs, and other elements together in a single HTML document or layout. It provides a WYSIWYG design environment to help you create professional looking layouts that require more advanced components such as custom HTML, HTML template files, and cascading style sheets (CSS). Advanced programmer tools including: Data profiling Impact analysis Ability to change field types (including integer or alpha to recognized date fields) Automatic date decomposition
Active Reports: Offline reporting capability Many mobile workers require access to important information that is stored in their analytic reports while disconnected from the Internet. With DB2 Web Query Active Reports, such users can take the power of business intelligence with them wherever they go. By combining data and interactive controls into a single, self-contained HTML file, Active Reports delivers analytic capabilities in a completely portable and disconnected environment, with absolutely no software required. For more information about Active Reports, refer to Chapter 8, Active Reports on page 229, and refer to the following Web address: http://www.informationbuilders.com/products/webfocus/portable_analytics.html Additional named user licenses If you need more named users than the base option provides or you need more than you are currently licensed for, you can purchase additional licenses. For more details, contact your IBM representative. Run Time User Enablement For environments that have a large number of report consumers, compared to report authors, the standard named user licensing model may put Web Query out of reach. To help with this, we have developed a second licensing model. This model allows for essentially an unlimited number of report consumers. For complete details on this offering, please review the White Paper at: http://www-03.ibm.com/systems/resources/systems_i_software_db2_pdf_DB2_Web_Que ry_Run_Time_User_Enablement.pdf Spreadsheet Client While the base product has the ability to generate Microsoft Excel spreadsheets, it still requires the users to go into the Web Query product to generate the output. With this 8
Getting Started with DB2 Web Query for i
7214ch01.fm
additional feature, users simply access the power of Web Query from within Excel. There is no need to go to the web browser. While in Excel, two modes of operation are possible. If you are a report author, you can access Report Assistant within Excel to allow for the creation of reports that are put into your spreadsheet. If you are simply a report consumer, you can use the Structured Ad-hoc Forms (SAF) method. This provides the user a HTML page, like an HTML Launch Page, to pass parameters into the report. The output is then placed inside the spreadsheet. Within a single spreadsheet, you can have multiple reports saved. By saving the report definition, this allows the reports to be refreshed and sent to other users. This, along with the powerful template capabilities of Excel 2007, allow for the creation of dashboards right in Excel. With the reports created, they can be set to even automatically update the data on a set schedule. Adapter for Microsoft SQL Server While most of your data should be stored on the IBM i, we do realize that some applications require data to be stored in a Microsoft SQL Server 2000 or 2005. Just because the data is outside of the System i does not mean that it is out of reach of Web Query. With this additional feature, DB2 Web Query can integrate data stored on Microsoft SQL Server. Reports can be based solely on SQL Server data or mixed in and joined to data on your System i. Why learn two different reporting tools when Web Query can use that remote data source in an environment you will be very familiar with by the end of this Redbook!
7214ch01.fm
Feature Report Assistant Graph Assistant Power Painter Modernized output (HTML, XLS, PDF, and so on) Query/400 adapter DB2 Heritage File adapter (multi-member or multi-format files) DB2 CLI adapter (System i tables, physical files, views) DB2 for i5/OS cross-system join OLAP Developer Workbench Active Reports Additional named user licenses Report Broker Web Query Spreadsheet Client Run Time User Enablement Adapter for Microsoft SQL Server
Base offering X X X X X X X X
X X X X X X X X
10
7214ch01.fm
1.5 Architecture
Although DB2 Web Query runs natively on the System i platform, it is comprised of multiple application tiers that service different components. The overall architecture contains each of the following components: HTTP clients Web tier Application server Web server Reporting Server Data adapters Relational Database Management System (RDBMS) data DB2 for i5/OS is the integrated database for the System i platform. Other source databases can be used with the installation of the appropriate add-on adapters that are discussed earlier in this chapter. Figure 1-1 shows the overall architecture of the DB2 Web Query system.
Browser Client
IBM System i
HTTP
Reporting Server
IBM HTTP server Powered by Apache
Applet
TCP
Synonyms
Data adapters
DB Heritage Files
Query/400 Microsoft SQL Server
Application Client
QSQSRVR jobs
IFS
Application directories (domains and reports repository)
HTTP
SOAP / XML
Windows Server
Application developed using Web service language: C++, C#, VB.NET, JAVA, RPG, COBOL
To better understand the architecture, it is helpful to understand the end-to-end process and how a report request flows through the architecture. The following actions describe the life cycle of a typical DB2 Web Query request: 1. A user requests a report for execution from a Web browser.
11
7214ch01.fm
2. The Web server receives the request, processes the parameters, and routes it to the Reporting Server via the DB2 Web Query servlet. 3. The Reporting Server processes the request and passes it to the appropriate data adapter. 4. The data adapter generates the appropriate database request and submits the request to the DB2 for i5/OS database engine. 5. The Reporting Server receives the result set from the database, formats the report, and returns the formatted report to the Web server via the DB2 Web Query servlet. 6. The Web server delivers the report to the users Web browser for display.
12
7214ch01.fm
In some cases, groups multiple applications into Web Application Bundle (WAB) files Applications are grouped into the WAB file named webfocus76.wab. This WAB file is served under the context root of /ibi_apps and contains the following components: DB2 Web Query servlet DB2 Web Query API Managed Reporting API Communicates with the MR Repository (basedir) DB2 Web Query home page controller and JSPs DB2 Web Query administration console DB2 Web Query and Managed Reporting drivers Communication Drivers to DB2 Web Query server Custom DB2 Web Query exit (plug-in) Custom servlet filter (plug-in)
13
7214ch01.fm
Table 1-2 Data adapters Adapter DB2 CLI DB2 Heritage File Query/400 Data type Single member physical file; alias, stored procedure, or MQT Multiple member file, multi-record format files QRYDFN object Command sent to System i5 machine CLI API OPNQRYF RUNQRY
In addition to the three adapters that are included in the base Web Query product, we offer the optional Adapter for Microsoft SQL Server. This feature is available as a chargeable add-on to the base 5733-QU2 product. With the Microsoft SQL Server adapter, you can connect to Microsoft SQL 2000 or 2005 servers. Metadata is created the same way as in DB2. Once created, you can create reports solely against the SQL Server data or even join tables between SQL Server and DB2 on i. Learn one set of tools and use them for all of your reporting needs!
14
7214ch01.fm
15
7214ch01.fm
16
7214ch02.fm
Chapter 2.
17
7214ch02.fm
18
7214ch02.fm
Table 2-1 System objects Object name Object type *LIB *USRPRF *USRPRF *USRPRF *AUTL *JOBD MSGQ
QWEBQRY76
QSYS/QWEBQRYADM QSYS/MRADMIN QSYS/MDUNTITLED QSYS/QWEBQRY
QWEBQRY76/QWEBQRYJOB
QUSRSYS/QWEBQRYADM
These are DB2 Web Query-related user profiles: QWEBQRYADM: This profile has functionality on the server side and has authority to start and stop the Reporting Server. The profile is automatically created. MRADMIN: This group profile has the authority to create domains in DB2 Web Query. It also has the rights to create reports in all domains and folders on the system. MDUNTITLED: This group profile gives users the authority to create reports in the default common domain.
19
7214ch02.fm
Each license key is used to activate either the base product feature (5050) or one of the add on features. To enter your license keys and activate the specific features, use the ADDLICKEY command. Note: You do not have to wait for the grace period to expire before you enter your license keys. You can do this at any time.
2.2 Requirements
In this section, we cover the PC and System i minimum requirements to install and run DB2 Web Query.
2.2.1 PC requirements
No client is required to be installed on your PC to enable DB2 Web Query; you only need a browser. The browser requirements are: Internet Explorer 6.0 or later Firefox 1.5 (certified), version 2.0 (supported) If you are unsure about the version of Internet Explorer that you are using, open the browser and select Help About Internet Explorer. Note the version number.
20
7214ch02.fm
In regard to PC memory requirements, in general, queries usually run best on PCs that have 1 GB of RAM or more.
Hardware requirements
Verify that your Windows machine meets the Developer Workbench hardware requirements: Pentium 3 or later at 600 MHz or later VGA or later resolution graphics card; display of 1027x768 recommended 512 MB of RAM 500 MB free hard disk space
Software requirements
Verify that your Windows machine meets the Developer Workbench software requirements: Windows 2000, XP, or 2003 Server and Professional Editions Windows 2000 must have Service Pack 2 or later Internet Explorer 6 and later Internet Explorer components are required for Developer Workbench. If possible, upgrade to the most recent version of Internet Explorer. Adobe Acrobat Reader 6.0 and later. Acrobat Reader 6 and 7 are certified to view PDF reports generated by Developer Workbench. Note: You must be an administrator to the Windows machine to run the Developer Workbench installation.
21
7214ch02.fm
22
7214ch02.fm
HLISNK: One job which is an internal server process and runs under the user profile QWEBQRYADM. WQLWI7: This job is for integrated application server jobs. Four of these jobs should be running whenever DB2 Web Query is active (three run under the user profile QTMHHTTP, the other under profile QWEBQRYADM) QSQSRVR: This IBM i native prestart job handles SQL requests that are made over CLI. This job does the actual database work of optimization, execution, and returning the result. By default these jobs run under the user profile QUSER but when DB2 Web Query report (based on a DB2 CLI synonym) is run, a CLI connect event occurs with one of these jobs. At this point, the user profile running the job is swapped to the user profile that initiated the DB2 Web Query report request. With the exception of the WQLWI7 jobs, these jobs will run in the QSYS work subsystem. However, it is possible to customize your system such that the QSQSRVR jobs run in a different subsystem. The WQLWI7 jobs will run in the QHTTPSVR subsystem. In addition, the following jobs are started if you have the DB2 Web Query Report Broker product installed and running: STRBROKER: One job that runs under QWEBQRYADM and invokes QSHELL to run a script to start the Distribution Server. QP0ZSPWP: Two jobs that run under user profile QWEBQRYADM. One job is the JVM and the other is the console window that the Distribution Server starts up. Another way to look at the jobs is via their ports. When running, DB2 Web Query will be active on ports 11331 to 11339. When first started, ports 11336 and 11338 may not start until the first user hits the Web Query login page. Port 11339 is used for DB2 Web Query Report Broker. Therefore, if you do not have that product installed, this port will not be active. At the time of publication, port 11337 is not used. You can look at active ports by using the NETSTAT command and taking option 3. Once the display is up, use F14 to display port numbers. As you scroll down, you will see the local port column is ordered descending. Scroll down until you reach a local port of 11331 to see these connections.
23
7214ch02.fm
24
7214ch03.fm
Chapter 3.
25
7214ch03.fm
Finally, a Basic user of reports is someone who is only allowed to run reports and again, only in specifically authorized domains. A basic user can, based on how the report is defined, influence the content of the report by selecting or providing various input values to a report but cannot actually alter the definition of the report. Although a DB2 Web Query user may be an administrator, a report developer or a basic user as defined by the product, the operating system's object level security rules are still enforced when it comes to actually accessing the data related to a report. As a basic user, you may be authorized to run a report within a specific domain but if your login profile is denied access to the underlying table, view, stored procedure or Query/400 object, the report will still not run
7214ch03.fm
is exposed to.For example, in Figure 3-1 this would mean acquiring four additional user licenses for runtime users, one for each domain.
Four Domains
Figure 3-1 Example of DB2 Web Query environment with four domains
Alternatively, you could choose to put all reports under a single domain, as shown in Figure 3-2. The groups of reports could be organized in subfolders. Such an environment would require only one additional license for runtime users. While this type of implementation would effectively provide an unlimited run time (basic) user environment, it would not be as secure because all users would have access to all reports in the single domain, regardless of the subfolder they are placed in. Keep in mind that you if have in place object level security the unauthorized users can see the list of reports but they can not actually execute them.
27
7214ch03.fm
One Domain
Figure 3-2 Example of DB2 Web Query environment with one domain
Note: The maximum number of group profiles that a user profile can be a member of is 16. This is an IBM i operating system restriction and it means that, at most, a basic user could only access reports within 16 distinct domains. For more information on the Run Time User Enablement option, considerations for how many licenses are needed and whether or not this licensing option is a good fit for your environment, follow the articles link on the DB2 Web Query Getting Started page, and look for "DB2 Web Query Run Time User Enablement'. If the majority of your users are basic users that, another licensing option to consider is DB2 Web Query Report Broker, the scheduling and automated distribution product of the DB2 Web Query product suite. With Report Broker, reports and graphs can be scheduled to run in a batch mode and distributed to the target recipients via E-mail or printer. This type of push implementation means that there is an entire report user community that can have access to reports without consuming user licenses: because their reports are distributed to them via E-mail, the members of this user community would not require direct access to DB2 Web Query, and therefore would not require and consume a user license. For more information, see Chapter 15, Report Broker on page 393 licensed program product.
28
7214ch03.fm
3.4 Logging in
Regardless of the type of DB2 Web Query user you are, the process of logging in is the same. One of the many attributes of DB2 Web Query is that you do not need to install anything on your PC to use it. You only need a web browser to create and run reports. As mentioned in 2.2.1, PC requirements on page 20, DB2 Web Query supports Internet Explorer and Firefox. To log into DB2 Web Query, take the following steps: Note: In this example, the system name is MYSYSTEM.ABC.ACME.COM: 1. Enter the following internal URL: http://mysystem.abc.acme.com:11331/webquery The port number in the URL is always 11331 - this is the pre-configured port for DB2 Web Query.
29
7214ch03.fm
2. A Web page opens like the example shown in Figure 3-3. Sign onto DB2 Web Query with the same user profile and password that you use to access the IBM i machine.
If your DB2 Web Query instance was configured with Dynamic Language selection, your login will provide you with a Select Language pull down as illustrated in Figure 3. This allows you to select the language of choice. See 2.1.4, Dynamic Language Switch on page 20 on how to configure Dynamic Language selection.
Figure 3-4 DB2 Web Query signon page with Dynamic Language Selection
Upon log in, you see only the domains and menu options that you are authorized to as shown in Figure 3-5. For an explanation about domains, refer to 3.5.1, DB2 Web Query domains on
30
7214ch03.fm
page 31. If you do not see a domain that you think you should be authorized to, contact your DB2 Web Query administrator. Tip: Add your DB2 Web Query URL to your browser Favorites.
31
7214ch03.fm
The first time you open your browser to DB2 Web Query, you see only the default Common Domain folder. Inside the Common Domain folder, you see two other folders as shown in Figure 3-6: The Reports folder is where permanent report objects are displayed. Users go into this folder to find the report they want to run. Developers that are authorized to this domain can create new reports in this folder. The Other Files folder contains files like style sheets and JPG files that you might want to import into your report.
32
7214ch03.fm
associated Href. For a user to be a developer in the Common Domain (Figure 3-7), they must belong to the group MDUNTITLED. The other special prefix is that DB2 Web Query checks for MU. Having a group profile of MUUNTITLED means that the profile is a valid user in the Common Domain (Href untitled) and is allowed to run reports there but not to create them. In fact, the Common Domain is the system default and is the one domain in which you do not require an MUhref to run reports. If you are registered as a licensed user of DB2 Web Query, then you are entitled to run reports in the Common Domain by default. If you want a domain name to be greater than eight characters, first create it with a meaningful name of exactly eight characters. Then rename your domain to a desired name that is greater than eight characters. The original eight characters remain as your Href name. For example, if you want your domain to be Month End Reports, you can first create your domain as monthend. Then you can rename it to Month End Reports and your Href remains as the eight characters of monthend. Table 3-1 shows the Developer and Basic User group profiles for our example.
Table 3-1 Developer and basic user group profiles Domain name Month End Report Href name monthend Developer group profile MDMONTHEND Basic user group profile MUMONTHEND
Creating a domain
To create a domain: 1. Log on to the DB2 Web Query home page as administrator, which is a user profile that belongs to the MRADMIN group. 2. Right-click Domains and select New Domain. 3. In the New Domain window that opens, like the one in Figure 3-8, type your domain name and click Save.
4. If your domain name was shorter than eight characters, right-click your domain and select Properties in order to view what was autogenerated. Tip: Avoid using blanks or special characters in domain names, folder names, or field names within DB2 Web Query.
Chapter 3. DB2 Web Query fundamentals
33
7214ch03.fm
Renaming a domain
After creating your domain with a short name to facilitate a meaningful Href, you can then rename your domain by selecting the Properties menu option to give it a more descriptive name. Take the following steps to rename a domain: 1. Right-click the existing domain and select Properties. 2. In the Domain Properties window (Figure 3-9) that opens, in the Name field, type a preferred name over the name in the white box. After you edit the name, click OK.
34
7214ch03.fm
A DB2 Web Query administrator has two approaches to authorize developers or basic users to DB2 Web Query: a manual approach or the use of the WRKWEBQRY administration utility.
35
7214ch03.fm
Let's say the administrator just created a new domain call monthend where the hrefname for that domain is also monthend. ARCH is a developer and SHANEG is a basic user who runs read-only reports The administrator would do the following steps: 1. Log in to DB2 Web Query and creates a new domain from the DB2 Web Query home page. 2. From the IBM i command line, create two new profiles that reflect developer and user access to the domain: CRTUSRPRF USRPRF(MDMONTHEND) TEXT('Group profile for Developers of domain MONTHEND') CRTUSRPRF USRPRF(MUMONTHEND) TEXT('Group profile for Basic Users of domain MONTHEND') 3. Change the user profile of both ARCH and SHANEG, adding the domain's developer group profile to ARCH and the domain's user group profile to SHANEG. If ARCH or SHANEG already have a GRPPRF, use the supplemental group profile option, SUPGRPPRF. CHGUSRPRF USRPRF(ARCH) GRPPRF(MDMONTHEND) CHGUSRPRF USRPRF(SHANEG) GRPPRF(MUMONTHEND) 4. Register ARCH as a licensed user (only necessary if this is the first time ARCH has been authorized as a developer. You can use WRKLICINF 5733QU2, option 8 on 5050 to check). ADDWQLUSR USRPRF(ARCH) 5. If you are using Run Time User Enablement to authorize SHANEG and as you know you just created the domain, authorize MUMONTHEND as the shared license user for all basic users running reports in the MONTHEND domain. ADDWQLUSR USRPRF(MUMONTHEND) -ORIf you are not using Run Time user access then SHANEG must be explicitly licensed to use the domain. ADDWQLUSR USRPRF(SHANEG) Note: If you use the CHGUSRPRF command to change the group profile or supplemental profile parameter while a user is currently signed on to DB2 Web Query, the user must log off and back on to see the new Domain. If a user does not belong to any group profiles for a domain, the user will only be authorized run reports in the Common Domain. No other domains are visible to the user.
7214ch03.fm
To accomplish the same task as the manual steps in the previous section, you can use the WRKWEBQRY utility. Note: The WRKWEBQRY command is installed with PUBLIC *EXCLUDE, so you need *SECOFR user class or *ALLOBJ special authority to issue the command or you must be granted explicit authority to the command. If your profile is granted access to the command it will automatically adopt enough authority to complete Web Query administrative tasks such as authority to create the group profile necessary under the covers necessary to secure domains for developers or users and enough authority to alter existing user profiles to supply specify those domain specific profiles as a group profile. As with the previous example, assume that the administrator wants to create a domain called monthend and authorize ARCH as a developer and SHANEG as a basic user. Take the following steps to complete the process using WRKWEBQRY: 1. Log into DB2 Web Query as an administrator and create a new domain named monthend. 2. Sign on to a 5250 session with a user profile that has sufficient authority (as described in the call-out box above) 3. Issue the WRKWEBQRY command. The main menu is presented. This screen displays the current status of DB2 Web Query and how many explicit licensed users of DB2 Web Query. It also provides options to Start and End DB2 Web Query capability and the ability to Work with users authorized to use the product. 4. To work with the list of DB2 Web Query domains, select option 8, Work with domains. 8/03/09 14:48:10 Work with DB2 Web Query LP12UT21 ______________________________________________________________________________ DB2 Web Query Status: Active
Type options, press Enter. 1=End DB2 Web Query 4=Force Server end 5=Work with users 8=Work with Domains *NOMAX 5 5 Maximum number of licenses for system Total licenses in use for system Licenses in use on this partition
The Work with DB2 Web Query Domains screen is presented. This screen displays each domain's short Hrefname and the descriptive name, and a column to indicate if the domain is currently enabled. 5. To display a panel with all the current users authorized to work with the MONTHEND domain, locate the MONTHEND domain and specify option 5 to Work with users.
37
7214ch03.fm
8/03/09 14:51:22 Work with DB2 Web Query Domains LP12UT21 ______________________________________________________________________________ Type options, press Enter 1=Enable Domain 4=Remove Domain from system Opt Enabled YES YES YES YES YES 5 YES YES YES YES YES YES YES YES Domain ADVLAB99 COBBGRPP COMMON20 DB2WBQRY FLGHT400 MONTHEND NEUGCAM2 OTHLABXX PAYROLLR PERFORMA SAFDOMAI SECLABXX SPREADSH
Description Advanced Lab Template cobbg domain Common 2009 Sales and Marketing Demo Flight400 Reports Month End Reports NEUGC OthLabXX Payroll Reports Performance testing Structure Ad-Hoc Forms Domain SecLabXX Spreadsheet Client
The Work with DB2 Web Query Domain Users screen is presented as shown in Figure 3-13. Note: Because we just created the MONTHEND domain, this list is limited to users set up with the MRADMIN group profile. In the example, this is user profile WQADMIN
8/03/09 14:54:44 Work with DB2 Web Query Domain Users LP12UT21 ______________________________________________________________________________ Domain Name: MONTHEND Description: Month End Reports Type options, press Enter. 1=Add authority 4=Remove Authority Opt User Name WQADMIN Authorization ADMIN Bottom ______________________________________________________________________________ F3=Exit F5=Refresh F6=Add user F11=Sort by authorization F12=Cancel
Figure 3-13 Work with DB2 Web Query Domain Users panel
38
7214ch03.fm
7. Enter all the information necessary to give user profile ARCH developer (DEV) access to the domain. 8/03/09 14:59:13 Add User Authorization LP12UT21 ______________________________________________________________________________
User Name:
ARCH
Domain Name:
MONTHEND
Figure 3-14
8. Press Enter to authorize ARCH as a developer to the MONTHEND domain. As a result of this request, ARCH will be registered as a licensed user and the profile MDMONTHEND will automatically be added as a group profile. In addition, if this is the first time a developer has been added to this domain, the utility will automatically create the underlying MDMONTHEND profile. The other valid types of authorizations possible are: ADMIN will automatically register the user profile as a named user and specify MRADMIN as a group profile (thereby making the named user a DB2 Web Query administrator_ USER gives the named profile the ability run (read-only) reports in the specified domain. If the Runtime User Enablement option is installed the user can share the license of the group profile for the domain. If it is not installed, the user is explicitly registered and consumes a license. SCHED is only applicable if Report Broker is installed. Because ARCH is a developer, he can also be given schedule authority for reports in any domain he is authorized to as a developer. Schedule authority allows ARCH to create Report Broker schedule entries for the automatic distribution of reports. You are returned to the Work with DB2 Web Query Domain Users screen. 9. Press F6 again to add a new user and enter similar information to give user profile SHANEG basic USER access to the domain. The Add User Authorization screen is presented as shown in Figure 3-15.
39
7214ch03.fm
User Name:
SHANEG
Enter Y or N
10.Press Enter to authorize SHANEG as a user to the MONTHEND domain. Because Run Time User enablement is installed on this box, the administrator has the choice of either registering SHANEG explicitly as a licensed user or of registering the MUMONTHEND group profile as a runtime user license. By default, Runtime enablement is set to Y. If the value for this setting is Y, MUMONTHEND will be created and registered, allowing other basic users to share the registration of MUMONTHEND. If Runtime enablement was not installed, or if N was specified for the Runtime Enablement setting on this screen, SHANEG would be registered as a named user. 11.Press F12 to return to the Work with DB2 Web Query Domains screen. 12.Select option 5, Work with users for the domain MONTHEND. You will now see that we have three users authorized to the domain. One is an administrator, one is a developer and the other is a run time user. This is shown in Figure 3-16.
40
7214ch03.fm
8/03/09 14:54:44 Work with DB2 Web Query Domain Users LP12UT21 ______________________________________________________________________________ Domain Name: MONTHEND Description: Month End Reports Type options, press Enter. 1=Add authority 4=Remove Authority Opt User Name ARCH SHANEG WQADMIN Authorization DEV USER ADMIN
Note: The presented list was Sorted by user name. You can press F11 to toggle the view to Sort by authorization as well.
Note: Although WRKWEBQRY does NOT allow you to create domains, it does give you the ability to register users, both named and runtime, to access the domain. It also manages the underlying changes to user and group profiles. Table 3-3 summarizes how the different user type gains access to report domains.
Table 3-3 User Type Administrator Group Profile requirement MRADMIN License requirement User profile is explicitely register using ADDWQLUSR or WRKWEBQERY User profile is explicitly registered via ADDWQLUSR or WRKWEBQRY
Developer
MDhrefname group profile specified for each domain the developer is authorized to develop reports. MUhrefname for 'other' domains the developer can only run reports in
41
7214ch03.fm
Group Profile requirement MUhrefname for each domain user is authorized to run reports
License requirement Run Time User: MUhrefname is created and registered as the shared licensed user OR Not Run Time User: Base user profile is explicitly registered via ADDWQLUSR or WRKWEBQRY
Note: The DB2 Web Query user license is not automatically removed when a user profile is deleted from the system. This means you must explicitely remove the users registration before the license is freed up and can be used by another user profile. An advantage of Run Time User Enablement is if that if a user profile is deleted, you do not need to worry about removing the DB2 Web Query license (because the license belong to the group profile and not the user profile that was deleted from the system). To view all users authorized to access DB2 Web Query domains and the type of license they consume, take option 5, Work with users on the main WRKWEBQRY menu. Figure 3-17 on page 42 illustrates the currently authorized users. 8/03/09 15:14:07 Work with DB2 Web Query Users LP12UT21 ______________________________________________________________________________ Type options, press Enter 4=Remove user from Web Query Opt User ARCH SHANEG WQADMIN
Type Description NAMED Mike Archer USER Shane Garton NAMED Web Query administrator
WQADMIN is an administrator and therefore a NAMED license user. ARCH is a developer and also a named license user. MUMONTHEND is a RUNTIME user that shares a license with all basic users with MUMONTHEND as a group profile. SHANEG is designated a USER, no explicit license. He gains access through the group profile. If you did a WRKLICINF
42
7214ch03.fm
PRDID(5733QU2), option 8 on the base option, all of the user profiles except SHANEG would be reflected in the list.
Tip: The data in the QWQCENT library contains sample data for the years 2006 and 2007. If you would like to update this data so that the year is something more recent, issue an SQL command similar to this one: UPDATE QWQCENTDEM/ORDERS SET ORDERDATE = ADD_MONTHS(ORDERDATE, 24) This is statement adds 2 years (24 months) to the values of the ORDERDATE column for all rows in the ORDERS table. Bear in mind that making this change will mean that for some reports, your results will be different than those in the tutorial examples of this Redbook.
CENTURY versus QWQCENT: The sample database was called CENTURY on the pre-GA version of the product. It is called QWQCENT in the GA version of the product. For this reason, we might refer to the CENTURY database in some places, for what is now the QWQCENT database.
43
7214ch03.fm
For those that are not familiar with SQL and its terminology, the table shown in Figure 3-19 on page 44 maps the equivalent terms between SQL and IBM i.
SQL
schema/collection table view index row column log
i5/OS
library physical file logical file keyed logical file record field journal
44
7214ch03.fm
3.6.1 Metadata
Before you can create a single report or graph in DB2 Web Query, you must create metadata (also known as synonyms) over the data source. The metadata requirement of the DB2 Web Query product may be foreign to you: many IBM i customers are simply not accustomed to working with a product that requires metadata and consequently view it as an unnecessary burden: an extra layer of complexity that they have to create and maintain. Typical questions include the following: What exactly is metadata? Why do I need it? Can't I just query my files directly? What happens if the structure of my underlying files change? This section explains what metadata is and why you should consider it as advantageous feature: something that can actually reduce the complexity of your query and reporting environment and make life easier for your report developers.
What is metadata
Metadata is simply data about data. Whenever you issue the DSPFD or DSPFFD commands, what is generated and displayed on your screen is in fact metadata: information such as record lengths, record formats, field names, data types, field attributes, and field lengths. DB2 for i also maintains system catalogs, which are files that store information about each of the objects in your database. They are effectively a materialized metadata repository that is kept up to date and can be queried to collect a wide variety of information about your database. In much the same way, DB2 Web Query metadata is a materialized repository that contains information about your database files. Before you can create a report or graph in DB2 Web Query you must first create metadata (also referred to as synonyms) over the data sources. You can create a synonym over the following database objects: Tables/physical files SQL views DDS Logical files Stored procedures Materialized Query tables In general, whenever you create a synonym over a database object, two stream files are created in a folder in the Integrated File System (IFS): the access file and the master file. Access file - This file has an extension of.ACX and contains the file level information such as the type of object and the library that it resides in. A very simple example of an access file would look something like this:
SEGNAME=FL400_FRCITY, TABLENAME=FLGHT400C/FRCITY, CONNECTION=*LOCAL, KEYS=1, $
The access file consists of multiple keyword-value pairs that are separated by commas. Attributes included are the name of the synonym segment (FL400_FRCITY), the underlying table that is referenced is (FRCITY in library FLGHT400C), the system to connect to in order to find the data source object (*LOCAL), and the number of key fields (1).
45
7214ch03.fm
Master file - This file has an extension of .MAS and contains the column (field) level information such as column name, data type, and length. Here is an example of the contents a master file:
FILENAME=FL400_FRCITY, SUFFIX=DB2, REMARKS='City table for building Flights (From City)', $ SEGMENT=FL400_FRCITY, SEGTYPE=S0, $ FIELDNAME=FRCINT, ALIAS=FRCINT, USAGE=A3, ACTUAL=A3, TITLE=' CITY,INITIALS', $ FIELDNAME=FRCNAM, ALIAS=FRCNAM, USAGE=A16, ACTUAL=A16, TITLE='CITY NAME', $ FIELDNAME=FRCALN, ALIAS=FRCALN, USAGE=A3, ACTUAL=A3, TITLE=' CITY,AIRLINE', $ FIELDNAME=FRCNBR, ALIAS=FRCNBR, USAGE=P4, ACTUAL=P2, TITLE=' FROM, CITY,NUMBER', $ Figure 3-21 DB2 Web Query Master file example
Similar to the access file, the master file uses a keyword-value pairing technique to define the column attributes. These include the name of the field, the ALIAS (the underlying field name in the file), the data type and length (for both how it is used in reports and actually defined in the file), and the title to be used in report column headings. Typically these two stream files are located in the following folder in the system's Integrated File System (IFS): /qibm/UserData/webquery/ibi/apps/baseapp The exception to this is if you have requirements to secure or segment your metadata. In those cases, a custom folder (referred to as an application folder) can be created and associated with a specific DB2 Web Query domain (more on this in section Creating an application folder for segmented metadata on page 80). The really nice thing about metadata is that it can be an abstraction layer: you can build business logic into the metadata so that all reports and graphs that reference those synonyms have access to all of that logic. This greatly simplifies the environment for the report developers.
Benefits of metadata
The primary objective of the metadata layer is simple: improve the productivity of the DB2 Web Query report developers by providing an abstraction layer and burying the database complexity. Report developers can be more productive if you keep the data model simple. A simple and intuitive data model also means you can extend the report developer community because it does not require an intimate knowledge of the database. By empowering more and more of your users, you can reduce their dependence on IT and the number of backlogged reporting requests. But before this can happen, some work needs to be done to build up this abstraction layer. For this, you will need the DB2 Web Query Developer Workbench tool. This Windows PC based tool contains several powerful components, one of which is the Synonym Editor. The Synonym Editor contains graphical tools and interfaces that will allow you to do the following: Define database joins Build virtual columns to centralize business logic Standardize column formats Convert and standardize date fields Create filters Create Business Views Define OLAP dimensions
46
7214ch03.fm
Creating metadata
DB2 Web Query metadata can be generated in multiple ways. Each technique is discussed below. Create your own Metadata creation wizards are available from both the web browser via the Web Query launch page and in the DB2 Web Query Developer Workbench tool (more on this tool later). To create metadata, you must either be a Web Query administrator (member of group profile MRADMIN) or a developer in the domain. In most cases, this is how the metadata is created. Through the use of third-party tools. Some examples of this include: Databorough x-WebQuery product (www.databorough.com) generates the metadata based on the data model it derives from both database definitions and business logic buried in application programs. It can also use this extracted information to generate the necessary dimensions for instant OLAP capabilities. Information Builders's iWay Data Migrator (www.ibi.com) and Coglin Mill's RODIN DB2 Web Query Edition (www.thinkrodin.com) products generate the metadata in conjunction with building a data mart or data warehouse. Provided by ERP or Services Provider ISV's have the ability to include DB2 Web Query content as part of their solutions package. If you purchase such a distribution, the metadata will be included in the package. Similarly, a services provider may have the expertise and tools to build the metadata for you. For more information about what is created on the system, see Appendix A, Metadata in the integrated file system on page 511. In most cases you are going to create your own metadata using the provided metadata creation wizards. To do this, take the following steps: 1. Open a web browser and enter the URL of the DB2 Web Query home page. 2. On the DB2 Web Query home page, expand the domain in which you want to work. Expand Reports. Right-click the specific report folder and select Metadata (Figure 3-22).
47
7214ch03.fm
3. In the Configuring Data Adapters pane (Figure 3-23), select the adapter that matches the data on which you will create metadata. In this example, we use DB2 cli, which is for a single member file. Click the adapter type and select Create Synonym as shown in Figure 3-23. If you have a connection to a remote database, select the database to which you want to connect from this panel. Notice that we click the *LOCAL connection. To learn more about Data Adapters, refer to 1.5.5, Data adapters on page 13.
4. In the Select Synonym Candidates for DB2 cli pane (Figure 3-24 on page 49), enter your collection name. Select the type of data that you want to query. In our example, we select Tables because want to create metadata on a table in QWQCENT. In the Library field, type qwqcent. Click Next.
48
7214ch03.fm
5. The Create Synonym for DB2 cli pane (Figure 3-25 on page 50) is displayed and shows all the different tables that reside on the QWQCENT (Century) schema. In this panel, select the table names for which you want to create reports. You might want to include a prefix or suffix. In our example, cen_ is our prefix, because the table resides in library QWQCENT. We leave the suffix blank, but the developer has the choice to use it. Leave baseapp for Application. Click the Create synonym button. Prefix and suffix (optional, yet recommended): The prefix and suffix are optional letters that you can add to your synonym name to provide extra meaning for you. Using a prefix or suffix is not required. It is up to the developer to decide whether it is necessary to use the prefix and the naming convention that is preferred. We recommend that you use the library name or an abbreviated version of the library name for the prefix. This way, when you create your reports, you can search on all metadata that starts with the library name. Keep in mind that all metadata is displayed in one box called Database Descriptions. The box is rather small and does not list the metadata according to library.
49
7214ch03.fm
The metadata takes a few seconds to create, depending on how many items you selected. After the processing is done, in the Status column, you see the message Created successfully as shown in Figure 3-26.
The process of creating metadata is now complete. You are ready to begin the tutorials in Chapter 5, Report Assistant on page 97.
50
7214ch03.fm
51
7214ch03.fm
To illustrate how a stored procedure could be used, lets assume that you need to create a report that returns rows from a sensitive table (the HR table) and you must add an auditing feature to this report. That is, each time the report is run, information such as the timestamp, name of the report, and requesting user profile must be logged to an audit table. To create a stored procedure that returns data from specific columns in the payroll table and satisfies the auditing requirement take the following steps 1. From an SQL interface such System i Navigator Run SQL Scripts, create the audit table: CREATE TABLE rptaudlog (rpttimst TIMESTAMP, rptname CHAR(25),rptusrprf CHAR(10)) 2. From same SQL interface, create the stored procedure: CREATE PROCEDURE hr_table_audit (inplantcode CHAR(3)) DYNAMIC RESULT SETS 1 LANGUAGE SQL NOT DETERMINISTIC MODIFIES SQL DATA P1 : BEGIN DECLARE c1 CURSOR WITH RETURN TO CLIENT FOR SELECT lastname, firstname, status, payscale, salary FROM hr WHERE plantcode = inplantcode; INSERT INTO rptaudlog VALUES(CURRENT TIMESTAMP, 'HR Salary Report', SESSION_USER); OPEN c1 ; END P1 ; Several things need to be pointed out in this store procedure: The cursor is declared with the WITH RETURN TO CLIENT clause specified. It is a good idea to specify this clause to ensure that the result set is returned to the client application. WITH RETURN TO CALLER is the default, which would cause problems in the event you had a nested stored procedure (a stored procedure called by another stored procedure) that was actually returning the result set. The INSERT statement is specified to log the request. This satisfies the auditing requirement. The cursor is opened (and left open). This returns a result set to the client application (which is DB2 Web Query) The process for creating a stored procedure synonym is similar to that of creating a synonym over a table. Take the following steps: 1. From the Select Synonym Candidates for DB2 cli (*LOCAL) Step 1 screen, select Stored procedures from the Restrict object type to dropdown list, specify the library, and click the Next button as shown in Figure 3-27 on page 53.
52
7214ch03.fm
The Select Synonym Candidates for DB2 cli (*LOCAL) Step 2 or 3 screen is displayed. 2. From the list of stored procedures displayed, select HR_TABLE_AUDIT as shown in Figure 3-28.
If the stored procedure has input parameters, you will be prompted to enter a valid value for the input parameter. 3. As demonstrated in Figure 3-29 on page 54, specify a valid input parameter value by taking these steps: Select/check the INPLANTCODE parameter Specify ORL as the value for the input parameter (this is a valid Plant Code value) Click Create Synonym. Note: When the synonym is created, the stored procedure is actually called by DB2 Web Query so that it can receive the result set. This is because it needs to store the format of the result set in the synonym. Consequently, you need to pass it a valid value for the input parameter at this step.
53
7214ch03.fm
As shown in Figure 3-30, a confirmation window is displayed to confirm that the stored procedure synonym was successfully created.
For an example of how to create a report over this synonym, see 5.6, Creating a report over a stored procedure synonym on page 144. Multiple result sets: DB2 Web Query supports the return of multiple result sets from the stored procedure. In this case, it assigns a distinct segment name to the fields of each separate result set.
54
7214ch03.fm
points to a specific member in a file. It is easy to create, and after it exists, SQL treats the alias the same as it would a table. You simply substitute the alias name in any query where you would put a table name. Here is an example of a CREATE ALIAS command in SQL: CREATE ALIAS QGPL/MYALIAS FOR QGPL/MULTI_MBR_FILE (MBR_NUM_2) You can run this command in the Run SQL Scripts window of iSeries Navigator or in STRSQL from the command line. STRSQL has a prompt for CREATE ALIAS that is intuitive. You can create metadata on an alias as easily as you can on a regular table. Refer to Creating metadata on page 47, which explains how to create DB2 Web Query metadata. The DB2 Heritage File adapter also has the limitation of only being able to join on key fields. If you try to join on non-key fields using the multimember file adapter, you receive an error message (see Figure 3-31). This message might provide extra incentive to create an alias and use the DB2 CLI adapter.
55
7214ch03.fm
When this action is taken, the synonym is parsed and its contents are compared with the structure of the actual underlying data source. New columns are added to the synonym and deleted columns are removed. Any custom changes (joins, virtual columns, filters, OLAP dimensions, etc.) that were made to the synonym are preserved Attention: Refresh synonym will not update the synonym for all database object changes. For example, if column attributes such as data type or length are altered in the database object, those changes are not applied to the synonym. For those types of changes, the synonym will either have to be manually edited or recreated.
Referential Integrity
In this section, we explain the benefits, to DB2 Web Query, of having referential integrity defined in the database. We begin by briefly explaining referential integrity. A feature of a relational database is that it must support the definition and enforcement of referential integrity. If you do not fully grasp the meaning of referential integrity, you are not alone. A database can consist of one large fact table and several smaller dimension tables. The dimension tables each contain a primary key that is referenced by a foreign key in the fact table. For our example, the primary key on the Inventory table is PROD_NUM, and the
56
7214ch03.fm
corresponding foreign key on the Order table is PROD_NUM. An entry in the fact table is not allowed unless there is a matching key in the dimension tables. That is, you are not allowed to place an order for a product that is not confirmed to be in your inventory. The referential constraint does not permit an entry into the Orders table unless the entry has a value for PROD-NUM in the Inventory table. This prohibits unmatched, or orphan, entries in the Orders table. Tip: You can also think of the small dimension tables as parent tables, and the large fact table as a child table. Do not let the part about the child table being larger confuse you. Think of it as a parent that has many children. The constraint does not let the child be born unless the parent already exists.
57
7214ch03.fm
3. In the Select Schemas to Display window (Figure 3-33), in the Enter schema names field, type Century and click Add. Then click OK.
4. In the left navigation bar of iSeries Navigator, expand the CENTURY database and click Tables. In the right pane, right-click the INVENTORY table and select Definition as shown in Figure 3-34.
58
7214ch03.fm
5. In the next window, from the tabbed selections, click the Key Constraints tab and then click Add. 6. In the New Key Constraint window (Figure 3-35), complete these steps: a. Under Constraint type, select the Primary Key radio button. b. Under Available columns, select the ProductNumber field and click the Add arrow button. Now the ProductNumber field is displayed under Selected columns. c. Click OK.
59
7214ch03.fm
7. In the window that contains the various tabs (Figure 3-36), click OK.
You are now finished creating the primary constraint on the Inventory table. Next, we go to the Orders table and create a referential constraint. Remember that the Orders table checks the Inventory table to ensure that any new record also has a matching key value in Inventory. 1. Expand the Century schema and click Tables. Right-click the Orders table, and select Definition. 2. In the next window, click the Foreign Key Constraints tab. Click Add. 3. In the New Foreign Key Constraint window (Figure 3-37), complete these steps: a. For Table name, select Inventory.
60
7214ch03.fm
b. Under Available Columns, select ProductNumber and click Add. We know this is the primary key on the Inventory table because it is indicated under Key columns near the top of the window on the right. c. Click OK.
You are now finished creating the referential constraint between the Inventory and Orders tables. You can now repeat this process with the two other dimension tables, Stores and Plant. The key fields on those tables are, respectively, Store_Code and Plant_Code. The Orders table has the corresponding foreign key for each table as it did for the Inventory table. After you are done creating the other two referential constraints, your database is now ready for metadata creation.
61
7214ch03.fm
Next the status pane (Figure 3-39) is displayed on which you see a status message of Created successfully. Notice that there is only one piece of metadata. You can close this panel.
62
7214ch03.fm
When you first start to write the report based on the file cluster, you are presented with the metadata window. The related files are all under one name; the description says Cluster xxx for table yourFactTable like the example in Figure 3-40. The word Cluster in your metadata indicates that referential integrity has been used to create that metadata. All the related dimension tables with referential constraints defined appear in Report Assistant.
63
7214ch03.fm
When you create a report, the list of columns can be presented alphabetically or by segment. In our case, segment means table. See Figure 3-41.
7214ch03.fm
For DB2 Web Query, SQL views are particularly useful because they can used to join tables together. Once the view is created DB2 Web Query metadata can be created over the view (instead of the base tables). Reports using that synonym can access any of the columns from each of the join segments defined in the view. Using reports based on SQL views provides several distinct advantages to DB2 Web Query, including the following: Encourages database optimization (pushes logic down to DB2) Provides method for implementing more complex reporting requirements such as row and column level security Provides additional join types, unions, intersects, excepts, Common Table Expressions, complex business logic (case statements, etc.) Data-centric because business logic and rules can be defined in one place (at the database level) rather than the application level In addition, SQL views can be accessed by other interfaces such as RPG programs (with embedded SQL or native Record Level Access), ODBC, JDBC, etc.
Example 3-1
CREATE VIEW ORDERSVIEW (ORDERNUMBER FOR COLUMN ORDER_NUM, PRODUCTNUMBER FOR COLUMN PROD_NUM,...) AS SELECT a.*, b.*, c.*, d.* FROM orders a INNER JOIN stores b ON a.storecode = b.storecode INNER JOIN inventory c ON a.prod_num = c.prod_num INNER JOIN plant d ON a.plantcode = d.plantcode
A synonym created over the example SQL view would contain all of the columns in the joined tables.
65
7214ch03.fm
Before you begin this exercise, you need to have a basic understanding of the different types of joins that DB2 Web Query supports: Multiple (SEGTYPE=S0) Indicates that the segment has no key field and is therefore not sorted. Keys and sequences are defined in the access file. With the Multiple segment type, each joined file is represented as an individual join segment. If no matching row is found based on the join criteria, no row is returned to the join. This will prevent something called the multiplicative effect but will also not allow a developer to write a report that sorts (or performs a combination of sorting and selecting) across the different segments. Unique (SEGTYPE=U) For each join definition; every child segment becomes logically part of the parent. At least one row will be retrieved, regardless of whether or not a matching row was found. If there is a one-to-many relationship between parent and child, ALL children will be returned (despite the name "Unique" which would indicate a one-to-one relationship.). Since the child becomes an extension of the parent, the result is one virtual segment. This provides the ability to sort and/or select fields across the underlying segments, but could also result in a report that delivers incorrect results due to the multiplicative effect. For this exercise, we are not concerned about the multiplicative effect. Therefore Unique join types are defined. 1. Open DB2 Web Query Developer Workbench. 2. Expand WebFOCUS Environment your-system-name, and log in using your user profile and password 3. Expand Data Servers EDASERVE Applications baseapp 4. Under the contents of baseapp in the right navigation pane, select cen_orders.mas and from right-click menu select Edit in Synonym Editor as shown in Figure 3-42 on page 67
66
7214ch03.fm
The cen_orders master file is opened in the synonym editor. 5. Right mouse click on the CEN_ORDERS segment and select Add Segment From Existing Synonym as shown in Figure 3-43
67
7214ch03.fm
6. From the presented list, select the cen_inventory synonym as shown in Figure 3-44 and click the Select button.
The segment CEN_INVENTORY is added under CEN_ORDERS 7. Select the segment CEN_INVENTORY segment and change the join segment type (SEGTYPE Type) setting from Multiple (the default) to Unique as shown in Figure 3-45.
Note: Once you have changed the Segment type to Unique, the icon next to the CEN_INVENTORY segment becomes a red color.
68
7214ch03.fm
8. PRODUCTNUMBER is the field that is used to join ORDERS to INVENTORY. Select this field under both tables and click the = button. (located between the tables lists) as shown in Figure 3-47 on page 69. Make sure Inner Join is selected for the Join Type.
69
7214ch03.fm
This will bring the join formula into the Expression pane as shown in Figure 3-48.
9. Click the OK button 10.Repeat steps 5 on page 67 9 for the CEN_STORES segment. The join field for this join is STORECODE 11.Repeat steps 5 on page 67 9 for the CEN_PLANT segment. The join field for this join is PLANTCODE 12.At this point, you have created a cluster for the ORDERS table. The segments of this cluster should look like the example shown in Figure 3-49.
70
7214ch03.fm
13.Finally, save your work by clicking the Save icon as shown in Figure 3-50 on page 71.
71
7214ch03.fm
Figure 3-51 Selecting the option to create a new Relational Database Directory Entry
72
7214ch03.fm
3. In the Add RDB Directory Entry (ADDRDBDIRE) window (Figure 3-52), specify the following options: Relational database This is the logical name to assign to the relational database. It is usually the name of the remote system or partition. Remote location name or address This is either the fully qualified system or partition name or the IP address. Remote location type This refers to the protocol that is being used to communicate between the two systems or partitions. In most cases, you specify *IP for this setting. Click OK.
73
7214ch03.fm
4. Open your Web browser to the DB2 Web Query console on port 11331, for example: http://yoursystemname:11331/webquery 5. Enter your IBM i user ID and password. 6. Navigate down to any folder under Reports, right-click, and select the Metadata option. 7. Select Data Adapter from the menu bar. 8. In the Data Adapters window (Figure 3-53), click DB2 cli and select Add connection.
9. In the Add Connection for DB2 cli pane (Figure 3-54 on page 75), specify the following options: Connection Name This is the logical name that is used to identify this particular set of connection attributes. It is usually the remote system or partition name, but it does not have to match any value that is specified during the Add RDB Directory Entry step (step 3 on page 73). Datasource This is the DB2 database name that is used for this connection. The name must match the Relational Database value that is specified during the Add RDB Directory Entry step. Security There are three methods by which a user can be authenticated when connecting to a DB2 database server: Explicit The user ID and password are explicitly specified for each connection and passed to DB2, at connection time, for authentication. Password Passthru The user ID and password received from the client application are passed to DB2, at connection time, for authentication. Trusted The adapter connects to DB2 as a Windows login using the credentials of the Windows user, who impersonated by the server data access agent. User For Explicit security only, this field is for the i5/OS user profile.
74
7214ch03.fm
Password For Explicit security, this field is for the password that is associated with the specified i5/OS user profile. Click the Configure button.
10.Create the synonyms for the remote tables or views that you want include in your reports: a. In the Data Adapters window (Figure 3-55), click the remote connection and select Create Synonym.
75
7214ch03.fm
b. In the Select Synonym Candidates for DB2 cli pane (Figure 3-56), for Restrict object type to, select Tables and Views. Then specify the name of the Library (schema) that contains the database objects that you want to include in the cross-system join. Click Next.
c. In the Create Synonym for DB2 cli pane (Figure 3-57), specify the prefix (recommended format is connectionName_libraryName_) and select the tables, views, or both that you want to include in the cross-system join. Click Create synonym.
76
7214ch03.fm
11.Include the table in your reports by using a cross-system join: a. In the DB2 Web Query home page, under the desired folder, select Report Assistant. b. In the Select from available database descriptions panel, find and select the synonym for the local table; do not select remote synonym just yet. c. In the Report Assistant window (Figure 3-58), click the Join options tab. d. On the Join options tab, complete these steps: i. Click New. ii. In the Web Page Dialog that opens, find and select the synonym for the remote table and click OK. Notice that the Join options page changes.
77
7214ch03.fm
iii. Under Join Settings, as shown in Figure 3-59, specify the Join Type, Description, Instances, and Join fields options. Note: For more information about joining tables, see 5.5, Joining tables (reference only) on page 142.
78
7214ch03.fm
12.Click the Field Selection tab. At this point, you can finish the report by specifying the desired options such as Sort by and Sum as shown in Figure 3-60. All of the fields from the joined files are displayed in the list of fields to select from. Notice that the fields are color coded to clearly identify the files from which they originated. See Chapter 5, Report Assistant on page 97, for more details about report writing.
79
7214ch03.fm
These areas of concern have been addressed with the ability to create custom application folders and associate them with specific domains. The application folder (and the synonyms within it) can now be set up as an extension of the domain. Because domains are secured using IBM i group profiles, you now have the ability to segment and secure your synonyms.
80
7214ch03.fm
After clicking the right arrow icon, the application will move from the Available list to Selected. An example is shown in Figure 3-63 on page 82.
81
7214ch03.fm
You can remove applications from a domain by selecting the application under the Selected list and clicking the left arrow icon. This will move it back to the list in Available. Note: Although only one application can be selected at a time, you can repeat the above steps and add as many as you want from the list under Available to Selected. There is no documented limit for the number of application folders that can be linked to a domain (as many as 1,500 application folders have been successfully linked during system testing). However, you may want to consider performance implication before adding this many to your domains. 4. Repeat the above steps to add application webqry01 to the domain. 5. When you have finished linking the applications to the domain, you can sort the Selected list by selecting the application and using the up and down arrow icons above the list. Use this technique to move the payroll_files application to the top of the list as shown in Figure 3-64 on page 83.
82
7214ch03.fm
After clicking the up arrow icon, the Selected list is sorted as shown in Figure 3-65 on page 84.
83
7214ch03.fm
When DB2 Web Query searches for the synonym specified for a report in this domain, it will use the list in the order you have configured - much the same way library list searching works on the IBM i system. This means that if you have a synonym named cen_payroll in all three selected application folders (payroll_files, baseapp, and webqry01) any report that references cen_payroll will use the version in the payroll_files application, because it was first in the list. 6. Accept the settings by clicking the Apply button. 7. Click OK to close the Domain properties dialog window Once you have associated an application folder to a domain, you have secured it. The synonym is only visible and accessible to those developers explicitly authorized to the associated domain or to user profiles that are members of MRADMIN. The report developers can only reference the synonyms in the application by creating reports from within the domain that the application is linked with. A developer using DB2 Web Query Developer Workbench tool can only access the Application folders by going through the domain. As shown in the example in Figure 3-66 on page 85, notice that when the Payroll developer logs in using Developer Workbench, there is no Data Servers option under the system/environment name.
84
7214ch03.fm
Figure 3-66 DB2 Web Query Developer Workbench interface for developers
The Data Servers option is only available for members of MRADMIN. In order to work with application folders (and the synonyms within them), the developer must expand Domains Applications. The only applications that appear in this list are the ones that have been linked to the domain. This way the developer can only access synonyms in the application folders linked to the domains that he or she is authorized to.
85
7214ch03.fm
To run a report, expand the domain. Then expand the Reports folder and the subfolder. The subfolders inside of this report categorize the reports within the domain. After you expand the subfolder, double-click the report that you want to run. The Processing Request panel is displayed while your results are retrieved from the server. Then the results are displayed in the right panel (see Figure 3-67).
Keep in mind that the results of your report are returned to your PC and stored in your browser. This affects the time that it takes for your results to appear. If your report returns several thousands of records, you will notice more delay than if your report returns ten records. If you think the report returns more records than you can use, ask your developer to limit the number of records that are returned to you. We explain how to do this in 5.2.3, Sum and detail reports on page 102.
86
7214p02.fm
Part 2
Part
87
7214p02.fm
In DB2 for i5/OS, the following foreign keys are defined in the ORDERS table: ProductNumber is the key to the INVENTORY table. StoreCode is the key to the STORES table. PlantCode is the key to the PLANT table.
88
7214ch04SetupTutorials.fm
Chapter 4.
89
7214ch04SetupTutorials.fm
In preparation to start using the tutorials, you must authorize your user profile to create tables in the Common Domain. Then you must create a folder to store all your work. Finally you must define all the tables that we will query to DB2 Web Query through the Create Synonym process. 1. Before you start using the tutorials, register your user profile as a valid licensed DB2 Web Query user. Enter the following command: CALL QWEBQRY76/WQADDLIC USERPROFILE USERPROFILE references your System i user profile name and must be specified in uppercase letters. Note: You can also use the CL Command ADDWQLUSR for the same purpose. For more details about registering and removing users, see 3.3, Registering named users on page 28. 2. Incorporate the user profile to a group profile called MDUNTITLED. When you install DB2 Web Query, the system creates a group profile named MDUNTITLED. To create reports in the Common Domain, you must be a member of either MDUNTITLED. As a member of the MDUNTITLED group, you are authorized to create new reports in the default Common Domain. For more details about security and authorizations, see 3.5.3, Assigning authority to users on page 35. MRADMIN group: Being a member of the MRADMIN group instead of MDUNTITLED also works for these tutorials. The MRADMIN group profile allows a user to create new reports in all domains and to create new domains. This additional authorization is not required for the tutorials. 3. Open a browser. We tested these steps using both Internet Explorer and Firefox, but use Internet Explorer for the tutorials presented in this book. 4. Since DB2 Web Query uses port 11331, point your browser to the following URL (Figure 4-1): http://systemi_name:11331/webquery
5. Enter your System i user ID and password (Figure 4-2 on page 91).
90
7214ch04SetupTutorials.fm
6. In the main DB2 Web Query home page, right-click Common Domain and select Properties to see the domain properties. 7. The Domain Properties window (Figure 4-3) opens. The Common Domain is where we store our reports. One of the properties is the Href or the system identifier. For the Common Domain, this is always untitled. By previously including yourself in the group MDUNTITLED, you now have developer authority (MD) in the domain UNTITLED. Close this window.
8. Expand Common Domain, right-click the Reports folder, and select New Folder. 9. In the New Folder window (Figure 4-4), create a new folder called Tutorials, which is where we store all of our work. Click Save.
91
7214ch04SetupTutorials.fm
10.Before you can create a report on the System i machine, you must tell DB2 Web Query which tables the users can query. DB2 Web Query then creates the metadata or synonyms to describe the selected tables. For more details, see Creating metadata on page 47. In the left navigation area (Figure 4-5), right-click Tutorials and select Metadata. Note: Although you select a folder to enable the submenu that contains metadata, the metadata is not restricted to that folder. After the metadata is created, it is available system wide and to all reports.
11.In the Data Adapters window (Figure 4-6), right-click *LOCAL, which is the System i where the table resides, and select Create Synonym.
92
7214ch04SetupTutorials.fm
Tip: If you have other System i machines, logical partitions (LPARs), or independent auxiliary storage pools (IASPs) in your network, you can add a connection to these systems. Then the database names will be displayed under *LOCAL. Any of these remote DB2 tables are then available for use. These additional databases must be defined in the relational database directory table on the System i machine. 12.Enter the library where the tables reside. The library that we use throughout the tutorials is the QWQCENT library. Note: There are three types of System i objects that you can query with the base DB2 Web Query product.
DB2 cli refers to the majority of your tables created with either an SQL CREATE TABLE statement or by using data description specifications (DDS) and a CRTPF command. DB2 Heritage files refers to older tables that have multiple record types or multiple
members. Tables described with this adapter use the OPNQRYF command on the System i machine. It then directs the query to the older, and typically slower, database optimizer (Classic Query Engine (CQE)).
Query/400 imports the existing Query/400 definitions and converts them to both table and report definitions.
13.In the Select Synonym Candidates on DB2 cli pane (Figure 4-7), complete these steps: a. For Restrict object type to, specify Tables, Views, and Other Objects. b. Under Further restrict search to:, select the Tables option. In this example, we clear the Views check box. This leaves us with a concise list that contains only our physical files or tables. SQL views: If you created SQL views or logical files and want to query them, you must leave Views selected. If this library is an SQL collection or schema, selecting Views also displays all of the SQL catalog views in the library. c. For Library, type qwqcent. d. Click Next.
93
7214ch04SetupTutorials.fm
14.In the Create Synonym for DB2 cli pane (Figure 4-8), complete these steps: a. In the list of tables, select the check box next to Default synonym name to select all the tables that are currently displayed. b. For Prefix, enter Cen_. This prefix is added to the beginning of the table names, so the users see, for example, Cen_ALERTS, CEN_ORDERS, and so on. If you have a long list of table names, using a prefix is one way to keep all related tables grouped together. c. Select With foreign keys to bring in all tables that are directly related through referential integrity and foreign key support. For more details about foreign key support, see Referential Integrity on page 56. d. Click the Create synonym button.
94
7214ch04SetupTutorials.fm
You have now authorized your user profile to create tables in the Common Domain. You have created a folder to store all your work in called Tutorials. You have also defined all the tables that we query to DB2 Web Query through the Create Synonym process. See Figure 4-9.
95
7214ch04SetupTutorials.fm
96
7214ch04.fm
Chapter 5.
Report Assistant
Report Assistant provides an intuitive, graphical interface with drag-and-drop functionality. It enables you to quickly create a report in which you can sort data; include record selection criteria; add headings, footings, subtotals, and page breaks; apply a style template; and more. When you use Report Assistant, DB2 Web Query creates a styled report that you can deploy on the Web without learning the complexities of any reporting language. With DB2 Web Query, you can specify input parameters to allow users to easily subset or filter their reports. Report Assistant supports output in many different file types including PDF files, Microsoft Excel, and DB2 database files. Report Assistants tight integration with Excel includes the real-time creation of Excel spreadsheets with full styling, drill-downs, and formula capabilities. This support allows Excel power users to analyze their corporate data in a tool with which they are already familiar. Many of the reports created in this chapter are prerequisites for the enhanced features that are discussed later in this book. Active Reports, which is for users who are not connected to a System i machine, and online analytical processing (OLAP)-enabled reports are both based on existing reports that are created in this chapter. In this chapter, we go into detail about basic functionality that is common among the various DB2 Web Query components. For more details about the various options that are not discussed in the tutorials, use the help text. Tip: If you have Developer Workbench installed, you will find the help text to be more extensive than the help text that is available in Report and Graph Assistant.
97
7214ch04.fm
98
7214ch04.fm
After you choose the CEN_ORDERS table, you see a list of all the column or field names on the Field selection tab. Continue with the next section to learn how to use these names to define a report layout.
99
7214ch04.fm
when you select the Foreign key option during the creation of the Orders synonym or metadata. This results in the composite list of available fields. To define a report layout: 3. To see the table or segment names, drag the sides of the window to widen it. Icons for Available fields: You can choose to view your field names alphabetically regardless of which table they originated from, or you can view the fields for each table separately. Immediately above the field list are three icons. The first from the left is a calculator icon. The second icon is the dimension or hierarchy icon, which shows the fields within each individual table. The third icon is the list icon, which shows all the fields from all the tables in one long alphabetical list. 4. From the list of Available fields on the left, drag PRODUCTTYPE to the Sort by pane in the center of the window. Tip: If you are using the Firefox browser, you might not be able to drag your fields. In this case, you must highlight the column in which you want to insert in your report and then click the add field icon in the appropriate pane, for example Sort by, Sum, and so on, to where you want to move the field. 5. Again from the list of available fields, drag LINETOTAL to the Sum/Print pane on the right side of the window. LINETOTAL is the gross revenue for each line item on an invoice. 6. Select the Add grand totals to the end of the report check box. See Figure 5-3.
100
7214ch04.fm
7. At the top of the window, click the Run arrow to run your first report. Figure 5-4 shows the initial summary report.
Tip: If you use an alpha field instead of LINETOTAL, the default sum option shows the value of the alpha field in the last record for each sort group or product type. 8. Save the report as shown in Figure 5-5: a. Click the Save button at the top of the window and select Save As. b. In the Save Standard Report window, enter the name as RA1_Revenue and click OK.
It was easy to answer the question that was posed about the total revenue by product type, but we know that we can make this report look better and more meaningful for the users. Next we take a closer look at creating sum and detailed reports.
101
7214ch04.fm
Figure 5-6 Limiting the records to read on the Report options tab
102
7214ch04.fm
12.Click the Run arrow at the top of the window. Then you see the report shown in Figure 5-7.
13.The Print option is for a detailed report that includes one row for each selected record. The Sum option sums or aggregates field values that are based on your sort column and consolidates the records. Since we want a summary report, complete these steps: a. On the Field selection tab, click Sum. b. Click the Report options tab. c. On the Report options tab, for the Limit the number of read operations performed during report generation field, clear the value of 100. 14.We now enhance the report to make it more readable: a. Click to highlight the LINETOTAL field in the Sum/Print pane. b. Select the Show - Field options - LINETOTAL arrow near the bottom of the window. The Field options display allows you to work with the properties for an individual field. You can describe standard and conditional formats based on values in your report. You can set up a field so that when a user clicks on it they will drill down to a lower level report. You can specify if you want the report to display the actual data in a field or if you want to see the average, minimum, or maximum value in the field instead. If
103
7214ch04.fm
you are working with a sort field you have additional capabilities to control the sort, add ranking columns, and control the subheadings and subfooting. i. Click the ellipsis or three dots (...) button under the Format in report as field (Figure 5-8).
ii. Under Select options (Figure 5-9), select Commas inclusion and Floating dollar to change the LINETOTAL field to be displayed with commas and a floating dollar sign.
104
7214ch04.fm
c. On the Field selection tab, complete these steps: i. Ensure that LINETOTAL is highlighted. ii. Select the Show - Field options arrow. iii. Click the Title tab. See Figure 5-10. Notice that the title is Revenue. This pane is where you enter your own, more meaningful column headings for users. In our case, the LINETOTAL column was defined to DB2 as having a heading of Revenue. DB2 Web Query imports the DB2 heading attribute into the metadata attribute Title.
105
7214ch04.fm
15.Add a count of the number of orders for each product type: a. Drag ORDERNUMBER from the Available fields list on the left to the Sum/Print pane on the right. b. Click the Show - Field options button to open the pane if it is closed. i. Under Calculated as, select Count. Note: If you do not see a long list of field options including Count, verify that your report is a summary report and not a detailed report. Verify that Sum is highlighted, and not Print. ii. Under the Format in report as field (Figure 5-11), click the ellipses (...) button. Change the field format to integer seven with commas. The value is displayed in the field as I7C.
106
7214ch04.fm
iv. Change the heading as shown in Figure 5-12, with Order on the first line and Count on the second line.
107
7214ch04.fm
c. Using the up and down arrows (circled on the right in Figure 5-13) in the Sum/Print pane, move CNT.ORDERNUMBER above LINETOTAL.
16.Click the Run arrow at the top of the window to run the report. Figure 5-14 shows the results of running this report. You have now created a report that includes a count of the number of orders for each product type.
108
7214ch04.fm
109
7214ch04.fm
4. Repeat the process starting with step 2 on page 109 to create the year field. In the Define field creator window (Figure 5-16), for fields, type Year. For Format, select YY. In the date field, either select or type ORDERDATE.
Note: DB2 Web Query handles dates in an intelligent manner. However, much of this information, including the various date formatting options, is not well described in the help text. For this reason, we provide details about working with dates in Date and time system variables on page 514.
110
7214ch04.fm
7. From the first drop-down list, select WHERE. WHERE or WHERETOTAL: Although we select the default WHERE, DB2 Web Query allows you to choose WHERE or WHERETOTAL. WHERE does the select at read time and only passes those records to the query that meet the specified condition. WHERETOTAL does the comparison after the records are retrieved, sorted, and aggregated. The selection is done on the aggregate value of the column. For example, if you want to select only the product types whose total revenue was greater than $100 million, you use WHERETOTAL. If you use WHERE, you apply the selection on every individual order read and none meet this criteria. 8. Select EQUAL to. 9. Click Select values.
111
7214ch04.fm
10.In the window that opens (Figure 5-18), complete these steps: a. Click the Values radio button. b. DB2 Web Query looks for all distinct values in this field and presents them in a list. Select 2007. Note: You can compare a field to the following types: Constant Parameter Field Values c. Click OK. A specific number A variable whose value or values are either entered by a user or passed from another report Another field in your table or tables Selectable from a list of actual values in the selected field
Tip: With DB2 Web Query, you can store a list of products, regions, customers, and so on that you are specifically interested in on your local PC. This list can be stored in a text file or in Excel. If you click the wizard icon ( ) next to the Constant prompt, you can browse your local PC. The values in that file then become the filter for your query.
112
7214ch04.fm
12.Click the Run arrow at the top of the window to run your report. You see the results as shown in Figure 5-20.
113
7214ch04.fm
Tip: If your report shows only two quarters, remember that you must remove the 100 record limit. See step 13 on page 103. 13.At the top of the window, click Save Save As. In the Save Standard Report window, save the report with the name RA2_XTab, click OK, and close it.
114
7214ch04.fm
3. From the Available fields pane, drag PRODUCTTYPE and PRODUCTCATEGORY to the Sort by pane (Figure 5-22). 4. Drag LINETOTAL and COSTOFGOODSSOLD to the Sum/Print pane. 5. Under Hide - Field options, for Format in report as, click the ellipsis (...) button. Add commas to the formatting of LINETOTAL and COSTOFGOODSSOLD. 6. Select the Add grand totals to the end of the report check box.
115
7214ch04.fm
8. In the Define field creator window (Figure 5-24), complete the following steps: a. Enter a new field name of Gross_Profit. b. There are three icons on the right side: . The first two icons display the list of fields in various formats including alphabetically and hierarchically. The function icon is used to display the precoded functions that are available. Try the different buttons. Click the list icon ( alphabetically. ). This icon shows the list of available field names
c. Create the formula LINETOTAL - COSTOFGOODSSOLD. Double-click the field LINETOTAL, click the minus button (-) on the calculator pad or on your keyboard, and then double-click COSTOFGOOD. Tip: Field names in the Defined field creator panel must all be in uppercase. d. Click the Format button and define your field as being an integer, 10 long, with commas and a floating dollar sign. It is displayed in the field as I10CM.
116
7214ch04.fm
Tip: When creating your own reports, ensure that the field length is large enough to handle the commas, dollar sign, and maximum digits possible. e. Click OK. 9. Drag your new Gross_Profit field to the Sum/Print pane (Figure 5-25). Verify that the Gross_Profit field is highlighted.
Tip: There are times when you might create one define field based on a second define field. DB2 Web Query processes the defines in the order in which they are entered into the system. The define field must exist before it can be used in a secondary calculation. For more details about viewing the define order of the fields, see Appendix C, Processing differences between the define and compute fields on page 563. 10.Click the Show - Field options arrow near the bottom of the window. a. Select the Title tab. b. Change the column as shown in Figure 5-26, with Gross on the first line and Profit on the second line.
117
7214ch04.fm
If you define your DB2 tables and specify long names, aliases, or column headings, DB2 Web Query uses them. Tip: The IF THEN ELSE constructs allow you to use logic when creating virtual fields. For example, if you want to create your own count of the number of items sold in 2007, you can create a virtual field and use the formula: IF Year EQ 2007 THEN 1 ELSE 0 DB2 Web Query prefers using EQ instead of =.
b. In the Conditional styling window (Figure 5-28), click the wizard icon.
118
7214ch04.fm
c. In the Edit condition window (Figure 5-29), you can define various filters or conditions for which you want to test your data: i. ii. iii. iv. v. Enter the name High_Profit for this condition. For Field, select your test field of Gross_Profit. For Relations, select the is greater than or equal to relationship. Under Please select a value, enter a value of 25000000 (25 million). Click OK.
Values button: The Conditional styling dialog allows you to compare Gross_Profit to another field in your table. If you click the Values button, you see a list of distinct values in the Gross_Profit column.
You can now enter another condition. For example, you might want to create a condition called Low Profit. This allows you to monitor your report and present the high and low in different colors. Note: Now that you have created a condition, you must attach it to your column for it to take effect. You can create one condition and attach it to multiple columns. For example, in a high profit situation, you might want every column in the report to be highlighted. d. From the list of conditions, highlight the one in which your are interested, High_Profit, and then click the add icon on the right side of the window to attach the condition to the Gross_Profit column. That was the column that we started with when we clicked the Conditional styling button (Figure 5-30).
119
7214ch04.fm
13.Define the formatting of the Gross_Profit field when it meets the High_Profit condition. a. Click the Font button. b. To make the profit stand out, highlight it by choosing the Bold style and green for the background color (Figure 5-31). Click OK twice to return to the main reporting window.
120
7214ch04.fm
Note: DB2 Web Query ships with a default style sheet that automatically formats headings and footings. To control the report formatting yourself, you must remove the default style sheet under the Report options tab. 16.Click Run at the top of the window to run your report. Figure 5-33 shows the resulting report. Notice how easy it is to see the high profit items that are highlighted in green.
121
7214ch04.fm
17.Save your report. Click the Save button at the top of the window and select Save As. In the Save Standard Report window, enter the name it RA3_GrossPft and click OK.
122
7214ch04.fm
20.Click the Run arrow at the top of the window to run your report again. Figure 5-35 shows the results of running this report.
123
7214ch04.fm
21.To change the default subtotal heading, make sure that PRODUCTTYPE is highlighted. 22.In the Field options pane, click the new Subtotal tab (Figure 5-36). 23.Under Current Subtotal Text, type Subtotal for. Make sure that you leave a blank at the end because DB2 Web Query appends the product type to your heading.
Tip: By default, all columns are summed to create a total line. You can override individual columns and request that, instead of summing the column, the total line should show the result of calculations such as a count of values or the average of the values. Look at the options under Sum. 24.Click the Run arrow to run the report. Figure 5-37 shows the results of running the report.
124
7214ch04.fm
Tip: If you run your report without selecting the Total option, you see that the report contains detail records instead of summary records. Therefore, it is important to remember to select the Total option. 27.If you do nothing else, your report contains the Gross_Profit column twice. Select the Display tab and click the Make this field invisible option to make Gross_Profit invisible (Figure 5-39).
125
7214ch04.fm
28.Click the Sorting tab and select the Descending sequence. 29.Save your report. 30.Click the Run arrow to run the report. Figure 5-40 shows the results of running the report. Notice that the records within each product type are in descending sequence by gross profit instead of product category.
126
7214ch04.fm
35.Save your report. Click the Save button at the top of the window and select Save As. In the Save Standard Report window, enter the name it RA4_Advanced and click OK. 36.Click the Run arrow at the top of the window to run your report. Figure 5-42 shows the results of running the report. Tip: If you want to produce a Top 10 report, use the ranking capability. From the Ranking tab, you limit your ranked values to 10.
127
7214ch04.fm
Our sample report is not the best to show the on-demand paging feature, but you can see the options that are available with on-demand paging as shown in Figure 5-44. Assume that our report was 201 pages long instead of one page long. When on-demand paging is enabled, DB2 Web Query saves your report on the System i machine and delivers one page of report output at a time to your browser, decreasing the amount of time that you wait for your report to be transmitted. The bulk of your report remains on the System i machine until you request it or close the report. On-demand paging allows you to jump directly to a specific page or to search for a string of information in the report.
Jump
Next page
Search
128
7214ch04.fm
Restriction: The report shown in Figure 5-46 was generated using an imported style sheet. If your PDF report scrolls onto two pages, you run into a known problem with the default style sheet. This problem is being investigated as this book goes to print. Not all style sheets have this problem. See I have my own style sheets that I want to use for my reports. How do I make them available from Report Assistant? on page 491. This FAQ includes information about how to import style sheets. The report in Figure 5-46 was created using the problue.sty style sheet that ships with DB2 Web Query.
129
7214ch04.fm
130
7214ch04.fm
Figure 5-47 shows the output of this report in Excel. Notice the total for Audio in cell F9. If you look at the Excel input line, you see that this is represented as a formula as opposed to an actual value of $162,704,821. This is a helpful feature for users who want to download reports and then analyze the data and possibly delete or move rows of data. Having formulas instead of values in your report allows the total fields to adjust automatically. If you want to see the constant values downloaded, then simply choose Excel 97 or Excel 2000 for your output.
Tip: If Gross Profit is calculated as a compute field instead of a define field, it is also represented in the Excel spreadsheet as a formula.
131
7214ch04.fm
This time when you run your report, the records are inserted in the table that you specify. After the file insert is complete, you see a new window that tells you the number of records that were inserted into the DB2 table (Figure 5-49). Note: See Using output files for the next query on page 429 for recommendations about converting Query/400 definitions that currently create temporary output files in QTEMP.
132
7214ch04.fm
3. Set your output option back to HTML as shown in Figure 5-43 on page 128 or reload your saved report. We continue with the last steps of our example.
133
7214ch04.fm
4. In the EQ Values window (Figure 5-51), select Parameter and then click the Auto Prompt icon ( ).
5. Under Selection, ensure that Dynamic is selected (Figure 5-52). Note: Choosing Dynamic presents the users with a distinct list of current values of the column when the query is run. The Static option allows you to define a predefined set of values. If you allow the users to select multiple values at runtime, they will be able to use the Windows standard Ctrl and Shift keys to select multiple product types. For now, leave it to default to a single input value. For the Description field in the Name section, enter the prompt that you want the users to see. We use the default name for this parameter of PRODUCTTYPE.
134
7214ch04.fm
135
7214ch04.fm
6. To make the drill-down report more understandable, place the product type in the report heading: a. Click the Report headings tab (Figure 5-53). b. Add the words for Type to the heading. c. Select the Show - Field list arrow and drag PRODUCTTYPE to the end of the heading.
136
7214ch04.fm
7. Since we know that this parameterized report is small and, in most cases, it fits on one browser page, remove the default page numbering. Click the Report options tab and for Page numbering, select Off (Figure 5-54).
8. Run the report. Figure 5-55 shows the results of running this report.
137
7214ch04.fm
9. Save and close this report. We now have a report that can either accept a parameter passed by another report or prompt the user for their input.
138
7214ch04.fm
5. In the next window (Figure 5-57), complete these steps: a. Click the Execute procedure radio button. DB2 Web Query populates the list with your reports. b. Navigate through the list until you find your RA4_Advanced report and select it. c. In the Alternate comment for hyperlink field, add a comment for users to see when they hover over the Product Type field. d. Click Add.
139
7214ch04.fm
e. In the Drill-down parameter window (Figure 5-58), complete these steps: i. In the Parameter name field, type the same name as the parameter that the drilldown report is expecting. In this case, type PRODUCTTYPE. ii. Under Parameter value, select the Field option and then select the field that you want passed into the variable PRODUCTTYPE. Select the PRODUCTTYPE field. iii. Click OK.
6. Run your report. Figure 5-59 shows the results of running the report. 7. In the parent or top-level report, the product types are highlighted in blue indicating that they can be selected and you can then drill-down to a more detail report. Click Audio to drill down to see more information.
Figure 5-59 Report Assistant parent (summary) and child (drill-down) reports
8. Save your report: a. Click the Save button at the top of the window and select Save As. b. In the Save Standard Report window, enter the name it RA5_Child and click OK. 9. Close the report and close Report Assistant.
140
7214ch04.fm
141
7214ch04.fm
142
7214ch04.fm
Next you must define the actual join criteria. You tell DB2 Web Query which field from each table that you want to use for your join. See Figure 5-62. Join types:
Unspecified: This option was created for compatibility with prior versions. It is
recommended that, instead of this choice, you select the appropriate options (Inner Join, Left Outer Join, Multiple Instances, Single Instances).
Inner Join: An inner join combines rows from both tables where there is an exact match
between the join fields.
Left Outer Join: This option retrieves records from both primary and secondary tables, including all records from the left table (primary) and any records from the right table (secondary) where the condition values match. If there are no matching values in the secondary table, the join still retrieves the records from the host table. Multiple Instance: A one-to-many join structure that matches one value in the host data source to multiple values in the cross-referenced field. Joining employee ID in a company's employee data source to employee ID in a data source that lists all the training classes offered by that company would result in a listing of all courses taken by each employee, or a joining of the one instance of each ID in the host file to the multiple instances of that ID in the cross-referenced file. Single Instance: A one-to-one join structure that matches one value in the host data source to one value in the cross-referenced data source. Joining an employee ID in an employee data source to an employee ID in a revenue data source is an example of a unique join.
You must remember to click the Save & Create button. If you forget to do this and navigate away from this page, your join is not created.
143
7214ch04.fm
After you save and create the first join definition, you can click New and proceed to define a second join if you want. When you click the Field selection tab, you see that the fields from both tables are available for use (Figure 5-63).
Notice that the columns from the secondary table are in a different color than the columns from the primary table. This is a quick visual check to help identify the different source tables. If you select the Tree icon (between the calculator and the spreadsheet), you can see the fields listed in physical sequence by table. Tip: If you switch to tree mode and hover over a field name, additional information pertaining to that field is displayed.
144
7214ch04.fm
The Report Assistant tool is displayed. Notice that the columns under the list of available fields have two different segment names: ANSWERSET1 and INPUT (Figure 5-65). The columns in the ANSWERSET1 segment are the columns returned in the stored procedures result set. This means they can be used as output fields in the report. Any columns in the INPUT segment can only be used as input parameters to the stored procedure.
3. Create a new input parameter to the report by dragging the INPLANTCODE column from the list of available fields to the Screening conditions area. Click <Select Value> as shown in Figure 5-66.
145
7214ch04.fm
4. Select Parameter and make it a prompt control (drop down list) by clicking the Auto Prompt icon as shown in Figure 5-67 on page 146.
5. To populate the list of plant codes to be displayed in the prompt control, you can select a different data source. Because these values are stored in the ORDERS cluster, select CEN_ORDERS from the list of values for Data Source. This will repopulate the list of fields displayed. Find and select PLANTCODE from this list and click OK. An example is provided in Figure 5-68.
146
7214ch04.fm
Figure 5-68 Specify data source and field to populate prompt control Figure 5-69 on page 147
6. Click OK again. Your Selection Criteria should look like the example in Figure 5-69 on page 147
147
7214ch04.fm
When run, this report will prompt the user for an input parameter. The selected value will be passed as an input parameter to the stored procedure. 7. Next finish your report by doing the following (as displayed in Figure 5-70 on page 148): a. Sort by columns LASTNAME, FIRSTNAME, STATUS, and PAYSCALE b. Sum SALARY column and specify formatting of comma inclusion and floating currency.
8. Save your report as HR Salary Report 9. Run the report. Select a value from the Plantcode prompt control and click Run as shown in Figure 5-71 on page 149.
148
7214ch04.fm
10.As a final step, verify that running the report above resulted in a row being added to the audit log. From any SQL interface, run the following SQL statement: SELECT * FROM rptaudlog ; You should see a row that was logged as a result of running the HR Salary Report through DB2 Web Query: 2009-09-01 09:54:11.896625 HR Salary Report COBBG
149
7214ch04.fm
150
7214ch05.fm
Chapter 6.
Graph Assistant
Graph Assistant provides a wide variety of graph types and graphing functionality to allow users to choose how to present their data in the best possible format. The available graph types range from a variety of bar and line charts to histograms and area charts, stock charts, gauges for key performance indicators, and much more. You can find additional details about the graphing facility in the help text. In this chapter, we continue with the same Century database used in the previous tutorials. In this chapter, we complete the following tasks: Create a simple bar chart that shows revenue by product type within country. We drill down from this graph to the detail report that we created previously with Report Assistant. We then modify this graph to be a dual axis bar and line chart that accepts country as an input parameter. Create a line chart that shows revenue trending over time. The users can specify the time range they want to see. Create multiple pie charts with traffic lighting or conditional styling based on a calculated field.
151
7214ch05.fm
152
7214ch05.fm
We then modify this bar chart to create a dual axis bar and line chart that accepts country as an input parameter. See Figure 6-2.
153
7214ch05.fm
154
7214ch05.fm
3. In the Graph Assistant, click the Graph types tab (Figure 6-4). On this tab, complete the following steps: a. Under Select from the following graph types, look at the various chart types that are available. For graph type, choose a Bar chart type. b. For each chart type, there are many variations shown in the Graph Styles pane. For Graph Styles, select Clustered. c. Look at the various templates under Apply template. Select Cylinder on grey.
155
7214ch05.fm
4. Click the Field selection tab (Figure 6-5). 5. Define the fields that represent the x and y axis for the chart: a. Drag LINETOTAL to the Sum pane. This is our Y axis. b. Drag COUNTRY to the X axis field. c. Drag PRODUCTTYPE into the separate graph area field. By default, this produces one chart for each separate plant.
156
7214ch05.fm
9. Click the Headings tab (Figure 6-6). Graphs can have headings both at the page level and at the individual chart level. Click the Graph tab. Under Chart title, type Revenue by Product Type and for Chart subtitle, type Country Comparison.
10.Save your graph as GA1_Bar and then run it. Figure 6-7 shows the results of running this report.
157
7214ch05.fm
13.In the next window that opens (Figure 6-9), complete these steps: a. Select Execute procedure and a list of your reports is populated in the top white pane. b. Navigate to and select the RA4_Advanced report that you created earlier. After you select your procedure, the Add button becomes available. c. Click Add to add the parameter that you pass from this report to the RA4_Advanced report.
158
7214ch05.fm
14.In the next window (Figure 6-10), complete these steps: a. For Parameter value, select Field and then select the field that you want to pass as the parameter value, which is PRODUCTTYPE. b. Under Parameter name, type PRODUCTTYPE. This name must match the name that the child report is expecting to be passed. We defaulted our parameter name to equal the input column name of PRODUCTTYPE. c. Click OK.
Drill down: When you drill down from one report to another, the child report expects a parameter. In our case, this is the PRODUCTTYPE parameter that is linked in the gross profit report to the PRODUCTTYPE field. In the parent report or graph, you indicate where users can drill down. In this graph, the users can drill down on any LINECODE or bar. When they click a bar, we tell the system that we want the RA4_Advanced report to run. We also indicate that we are going to pass in the PRODUCTTYPE field that is referenced by the selected bar. We do this by passing the value as a parameter called PRODUCTTYPE. Since this is the name of the parameter that the Advanced report was expecting, it accepts the value and executes the report.
159
7214ch05.fm
15.Save and then run this graph. Figure 6-11 shows the results of running this report. 16.Roll over the bars with your mouse. Notice that the cursor changes from an arrow to a hand. The hand indicates that you can drill down in this area. When you hover over a bar, a window opens that shows all the details about the bar. First you see the product type, then the country, and lastly the revenue or line total.
Note: In this drill-down example, we pass the product type to the child report. We could design the report to accept both country and product type. If we do this, when the user clicks the same bar, they can pass the country name as well as the product type as filters or parameters to the Gross Profit report (RA3_GrossPft).
160
7214ch05.fm
3. Modify the existing graph slightly as shown in Figure 6-12: a. In the Create a separate graph for each value of this field, remove PRODUCTTYPE by highlighting the entry and clicking the red Sort Across Remove (X) button. b. Change COUNTRY in the Field value plotted on X axis field, to be PRODUCTTYPE. You can choose one of the following options: Delete COUNTRY by clicking the Sort Across Remove (X) button. Drag PRODUCTTYPE on top of COUNTRY, which does an automatic replace.
Note: At any time during development, you can click the Run button to see how your chart looks up to this point. Using the Update button on the graph preview is useful during development. If you closed your graph preview box, click the Graph Type tab and select Show Graph Preview. 4. Add COUNTRY as a parameter: a. Click the Selection criteria tab (Figure 6-13). b. Drag COUNTRY from the Available field list to the pane on the right. c. In this case, the defaults of WHERE and EQUAL TO are appropriate since we want the user to select or specify a single country. d. Click Select values.
161
7214ch05.fm
e. In the next window (Figure 6-14), select Parameter and click the Auto Prompt icon.
f. In the Parameter Properties window (Figure 6-15), complete these steps: i. Change the prompt that the user sees. For Description, type Select Country:. ii. For the remainder of the window, select the default options. iii. Click OK.
5. Save your report as GA2_Parm. We just created a simple bar chart that prompts the user for country, which you can try and see how it works. Remember that you can run your report or update the graph preview at any time.
162
7214ch05.fm
7. Superimpose Gross Profit as a line on top of the existing bar chart. Since Gross Profit does not exist in the field list, create it: a. Click the Field selection tab. b. On the Field selection tab, click the calculator icon and select New define field (Figure 6-17).
c. In the window that opens (Figure 6-18), complete these steps: i. For Field, type Gross_Profit. ii. To define the field, you can type the formula manually or open the field list pane to the right and double-click the field names to move them over. Enter the following formula: LINETOTAL - COSTOFGOODSSOLD Now Gross_Profit is available for us to use.
163
7214ch05.fm
8. Drag Gross_Profit to the Y axis panel below LINETOTAL. 9. Click Show - Field options - Gross_Profit. 10.Click the Visualize subtab (Figure 6-19), and complete these steps: a. For Force the values on this field to be plotted as, select Line. b. For Place this field on the specified axis, select 2nd axis.
11.Ensure that there is a heading for the graph: a. Click the Headings tab. b. Click the Graph subtab. c. Under Chart title, the graph title is Revenue by Product Type. We do not need a subtitle for this graph. See Figure 6-20.
164
7214ch05.fm
13.In the report that is displayed, for Select Country, select Germany. Then you see the results shown in Figure 6-21.
Figure 6-21 Dual axis bar and line chart with prompting
165
7214ch05.fm
16.Save and run your report. Figure 6-23 shows the result of the chart.
166
7214ch05.fm
17.Close Graph Assistant. With these minor changes, our users are now less likely to misinterpret the dollar values.
167
7214ch05.fm
168
7214ch05.fm
169
7214ch05.fm
3. In the next window, click the Graph types tab. 4. On the Graph types tab (Figure 6-26), under Select from the following graph types, select Line. Then under Select from the following Graph Styles, select Absolute.
5. To show product revenue trending by month, you must plot one point for every month for each product. To do this, convert the date field from year, month, and day to a field with just the year and month. a. Click the Field selection tab. b. Click the calculator icon and select New define field (Figure 6-27).
170
7214ch05.fm
c. In the Define field creator window (Figure 6-28), complete these steps: i. For Field, type MthYr. ii. In the pane below Field, where you define the formula for the new field, type ORDERDATE, which is the name of the date on which MthYr is based. iii. In the Format field, type TMYY. T means that the month or day immediately following will be represented as uppercase text. A single Y means that you want to display a two-digit year, but YY means that you want to display a four-digit year. An example of a MthYr value is Jan, 2007. If we want to place the year first, we specify a format of YYTM. DB2 Web Query is powerful when it comes to working with date and time fields. See Date and time system variables on page 514 for many of the different ways you can work with date and time fields. iv. Click OK.
171
7214ch05.fm
d. On the Field selection tab (Figure 6-29), complete these steps: i. Drag MthYr to the Field value plotted on X axis (our main X axis) pane. Drag LINETOTAL to the Sum/Print pane under Field value(s) plotted on Y axis. Under Create a separate graph for each value of this field, specify PRODUCTTYPE. Tip: You must place LINETOTAL in the SUM/Print pane before you can drag PRODUCTTYPE to the Create a separate graph for each value of this field pane. ii. Click Show - Field options - PRODUCTTYPE. Select the Merge graphs into a single graph option.
172
7214ch05.fm
6. Since an entry on an axis of Jan, 2007 is obviously a date, remove the heading or label for MthYr from the graph (see Figure 6-30): a. Under Field value plotted on X axis, highlight MthYr. b. Click Show - Field options - MthYr and under X axis field label, delete the label MthYr.
173
7214ch05.fm
8. Run your report. Figure 6-31 shows the results of running this report.
9. Change the X axis to rotate the text and make it look better: a. Click the Properties tab and then click the X axis subtab. b. Click the Style labels button.
174
7214ch05.fm
c. In the X Axis Properties window (Figure 6-32), complete these steps: i. Under Set Style for, select Data. ii. Some of the options initially are unavailable because a default style sheet is in effect. Select the Because automatic arrangement is turned on, certain style options are disabled. Check here to override defaults check box. iii. For Text rotation, select 45-degree bottom to top. iv. Click OK.
175
7214ch05.fm
10.Save and run your report. Figure 6-33 shows the result of running this report.
176
7214ch05.fm
To filter the dates: 11.Click the Selection criteria tab (Figure 6-34). 12.Drag MthYr to the Screening conditions pane on the left. 13.In the Screening conditions pane, complete these steps: a. To select the records as we read them, use the WHERE default as opposed to WHERETOTAL. b. As stated previously, our range is all orders inclusively from July 2006 to June 2007. For our first WHERE clause, for MthYr, select GREATER THAN or EQUAL to and then click Select values to enter the date. c. In the GE Values window, select Constant and type 072006.
177
7214ch05.fm
14.Drag MthYr to the Screening conditions pane (see Figure 6-35). 15.Notice that, by default, the two conditions that you define will be ANDed together. 16.In the Screening conditions pane, complete these steps: a. Select LESS THAN or EQUAL to and click Select values. b. In the LE Values window, select Constant and type 062007. You have now defined a range where 072006 <= MthYr <= 062007.
17.Save and run your report. Figure 6-36 shows the results of running this report. Notice that our report now starts with July and ends with June.
178
7214ch05.fm
Here are a couple of options that achieve the same results: Option 1 i. Remove the selection criteria that we specified. In the Screening conditions pane (Figure 6-37), select both conditions. Then click the red X under the text Screening conditions to remove them.
ii. Using the same steps as we did with MthYr, this time drag ORDERDATE to the Screening conditions pane and specify the full date. See Figure 6-38.
iii. Run your report. It should look exactly the same as our previous report.
179
7214ch05.fm
Option 2 i. ii. iii. iv. Remove the previous screening conditions. Drag ORDERDATE to the Screening conditions pane. Select FROM - TO and click Select values. In the FROM-TO values window (Figure 6-39), for the From criteria, type 20060701, and for the To criteria, type 20070630.
180
7214ch05.fm
21.Again drag ORDERDATE to the Screening conditions pane. 22.In the Screening conditions pane (Figure 6-41), complete these steps: a. Select LESS THAN or EQUAL to. Click Select values. b. In the LE Values window, select Parameter and name the parameter TO_DATE.
181
7214ch05.fm
23.Save and run your report. Figure 6-42 shows the results of running this report.
182
7214ch05.fm
In this exercise, we saw multiple ways to hard code a date range and how to have the user specify a variable date range.
183
7214ch05.fm
2007
Audio (24%)
Figure 6-43 Yearly pie charts with conditional styling or traffic lighting
184
7214ch05.fm
3. On the Graph types tab (Figure 6-44), under Select from the following graph types, select Pie. For Select from the following Graph Styles, select Basic.
In this example, we create a pie chart for each year in our data. We do not currently have a field that contains just the year. 4. Click the Field selection tab. 5. Click the calculator icon and select New define field.
185
7214ch05.fm
6. In the Define field creator window (Figure 6-45), for Field, type Year and for Format, type YY. Remember that this creates a four-digit year, for example 2007. In the pane under Field, specify that the field is to be based on ORDERDATE. Click OK.
Tip: If you are tired of splitting ORDERDATE into its various components for each report, make sure that you continue to progress to the tutorial in 12.1.1, Date Decomposition on page 348. This tutorial shows how to automatically break down a date and make the components available to all reports. 7. Click the Field selection tab to define the fields used in the pie chart. See Figure 6-46 on page 187. 8. Drag PRODUCTTYPE to the Field value plotted on X axis pane. This means that we will have a pie slice for each product type. 9. Drag LINETOTAL to the Field value(s) plotted on Y axis box. This means that the product type pie slices will be proportionately sized based on the LINETOTAL summed values. 10.Drag Year to the Create a separate graph for each value of this field pane. By default, this creates a separate graph for each value in Year.
186
7214ch05.fm
11.Click Show - Field options - Year. a. Select the Display graph in number of columns option. b. Type a value of 2 next to the Display graph in number of columns option to indicate that you want two graphs across the page. If you had six different years, these settings would create six pie charts in a 2 x 3 layout. If you specified six across, you would have six, small pie charts across the page in a single row.
187
7214ch05.fm
13.Often a graph is easier to read without a legend. Instead we want the labels directly on or next to the pie slices for easy readability. Click the Properties tab and the Pie subtab (Figure 6-47). a. In the Graph preview window, select the Automatic update option. Whether you permanently work in Automatic update mode is strictly a performance question. Tip: If you closed or lost your Graph preview window, click the Graph types tab and select Show graph preview. b. While viewing the Graph preview window, select Show pie labels. c. Try selecting the different option combinations from both columns to see the results. In the end, select the Labels only and Slice label and % value options. d. In the Graph preview window, clear the Automatic update option.
14.As you can see in the Graph preview, you still see the legend, which duplicates the information on the slice labels. To remove the legend from your pie chart, click the Properties tab and the Settings subtab.
188
7214ch05.fm
15.On the Settings tab (Figure 6-48), clear the Show legend option.
16.Tell DB2 Web Query the size to make each of our pie charts: a. Click the Properties tab and the Options subtab. b. On the Options tab, select Custom size. For Horizontal, type 400 pixels, and for Vertical, type 300 pixels.
189
7214ch05.fm
17.Save your chart as GA4_Pie and run the report. Figure 6-50 shows the results of running this report.
2006 2007
Audio (24%)
As we expect, notice how similar the graphs look compared to the Graph preview window in Figure 6-47 on page 188.
190
7214ch05.fm
1. If you are still in your GA4_Pie report, click the Field Selection tab (Figure 6-51). If this report is not open, open the GA4_Pie report. On the DB2 Web Query home page, right-click the GA4_Pie report and select Open. 2. To create a compute field, select the Wizard icon next to the Print button.
191
7214ch05.fm
3. In the Compute field creator window (Figure 6-52), for Field, type MARKUP. Specify the formula in the pane below Field. Type the following text in the pane: ((LINETOTAL - COSTOFGOODSSOLD) / COSTOFGOODSSOLD) * 100 You can either type the field names or select them by double-clicking the names on the left. The DB2 field names must be in uppercase. Click OK.
While MARKUP is a field that we need to reference in our conditional styling, we do not want to display a graph of MARKUP data. 4. Under Field value(s) plotted on Y axis, highlight MARKUP. 5. Click Show - Field options (Figure 6-53). On the Display tab, select the Make this field invisible option. This makes MARKUP available to the report but does not display it on the graph.
192
7214ch05.fm
6. Define the pie slices that you want to highlight (Figure 6-54): a. Highlight LINETOTAL under Field value(s) plotted on Y axis. b. Click Show - Field options. c. Click the Conditional styling button.
e. We want to highlight the pie segments or slices that have a lower markup than our company standard of 35% (Figure 6-56). i. ii. iii. iv. v. Give this condition the name of Low_Markup. For Field, select MARKUP. For Relations, select is less than or equal to. For Please select a value, type the value of 35. Click OK.
193
7214ch05.fm
f. Attach the condition definition to LINETOTAL and define what happens when this condition is satisfied. i. Highlight Low_Markup and click the Add Condition icon. See Figure 6-57.
ii. Click the grey color indicator box (circled in Figure 6-58 on page 195).
194
7214ch05.fm
iii. In the Color window (Figure 6-58), select the color that you want the pie slices when the slice meets the Low_Markup condition. In this example, choose Red.
7. When modifying a report by applying filters or using traffic lighting, we recommend that you indicate this information on the report itself. You typically do this via a subheading or a page footing or footnote. a. Select the Headings tab and click the Graph subtab (Figure 6-59). b. Under Chart footnote, type Red pie slices indicate an average markup of less than 35%.
195
7214ch05.fm
8. Save your report and run it. Figure 6-60 shows the results of running this report.
2006
Audio (25%) Video (33%) Video (34%)
2007
Audio (24%)
196
7214ch06.fm
Chapter 7.
Power Painter
Power Painter is a Web layout and report creation tool. It is built using the new AJAX technology. This allows a thin browser to deliver advanced functionality without add-ons and plug-ins. With HTML, you must update the entire panel. With AJAX technology, the application can update portions of the panel for improved flexibility and performance. Power Painter allows you to create a compound report combining multiple graphs and charts on a single page. You can link the various charts together all tied to a common sort group. Power Painter supports a live feed to your data to allow for real What You See Is What You Get (WYSIWYG) report creation. With Power Painter, you can use multiple data sources to build your compound reports. In this tutorial, we build reports similar to those that we built using Report Assistant and Graph Assistant. The idea is for you to become familiar with the various ways of achieving similar end results. We lay out the report and graph on one page, link them by COUNTRY, and tailor the request for PDF output.
197
7214ch06.fm
198
7214ch06.fm
4. Set Power Painter User Preferences a. Changing the Reports & Graphs preview settings to sample data will improve development performance while using Power Painter. You can set your Power Painter user preferences by choosing Edit -> Preferences. b. In the Preferences Window (Figure 7-3) Click on the Reports & Graphs tab and uncheck the Use Live Data option. You can also change the Record Limit to 100 to improve building the sample reports and graphs.
199
7214ch06.fm
You will want to change which palettes are open based on the work that you are doing. The example in Figure 7-4 is one design that appears to work quite well and will be used in this tutorial. a. Click the pushpin button of the open Properties palette. This temporarily makes it a tab on the right side. We bring it back to the main docking area later. b. Either choose View Palettes Query or click the query icon (multi-colored circle with a question mark, circled in Figure 7-4). c. Drag the query palette to the right, underneath the Toolbox, and above your Data Sources palette.
While you initially lay out your report, the two main palettes that you use are the Query palette and the Data Sources palette. After you select your columns, you can move the Properties box back to the docking area and click the pushpin button for Data Sources so that it minimizes to the side. This keeps the Query and Properties palettes in full view while you design the desired layout and design of your report. You can have more than two palettes open and docked, but they can become a little small to work with effectively. In this report, we want our page to start with our logo or picture and a heading, with a graph below the logo and heading, and the main report below the graph.
200
7214ch06.fm
201
7214ch06.fm
5. In the New Chart window (Figure 7-6) that opens, you see that Power Painter offers more advanced graph controls in most areas than Graph Assistant. For this example, select the default Vertical Clustered Bar chart. If we want to display a series of bar charts, for example, one bar for each year for each representative, then we select the CrossTab box. However, we do not need to do this for this example. Click Finish.
6. Define the columns that are required in the graph. Similar to Report Assistant and Graph Assistant, you can view column names in multiple sequences, including in alphabetical sequence, or in a tree type hierarchy based on table names. Remember that our Orders data source is composed of multiple tables that are all joined automatically by foreign key definitions. The icons in the Data Source bar allow you to change the displayed sequence. Use the drop-down arrows on both the hierarchy structure icon and the list icon to see the different choices.
202
7214ch06.fm
7. To include a field on the report, drag the field name either onto the graph that you just created or onto the Query palette. When you drag a field onto the report area of the canvas, a Query palette opens. a. Drag LINETOTAL onto the Y Axis label. See Figure 7-7. Tip: Make sure that you select your graph before you drag the field. The open Query palette relates to the highlighted object.
203
7214ch06.fm
c. Drag COUNTRY onto the Coordinated label (Figure 7-9). Tip: Coordinated fields are common sort fields and filters that tie together the various reports and graphs on your page. Each change in the coordinated field causes a page break. The report layout you define is repeated for each new value.
8. Save your report as PP1_PDF. 9. After choosing most of the fields, you might find it easier to bring the Properties palette to the front and minimize the Data Sources palette: a. Click the pushpin icon to minimize the Data Sources palette. b. Double-click the Properties tab on the right side of the window to redock the Properties palette. Now any time you select a field in the query palette, you see that fields properties in the Property palette.
204
7214ch06.fm
Tip: The Property box changes between Document properties, Report properties, and Column properties. If you select a column in the Query palette, you see the properties that relate to that column. If you select a graph or report, you see the basic graph properties or report properties. And if you click the white space on the canvas outside of a report, you see the overall properties for the document. 10.Select a graph to open the Basic Chart Properties window (Figure 7-10). To see all the chart properties, you must open the Chart Editor. Click either the Show Chart Editor icon or select View Palettes Chart Editor.
11.With the Chart Editor (Figure 7-11 on page 206) open, the options that you select control the properties displayed in the properties panel. To read all of our region names, we must orient them differently on the graph: a. In the Chart Editor panel, select Ordinal axis and then select Labels. b. From the Properties panel, for Text rotation, under the Value column, select 45 degrees to present the region names on a 45 degree angle. c. Look at the various properties available between the Chart Editor and the properties box. This is where you will completely control the appearance of your graph. You define your traffic lighting or conditional styling here. You can choose whether one series shows as bars while a second series is displayed as a line chart and much more. Our graph is now complete.
205
7214ch06.fm
12.Add a heading to the report: a. From the Toolbox, select the Text icon (Figure 7-12).
b. Draw a rectangle where you want to place the heading of your report. c. Type a report title of Sales Analysis by Country. d. Click Font Properties.
206
7214ch06.fm
e. In the Edit Font window (Figure 7-13), complete these steps: i. ii. iii. iv. v. Choose a font; we choose Arial. Under Options, select blue for Text Color. Under Style, select bold and underline. Under Size, select 14. Click OK.
13.Add a date and page numbers to the report: a. Select the Text icon from the toolbar and draw a rectangle where you want to place the text on your report (Figure 7-14).
b. Select the Insert Date/Time and select the date format that you want to see (Figure 7-15).
c. After the date that you just inserted, press the Enter key to force a new line and type Page.
207
7214ch06.fm
14.Select the Font Properties button and make your new text the same color as your report heading (Figure 7-17).
15.In the Edit Font window (Figure 7-18), change the font size to 10 so this text is smaller than the main heading. Click OK.
208
7214ch06.fm
16.Save and run your report. Figure 7-19 shows the results of running the report. Notice that you have one page for each graph. When the coordinated column COUNTRY changes, a page break occurs.
Canada
180M 160M 140M
Revenue
da
an a
rn
te
Ea s
Region
Now that our graph is complete, we create the coordinated report as explained in the next section.
es t
er
an a
da
209
7214ch06.fm
4. Drag SALESREP to the new report area and a Query palette opens. Drop SALESREP in the By folder. See Figure 7-20.
You can drag fields directly to the report, or you can drag them to a query palette that you open and dock. Tip: When creating a report, you can select one or multiple fields from the data source list and then drag them to the canvas. DB2 Web Query automatically creates a region for the report, autosizes it, and places alpha fields in the Sort By folder and numeric fields in the Sum folder. Try it. If you have a small table or view, you can drag the entire table to the canvas and have an instant one-click report.
210
7214ch06.fm
6. Drag the remaining columns as shown in Figure 7-22 onto the Query palette. You do not have to drag COUNTRY under the Coordinated folder. After you place a column under the Coordinated folder, it is automatically there for every report or graph in your layout. You have now specified the columns to use in your query.
211
7214ch06.fm
7. Add some subtotals when the sales representative changes and when the country changes. Also add grand totals at the end of the report: a. Open the query palette if it is closed. b. Highlight SALESREP and go to the Properties pane. Scroll down to Subtotal and click the ellipsis (...) button. c. In the Sub Total Options window (Figure 7-23), select the Sub Totals radio button. In the Current Subtotal Text field, type subtotal for and click OK. The default for a column is to sum or total it. This can be overridden, and you can request column functions such as average or count.
d. Add the grand totals for each section or country in our report. To do this, we need Country as a By column not just a Coordinated column. i. Select Country from the Data Sources pane, add it as a By column, and then move it to the top of the By column list. We do not want to see a column for Country in our report since it is the same on the entire page. We must hide the column, but still have the properties available to indicate that subtotaling is desired. ii. Open the Query palette if it is closed. iii. Highlight COUNTRY under the By folder and go to the Properties display. iv. In the Field properties panel, for Visible, select No. Scroll down, highlight subtotal and click the ellipsis button.
212
7214ch06.fm
v. In the Sub Total Options window (Figure 7-24), click the Sub Totals radio button. Under Current Subtotal Text, type Grand totals for and click OK.
e. Add the grand totals to the report. These totals are not associated with any specific column changing but rather with the report itself. i. Highlight the report and go to the Report properties panel (Figure 7-25). ii. In the Report properties pane, locate Column totals and select Totals.
8. If the report is longer than the frame that we have drawn, complete these steps: a. Highlight the report so that you can work with the Report properties. b. The Overflow property controls what happens when the report has too many rows to be displayed in the defined region. The default value of Fixed indicates that the report is restricted to the exact area that you defined. If it overflows, the rows continue in the
Chapter 7. Power Painter
213
7214ch06.fm
same area on the next page until the report is complete. If you select Flowing, the report ignores the vertical boundaries and flows from the top to the bottom of each following page until it is complete. We want our report to take full pages and flow until it is finished. Make sure that the Sizing and Overflow parameter is set to Flowing (Figure 7-26).
c. Next you can add a flow relationship linking the reports location with the graphs in Power Painter. Related objects will allow multiple flowing reports to be presented without overlapping each other. To relate the objects, first select the Report object. Then hold the CTRL key and select the Graph. Once each object is selected click on the Relate Object icon as shown in This icon will relate the objects by the order selected. This relationship is graphically shown as an arrow between the Report and Graph.
9. Save and run your report. Figure 7-28 on page 215 shows the results of running this report.
214
7214ch06.fm
10.Notice that the report is quite long as indicated by the number of pages at the bottom of the window (1 of 100). Trying to find any individual country can be time consuming. To solve this problem, add a table of contents with an entry every time the COUNTRY changes; we have a page break and the report layout starts over again. From the Query palette under Coordinated, highlight COUNTRY. In the Field properties pane, and for Table of contents, select Yes (Figure 7-29 on page 216).
215
7214ch06.fm
11.Save and run your report. Figure 7-30 shows the results of running this report.
216
7214ch06.fm
12.Now add a URL drilldown on the SALESREP field in your Power Painter report. Open the Query Panel and select the SALESREP Field. Once the field is highlighted the SALESREP field properties will be toggled into the Properties Panel. Click on the Click here to edit" Drill Down option to open the prompt and enter http://www.google.com/search?(q=COUNTRY) into the URL field. (See Figure 7-29) Note You can also specify the drill down to run a DB2 Web Query Procedure. Section 5.4.2, Drill-down reports: Parent report (RA5_Child) on page 138: Parent report (RA5_Child) discusses how to use Procedural drill downs.
13.Save the report and run your report. Notice the SALESREP field now has a hyperlink on it. Click on a hyperlink to see how the URL drill down will open a browser with the dynamic search string. You have now created your first compound PDF report using Power Painter.
217
7214ch06.fm
A dialog window opens that displays all of the image files that reside in the \QIBM\UserData\webquery\ibi\apps\baseapp folder. 4. From the list, select the image you want to add to the layout and click OK as shown in Figure 7-33 on page 219.
218
7214ch06.fm
5. Outline the area where you want the image to be located on the page. The image appears in the box you outlined as shown Figure 7-34.
6. Save and run your report. Figure 7-35 on page 220 shows the results of running this report
219
7214ch06.fm
7214ch06.fm
5. Add a new chart to the layout by select the Chart icon in the Toolbox palette (Figure 7-37)
6. From the New Chart dialog window, select the funnel chart on the first row (far right), then select the gauge chart (first chart in the second row). An example is displayed in Figure 7-37.
7. Click Finish button 8. As shown in Figure 7-39 on page 222, define the gauge charts sum column by selecting the LINETOTAL column (under CEN_ORDERS in Data Sources palette) and drag it into Sum (under Chart - CEN_ORDERS in Query palette).
221
7214ch06.fm
At this point, your work should something like the example shown in Figure 7-40.
9. Change the gauge background style by selecting General (under the Chart Editor palette), and selecting Blue Bevel from the drop down list for Gauge background style. An example is shown in Figure 7-41 on page 223.
222
7214ch06.fm
10.The gauge chart will contain 3 band ranges. Set up format for first band. Under Gauge axis, select Band 1 format and make the following changes (as shown in the example in Figure 7-42 on page 224) d. Maximum value: 800000000 (or 8.0E8) e. Minimum value: 0.0 f. Border color should already be set to red. If not, click on color icon and set Border color to red. g. Band color should already be set to red. If not, click on color icon and set Band color to red.
223
7214ch06.fm
11.Set up values for band 2. Under Gauge axis, select Band 2 format and make the following changes (as shown in the example in Figure 7-43 on page 225) a. Maximum value: 1200000000 (or 1.2E9) b. Minimum value: 800000000 (or 8.0E8) c. Double-click on color icon for Border color and select yellow. d. Double-click on color icon for Band color and select yellow.
224
7214ch06.fm
12.Finally, set up the third band. Under Gauge axis, select Band 3 format and make the following changes. a. Maximum value: 2000000000 (or 2E9) b. Minimum value: 1200000000 (or 1.2E9) c. Double-click on color icon and set Border color to green d. Double-click on color icon and set Band color to green 13.Save your report as pp_gauge 14.Run your report. It should look like the example shown in Figure 7-44 on page 226.
225
7214ch06.fm
Note: There is a lot more that you can do in Power Painter. This tutorial has barely scratched the surface. Try dragging multiple fields at once on the page, and you will have a new report. You can also try looking at relationships and using the advanced graphics. You can open any Report Assistant or Graph Assistant report in Power Painter. This gives you a starting point before you continue to add new reports using the Power Painter functionality.
226
7214p03.fm
Part 3
Part
227
7214p03.fm
228
7214ch07Act_Rpt.fm
Chapter 8.
Active Reports
Active Reports is an optional feature that is available from IBM for DB2 Web Query. While the base product is licensed to named users, Active Reports is licensed to a System i machine, based strictly on the software tier (P10, P20, and so on). Any user who can create a report using either Report Assistant, Graph Assistant, or Power Painter is entitled to create an Active Report. Since Active Reports is intended for disconnected users, individual users do not require a license to use the reports. The HTML reports must be made available to users either by e-mail, a shared network drive, or additional tools, such as Report Caster, from Information Builders. As you will see in this chapter, with Active Reports, the data and the reporting controls are all stored within the HTML page. When the user has access to the HTML page, the user can access, manipulate, and analyze the data with no requirement for any additional licensing. With Active Reports, for example, a sales person might sign on to the System i environment in the morning and run a report for each customer they plan to visit that day. Then they can save the reports on their local hard drive. From their car, the sales person can then look at and analyze the data for their customer immediately prior to visiting them. Attention: To use Active Reports, the server requires a license key that can be purchased as an optional feature of DB2 Web Query (5733-QU2).
229
7214ch07Act_Rpt.fm
230
7214ch07Act_Rpt.fm
231
7214ch07Act_Rpt.fm
3. On the Report options tab (Figure 8-2), complete these steps: a. For Generate report as, select AHTML - Active Report. When you select this option, notice that the Active Report Styling button becomes active. At this point, you might run the report. However we a make a few formatting and highlighting changes first. Note: Horizontal (Across) sort fields are not supported for HTML Active Reports. b. Click the Active Report Styling button.
232
7214ch07Act_Rpt.fm
c. In the Active Report Styling window (Figure 8-3), under Report view, select Tabular. For Row selection, select yellow. For Visualization colors, select red for Negative and dark green for Positive. Click OK. Note: In this window, we define the presentation and initial look of the report for the user. We discuss Accordion reports later in the tutorial.
.
4. Save your report as AR1_GrossPft. 5. Run your report. Figure 8-4 shows the results of running the report.
233
7214ch07Act_Rpt.fm
6. Click a down arrow next to any column and select Save Changes (Figure 8-5). Save your report as AR1_GrossPft.html. Note: You can also use the Save As option in your browser to save the HTML page. If you choose the Export option instead of the Save Changes option, you export the records without formatting and controls. The records can be exported to an HTML page, Excel, and comma separated values (CSV) files.
Tip: After you save your report as an HTML file, you can send it to users by using e-mail. In this case, the recipient can view and analyze the report with no connectivity to the System i environment. To run and save an Active Report, you must be a named user. To work with the HTML file after it is created, you do not need to be a named user. In the next section, we continue to work with this Active Report, but we do this so as though we are the disconnected user and not the developer.
234
7214ch07Act_Rpt.fm
3. To make the report fit better on the page, we hide the Cost of Goods Sold column. To hide a column, click the down arrow next to Cost of Goods Sold and choose Hide Column (Figure 8-7).
235
7214ch07Act_Rpt.fm
4. The Visualize feature is a powerful tool that allows you to see, at a glance, relationships between various columns. Click the down arrow for the Gross Profit column and select Visualize. See Figure 8-8.
Notice the green or red bars that are displayed in the chart in Figure 8-9. Visualize gives you a quick visual representation of the data in a column. 5. Click the down arrow for the Revenue column and select Visualize. Now you see the bars for the Revenue column as well. With the visualize bars, it is much easier to spot relationships. Notice that although speakers is not ranked high in the Revenue column, they are extremely profitable and generate the third highest profit of any product category.
6. Click the down arrow for Gross Profit. Select Calculate % of Total (Figure 8-10). 236
Getting Started with DB2 Web Query for i
7214ch07Act_Rpt.fm
237
7214ch07Act_Rpt.fm
Notice that a new column, called % of Total, is now displayed that shows each product category row as a percent of the total Gross Profit in this report (Figure 8-11). 7. Click the down arrow for Gross Profit and select Sum. Your summary prints at the top of the page by default.
238
7214ch07Act_Rpt.fm
8. Filter the report temporarily so that we can concentrate on our audio sales. Click the down arrow for Product Type and choose Filter Equals (Figure 8-12).
9. In the Filter Selection window (Figure 8-13), click the down arrow on the right to see a list of the distinct values in a field. Select Audio from the list. Then click Filter. Highlight button: If you click the Highlight button instead of clicking the Filter button, your report contains all the records, but highlights the ones that meet the filter criteria.
Contains operand: Besides your standard operators, such as Greater Than and Equal, you can search for a string of data anywhere within a field using the Contains operand. By default, Contains is not case sensitive. If case is important, there is an additional operand Contains (match case). There are also similar Omits and Omits (match case) options.
239
7214ch07Act_Rpt.fm
10.In the filtered chart (Figure 8-14), you see both your filtered sum and the total sum for a column. In the upper left corner, click the new SUB/TOT icon. It enable you to cycle through viewing the sum of all your data, the sum of your filtered data, and having both sums displayed concurrently. At any point, you can choose the Restore Original option. To see all the records, close the Filter Selection window.
11.A helpful way to analyze the data involves changing the grouping and looking at your numbers slightly differently. Select the down arrow for Gross Profit and select Rollup Group By Product Category (Figure 8-15).
240
7214ch07Act_Rpt.fm
12.Click the Pie chart graph icon to change the report that you are looking at into a pie chart (Figure 8-16). You can choose line or bar charts as well.
13.Export the chart to Microsoft PowerPoint, Excel, and Word. Click the first List type icon and select Export to Excel (Figure 8-17).
You can access the same graph directly from your full report by clicking the Gross Profit column, selecting Chart, Pie, and Product Category as your Group by field. Tip: If you created filters, then plotted your graph, and closed the filter, by default, your graph changes to reflect the displayed report or all the data. To keep the chart as is, displaying the filtered data, select the Lock icon.
241
7214ch07Act_Rpt.fm
14.Export to the other Microsoft product if you have them loaded on your system. 15.Close Excel and close the charting window. 16.To use the Rollup functionality, select the down arrow for Gross Profit and select Rollup -> Product Type as the field to Rollup as shown in Figure 8-19.
17.Once a Rollup window is open you can add another measure using Add(Y), to add Revenue to this Rollup window. Click on the Add Icon -> Add(Y) --> Revenue as shown in Figure 8-20 on page 243. This will add the Revenue field to the Rollup window.
242
7214ch07Act_Rpt.fm
Note: You can also add new Grouping Fields to the Rollup Window using the Group By (X) selection as shown in Figure 8-20.
18.To use the Cross tab or Pivot functionality, select the down arrow for Gross Profit and select Pivot Product Category Product Type as the field to go across the top of your table (Figure 8-21).
Note: This report is not a good one to demonstrate cross tab or pivot functionality. There are not enough fields shown that relate to each other, for us to pivot on. The next steps illustrate additional capabilities of Active Reports.
243
7214ch07Act_Rpt.fm
19.When you have a basic pivot table, you can start adding to it, changing it, and pivoting it. Click the left (circled in Figure 8-22) icon above Product Type.
Clicking the icon to the left of the arrow moves a field back and forth between being a column or a row, pivoting on that field. Notice in Figure 8-23 that the title changes as the column layout changes.
Figure 8-23 Changing sort breaks and sort priorities for Active Reports
There is quite a bit more that you can do with pivot tables if it makes sense for your data. You might ask to see the average profit numbers, for example, if you have more than one record per row grouped together. Tip: To size the window shown in Figure 8-23 on page 244, scroll down to the bottom of the window. In the right corner is an area that you can drag to widen and size the pivot table. Click once outside the box after you finish dragging to release the cursor.
244
7214ch07Act_Rpt.fm
As you can see, Active Reports allow users to quickly add a level of analysis to their reports, all without being connected to the System i environment. Let us look at the difference between a tabular and accordion Active Report: 1. If your report definition is closed, go to the DB2 Web Query home page navigate to it, right-click, and open it. 2. Click the Field selection tab (Figure 8-24). 3. On the Field selection tab, complete these steps: a. Remove subtotals from PRODUCTTYPE. b. Clear the Add grand totals to the end of the report check box. Restriction: With earlier versions of the software, subtotal and total messages occasionally appeared in an accordion report. It is easiest to remove them now.
Figure 8-24 Removing subtotals and selecting the option to add grand totals to the end of the report
4. Click the Report options tab. 5. On the Report options tab, complete these steps: a. Click the Active Report Styling button. b. Select Accordion instead of Tabular and click OK.
245
7214ch07Act_Rpt.fm
6. Run your report. Figure 8-25 shows the results of running the report with the Accordian option selected. Only the data values at the highest level (first vertical sort field) are shown initially.
7. Click the plus sign (+) to expand a field. Click the minus sign (-) to compress the data. In our example, we expand Audio and see all the Product Categories within Audio (Figure 8-26). If we had more Sort By columns in our report, we could expand each of the levels.
8. Look at some of the other options that are available under the arrows. You will see that you can export data to CSV files, to HTML files and directly into Excel. If you filter your data, you have the choice of exporting the entire data set or just the filtered records. Tip: HTML Active Reports can support up to 20,000 rows of data. If you are using a Firefox browser, we recommend that you use only up to 15,000 rows of data. If you are using an Internet Explorer browser, use only 5,000 rows of data.
246
7214ch07Act_Rpt.fm
8.4 Summary
Active Reports is a tool that works extremely well when your users are remote and not connected to the System i environment. Even with local users, there are no named user licensing requirements to work with and analyze an Active Report. You can create an Active Report and send it by e-mail it to a user for the user to analyze it. The person who originally runs the report must be a licensed named user. The report is stored in a highly compressed format. Active Reports is just one more powerful reporting tool for you to use with DB2 Web Query.
247
7214ch07Act_Rpt.fm
248
7214ch08MRD.fm
Chapter 9.
Developer Workbench
Developer Workbench provides an integrated development environment (IDE) for building and maintaining a DB2 Web Query reporting environment. Developer Workbench includes additional tools to work with your metadata. The Synonym Editor allows you to change the way a field is displayed to the users. You can add commas and decimal signs, convert date formats, convert alpha to numeric fields, or even change the length of a field. The Synonym Editor also allows you to create calculated fields for users. You can predefine joins for the users or create business views that simplify the structure and number of columns the user sees. If you plan on using the optional online analytical processing (OLAP) feature, you must define your hierarchies or dimensions with Developer Workbench. Using the metadata layer, Developer Workbench provides the ability to perform impact analysis at both a file level and a field level. If you must make changes to a field, you can see which reports and graphs use that field and the business views that it is part of. Developer Workbench provides the capability to profile your data. Profiling allows you to see patterns in the text characters. For example, profiling telephone numbers in the Stores table might show us that five records have a format of nine numeric characters instead of ten. We might want to know if these five records are a quality problem. Data profiling also shows the minimum and maximum values in a column and identifies the outliers. The SQL Wizard allows you to import SQL into Report or Graph Assistant. One of the major tools within Developer Workbench is the HTML Composer component. HTML Composer is specifically designed to create HTML pages that can contain compound reports or dashboards. You can find a complete tutorial for this component in Chapter 11, HTML Composer on page 289. In this chapter, we configure the System i DB2 Web Query environment and set up some Developer Workbench default settings. This chapter is a prerequisite for both Chapter 10, Online analytical processing on page 257, and Chapter 11, HTML Composer on page 289. For more information about Developer Workbench, see Chapter 12, Additional features of Developer Workbench on page 343.
249
7214ch08MRD.fm
250
7214ch08MRD.fm
b. In the next window (Figure 9-2), complete these steps: i. Type a description of your System i environment. ii. For Host Name/IP Address, type a name. iii. For Port, verify that 11331 is selected. Tip: If you changed the default DB2 Web Query default port number, you must clear the Use Default box and specify your installations port number. iv. For HTML Alias, ensure that it is /webquery_html. v. Click OK.
251
7214ch08MRD.fm
3. The first time that you open the System i environment or connection that you just added, you must sign on. Sign on with your administrator or developer authorized profile. See Figure 9-3. Tip: Select the Remember my User Name and Password on this computer option in this sign on and the next sign so that you are not prompted with these sign-on windows again for this System i connection. Click Logon.
252
7214ch08MRD.fm
4. Expand system name Data Servers EDASERVE (Figure 9-4). 5. Log on again. Enter your user name and password and click Logon.
6. Continue down the metadata path by expanding EDASERVE Applications. Select baseapp.
253
7214ch08MRD.fm
In the right pane of Figure 9-5, you see all your metadata or your master (.mas) and access (.acx) files. Remember that the master file contains the field names and formats for your table. The access file contains information about the actual name and location of the physical table and the primary keys for the table. Nearly all your work is done with the master file. The source code or procedures that store your report definitions are located under the Managed Reporting Domains portion of the tree. You expand that branch if you want to create a new report or modify an existing one.
254
7214ch08MRD.fm
Restriction: Report Assistant does not pick up all the reporting options set under the Reporting tab at this point in time. Developer Workbench allows you to show your Windows desktop explorer tree in the same window as your DB2 Web Query explorer tree. On the Explorer tab, you select the Show Desktop on Explorer tree option (Figure 9-8). Showing your Windows desktop tree within Developer Workbench has a definite benefits. The obvious benefit is the ability to stay within one working environment as a programmer. The less that you have to flip back and forth between your development mode and Windows, the better. An additional benefit is the ease with which you can copy items from your PC hard drive to the DB2 Web Query folder structure. You might want to move style sheets, company logos, pictures, and other PC files between the different file structures.
255
7214ch08MRD.fm
In Figure 9-9, we copy and paste a text file that contains SQL statements into our Other Files folder in the Common Domain. From here, the SQL can be accessed and run via the SQL Wizard in Developer Workbench or the SQL metadata creation option from the DB2 Web Query home page.
Figure 9-9 Copying files between the PC and DB2 Web Query
For more details about using Developer Workbench, refer to the online help text and the following chapters: Chapter 10, Online analytical processing on page 257 Chapter 11, HTML Composer on page 289 Chapter 12, Additional features of Developer Workbench on page 343
256
7214ch09OLAP.fm
10
Chapter 10.
257
7214ch09OLAP.fm
Measure
Pivot
258
7214ch09OLAP.fm
259
7214ch09OLAP.fm
4. At the bottom of the window that opens (Figure 10-2), click the Modeling View button. This is the easiest way to define hierarchies to DB2 Web Query. Note: In the left pane of this window are four tables paneOrders, Inventory, Plant, and Storeseven though you only opened the master file or metadata for the Orders table. This tells you that the Orders table was defined in the System i environment with foreign keys pointing to the Inventory, Plant, and Stores tables. When you do this, DB2 Web Query automatically pulls in the metadata for all four tables into one clustered table.
260
7214ch09OLAP.fm
5. If Dimension Builder is not visible, click Synonym Dimension Builder. Figure 10-3 shows the Dimension Builder pane. To the right of the Dimension Builder view (Figure 10-3), you see the tables and their relationship to the base table Orders.
261
7214ch09OLAP.fm
6. You can either view the tables as icons or view a column list for each table. Double-click the Inventory table icon to switch to column view (Figure 10-4). You can double-click the icon again to revert back to icon mode.
7. The columns in the Inventory table are structured so that, within product categories, you have product types; within product types, you have models; and within models, you have product names. We must describe this hierarchy to DB2 Web Query. Right-click Dimensions and select Add Hierarchy Levels (Figure 10-5 on page 263). Tip: A quicker way to achieve the same result is to click the hierarchy icon (circled in Figure 10-5) at the top of the Dimension Builder pane. There are two types of hierarchies one is based on levels and the other is based on parent child relationships. We use level hierarchies. The level hierarchy is the example that we have used so far; that is Country, Regions, State, and City are a level hierarchy. For more information about the different types of hierarchies, see the Developer Workbench help text.
262
7214ch09OLAP.fm
8. Right-click your new dimensions icon and select Rename. Change the name to Product Hierarchy. 9. Starting at the top of the hierarchy (Product Type), drag the column name to Product Hierarchy. Repeat this action for Product Category and Product Name (Figure 10-6).
263
7214ch09OLAP.fm
10.Define the Date Dimension shown in Figure 10-7: a. Right-click Dimensions and select Add Hierarchy Levels b. Right-click your new dimensions icon and select Rename. Change the name to Date Dimension. c. Drag the column name to the Date Dimension for ORDERDATE_YEAR, ORDERDATE_QUARTER, ORDERDATE_MONTH, and ORDERDATE_DAY.
11.Define the Plant Hierarchy as shown in Figure 10-8 on page 265: a. Right-click Dimensions and select Add Hierarchy Levels b. Right-click your new dimensions icon and select Rename. Change the name to Plant Hierarchy. c. Drag the column name to Plant Hierarchy for Plant Country, Plant Region, Plant State, and Plant City. 12.Define the Store Hierarchy as shown in Figure 10-8 on page 265. a. Right-click Dimensions and select Add Hierarchy Levels b. Right-click your new dimensions icon and select Rename. Change the name to Store Hierarchy. c. Drag the column name to Store Hierarchy for COUNTRY, REGION, STATE, CITY, and Store Name.
264
7214ch09OLAP.fm
13.If you do not see the additional date fields such as ORDERDATE_YEAR, decompose your date as explained in 12.1.1, Date Decomposition on page 348. 14.Save your definition. You have now completed the all the definitions that are required for OLAP-enabling your reports. Typically this is done once by the IT department. After this, any user with authority to create reports can choose to OLAP-enable their report. You can see how easy it is to define a hierarchy in your data and create the necessary metadata to OLAP-enable your reports for detailed analysis. Note: OLAP is an optional feature with DB2 Web Query. As you have just seen, Developer Workbench, also an optional feature, is a prerequisite for creating OLAP-enabled reports. Developer Workbench is the only interface for defining the hierarchies that are required by OLAP.
265
7214ch09OLAP.fm
b. Under the Enable OLAP, select Show Tabbed. Enable OLAP options: The Enable OLAP options control how users can interact with an OLAP report and access OLAP tools: Off: Provides an OLAP button to open the OLAP Control Panel. There is no top Selection pane. Columns only: Allows you to sort, hide, drag and drop columns. There is no top Selection pane and there is no access to the OLAP Control Panel. Columns with panel: Looks the same as Columns only, but when you click the square blue button over a dimension, you open the OLAP Control Panel. Show filters on top/bottom: Adds the OLAP Selections pane to the top (or bottom) of the report. This option is acceptable with a few dimensions and a few levels in each hiearchy. It tends to look messy when you have too many levels within different dimensions. Try it to see the difference between showing dimensions and hierarchies as filters or as tabs. Show Panel in Report: Is the same as the Columns with panel option but includes a small OLAP symbol in the lower left to more obviously allow the user to open the OLAP Control Panel. Show Tabbed: For OLAP reports that have multiple dimensions, this option groups the dimension elements under a tab labeled with the dimension name. This is the option we use.
266
7214ch09OLAP.fm
c. Under the Automatic drill down, select Dimensions and Measures (Figure 10-10). This gives you the maximum drill-down capabilities. When creating your own reports, you can choose to drill down on the dimensions only and not the measures. Automatic drill down options: None: The user cannot drill down to a lower level in the hierarchy within the report itself. Dimensions: The user can drill down on a dimension to proceed to the next level down in the hierarchy. Dimensions and Measures: In addition to drilling down on the dimensions, the user can drill down on the measures within the report. This allows the users to drill down to the lowest level of all displayed hierarchies.
4. Save your report as OL1_Revenue. You have now OLAP enabled your report. To summarize, we took a basic report and selected an output option to enable OLAP. This simple selection automatically gives you an enormous amount of analysis capabilities as you will see in the next section.
267
7214ch09OLAP.fm
268
7214ch09OLAP.fm
To use the arrows and buttons to drill down for more details, follow these steps: 1. Because Revenue was previously unsorted, neither half of the arrow is dark and the prompt reads sort Revenue. Click the sort arrow to the left of Revenue (Figure 10-12).
2. Now that you have sorted by Revenue, hover over the column again. Notice that the bottom half of the arrow is dark. Click this arrow, and you sort the column in descending sequence (Figure 10-13).
Here is another way to sort Revenue. Right-click the column heading Revenue and select Visualize (Figure 10-14).
269
7214ch09OLAP.fm
As we saw in Active Reports, selecting Visualize displays bars to help you quickly note trends or to easily compare two columns. See Figure 10-15. Note: Positive numbers are visualized with blue bars, while negative numbers are visualized with red bars.
3. Click the Store Hierarchy tab. The Store Hierarchy tab has a drop-down tab for each element in the hiearchy, proceeding from the top of the hierarchy to the bottom. By default, each of the drop-down lists contains all the unique values for that column. For example, initially every region in the world is available under the Region tab. 4. To start to filter and drill down on your data, click the Country drop-down list and select United States (Figure 10-16). Tip: You can select multiple values using the Ctrl or Shift keys.
270
7214ch09OLAP.fm
5. Click the Region drop-down list. Notice that the only regions displayed are for the United States. Select the North region (Figure 10-17).
6. The filters in the Selection pane do not take effect until you click Run. Review your current totals and click Run (Figure 10-18). Your report now shows the revenue and number of orders for the North region in the United States.
7. Notice that immediately to the right of COUNTRY and REGION is an equal sign (=). Click the = button. Each time you fill in a value, you filter your data by creating a WHERE clause. Instead of selecting COUNTRY equal to United States, we can select all countries except the United States by changing the button to not equal. Click the button multiple times to cycle through your choices. 8. Click the Reset button to reset the report back to its initial state. You can also use the back arrow on our browser to go back one page at a time. 9. Click the Product Hierarchy tab (Figure 10-19).
271
7214ch09OLAP.fm
10.Drill down within the report, not by using the hierarchy tabs. Click Audio. Notice that not only did you drill down from Product Type to the next level of Product Categories within Audio, DB2 Web Query also filled in the Selection pane tabs for you (Figure 10-20).
11.Drill down on Amplifiers/PreAmps/Tuner to see the products that compose the Amplifier category. Again notice that the drop-down lists have been filled in for you. You can go back and forth this way between the body of the report and the tabs at the top. See Figure 10-21.
12.Continuing to analyze our data, drill down to see only the Amplifier sales that occurred in January 2007. Click the Date Dimension tab.
272
7214ch09OLAP.fm
13.For Year, select 2007. You can then select the quarter or go straight to month and select 01 (Figure 10-22).
14.Click Run. Figure 10-23 shows the results of running this report.
15.Click Reset to start back at the beginning with an unfiltered report. 16.Try drilling down on a measure or total field. Drill down on the Revenue column for Office products (Figure 10-24).
273
7214ch09OLAP.fm
After drilling on the revenue for Office products, the Office product type is expanded to its subcategories and products. The Revenue and Order count are now grouped at a much more detailed level (Figure 10-25).
17.Reset your report now so that all drill downs are removed. 18.The next request from our users is to generate a report that shows revenue by product type by year. Drag ORDERDATE_YEAR from the Selections pane into the area of the report where you want it, that is across the top. The plus symbol (+) shows that you are in a valid area to drop the field (Figure 10-26).
274
7214ch09OLAP.fm
20.We now have a pivot table. If you decide that you prefer to see the years down the left column, drag the column name ORDERDATE_YEAR to the left of Product Type (Figure 10-28). Again, the + sign directs you to where you can validly drag the field.
21.Click the Save button and select Save Report to save the new pivot report (Figure 10-29). You can also see what happens when you save to the Excel and PDF output formats.
275
7214ch09OLAP.fm
22.In the window that opens (Figure 10-30), specify the folder for your report. If you want to save this report without any OLAP capabilities, select the Save without OLAP option. Since you used the OLAP functionality to design a new report for a user, we do not select this option. Click OK.
23.Our users have changed their minds and decided that they do not want a pivot table. Instead they want to see the year and product type to the left of Revenue. Drag ORDERDATE_YEAR from the Sort across portion of the report to the Sort by section (Figure 10-31).
In addition to dragging from the Selection pane area, there are other methods to display additional columns in the report as explained in the following steps. 276
7214ch09OLAP.fm
24.Right-click ORDERDATE_YEAR and select Unhide (Figure 10-32). You see a list of columns that were either part of the initial report or are in one of the hierarchies. These are the columns that are available for display.
25.Try the same process for the Revenue field. Right-click Revenue and select Unhide. Notice that you see that only numeric fields are available. 26.Click the down arrow for the Measures tab (Figure 10-33): a. You see a list of all the measures that are available to you in this report. Notice that Order Count has no check mark. This is because we hid it. To display Order Count, select it again. b. Select Revenue. Notice that you can cycle through the different options for displaying, visualizing, and hiding the measure. We visualize Revenue, display Order Count, and run the report again.
277
7214ch09OLAP.fm
27.Click the down arrow for the Graph tab (Figure 10-34): a. Select Revenue. b. Click the icon to the right of Revenue to cycle through the graph types until you come to pie charts. c. Click Run. d. Make the pie chart window larger by dragging down the horizontal break line between the graph and the report.
Break line
278
7214ch09OLAP.fm
Notice that there is one pie chart for each year that was your major sort by axis. See Figure 10-35. Tip: To control the scope of the graph, use the drop-down lists in the Selection pane. For example, if you only want a graph for 2007 revenue, you can select the year 2007 from the ORDERDATE_YEAR drop-down list. If the measures in the original report were drill down capable, then the graph can be drilled into.
Drilling down on the graph generates the same report as though you drilled down on the Revenue field in the original report. 28.Experiment with the various options for drilling down and filtering your report. When you are finished, click Reset to restore the report to its original values. Tip: If our report has multiple measures that can be graphed, you can graph them on the same chart. You can select each measure for graphing and choose a different graph type. For example, if our report contains profit, you can superimpose a line graph on a bar graph with the line representing the profit and the bar representing revenue.
279
7214ch09OLAP.fm
Control Panel. The OLAP Control Panel can do everything that can be done from the OLAP report and the Selections pane and more. The following unique OLAP functions, among others, can only be performed from the OLAP Control Panel: Selection of a Top or Bottom n rows report Ability to group numeric data by percentile (or decile, quartile, and so on) Advanced row selection criteria Stacking of multiple measures vertically in a report as opposed to horizontally
2. We want to see our data in columns by quarter: a. Expand Date Dimension. b. Click the Drill Across box. When selected, it is surrounded by a blue rectangle. c. Click the ORDERDATE_QUARTER field. It should appear in the Drill Across box. See Figure 10-37. Tip: If Quarter appears in the Drill Down box by accident, simply highlight it and use the Pivot button to pivot Quarter from rows to columns. d. Click Run.
280
7214ch09OLAP.fm
281
7214ch09OLAP.fm
3. Often when you have multiple measures and sort across columns, the report can become wide and unwieldy. Open the OLAP Control Panel and select Stack Measures (Figure 10-39). Click Run.
There is a potential problem with this report as it stands right now. If the Orders table contains data for multiple years, we now have the sales for every Q1 added up together (Figure 10-40). Although this is technically accurate, it probably is not what the user wants to see.
4. From the OLAP Control Panel, expand Date Dimension and select Values for ORDERDATE_YEAR (Figure 10-41). Note: For most dimensions, when you click Values, you see the list of values from your table. The date components are prefilled in with general dates. If you expand ORDERDATE_MONTH, you see that the actual month names, that is June, are filled in for ease of use for the user. 5. In the window that opens (lower half of Figure 10-41), select the Range box. This is not appropriate for our data that contains only records from 2006 and 2007, but it is interesting to see the capability. Deselect Range. For Year, select 2007 and click Add.
282
7214ch09OLAP.fm
6. At this point, you can click Run. However, for demonstration purposes, click OK to see the full Selection Criteria pane. 7. In the Selection Criteria pane (Figure 10-42), notice that Q1 is prefilled in for ORDERDATE QUARTER, because we drilled down and selected Q1 prior to opening the control panel. If you use the scroll bar on the right, you see all the various dimensions and their individual elements or columns that were available through the tabs in the Selection pane. You can continue to filter your data here. If you want to filter on Product Type, you have two choices. You can click the down arrow next to Product Type or you can click the Select button. In both cases, you see a list of all the unique values for Product Type. Using the Select button takes you to a second window. This is easier to use when you are selecting multiple values. Again, when filtering, you can modify the operand for each filtered column. Here, we do not filter on Product Type. Click Run.
283
7214ch09OLAP.fm
Figure 10-43 shows the output of running the report. Note: Best practice states that you should always display any filters in effect on a report. DB2 Web Query has the capability from the OLAP Control Panel to document your filters at the beginning or end of your report.
284
7214ch09OLAP.fm
8. If you are still on the Selection pane in the OLAP Control Panel, click OK to return to the initial layout. Notice that you can click Selection Criteria in the bottom right of the Control Panel to return directly to the Selection Criteria layout. 9. In the Measures pane (Figure 10-44), select the Revenue check box. Then click the Revenue name.
10.In the Revenue pane (Figure 10-45 on page 286), if we want to see a Top 3 analysis report: a. b. c. d. e. Select the Sort check box. Select High to Low. Select the Rank (1, 2, 3 ...) check box. For Highest, select 3. For Measure Calculations, keep the default of None. Notice that if you expand Measure Calculations, you can ask to see the Revenue column in multiple ways. For example, you can ask to see each Revenue as a percentage of the product type revenue in that quarter (Row Percent). You can ask to see the average revenue per order and much more. Tip: If you want to see a report that shows your bottom Products by revenue, you sort from low to high and then rank and select your top three.
285
7214ch09OLAP.fm
Figure 10-46 Starting report showing sales people and their attainment
286
7214ch09OLAP.fm
In the next pane (left in Figure 10-47), we choose a high to low sort sequence and then select the Tiles tab. On the Tiles tab (right in Figure 10-47), we select the options to tile the report in groups of 10 so that we can see our revenue numbers evenly split into ten groups. We want the new column with the group number to be called Decile. If we only want to see the top 10%, we restrict the report to the first tile only. If we want to see the top 5% of the sales people, we can ask the system to split the sales people into 20 groups and then we choose the top group. We can also split the sales people into 100 groups with 1% in each group. To get the top 5%, we choose groups 1 - 5.
287
7214ch09OLAP.fm
288
7214chHTML.fm
11
Chapter 11.
HTML Composer
HTML Composer is a component of IBM Developer Workbench. Prior to starting this set of tutorials, you must have completed Chapter 9, Developer Workbench on page 249. HTML Composer is specifically designed, as the name suggests, to design HTML pages. HTML Composer does not create reports or graphs, but rather references existing ones. You can create compound reports with background style sheets and add company logos and other standard HTML components. The design of the HTML page can be set to match your companys intranet standards. Both HTML Composer and Power Painter can create compound reports. Power Painter is architected for PDF output and has additional controls specific to large PDF reports. It can also create other types of output such as HTML pages. HTML Composer is architected for HTML pages; it can only create HTML pages. It cannot create a PDF report. The products both have different user interfaces. You have already tried Power Painter. In this tutorial, you try HTML Composer. Choose the option that fits your companys needs the best. In this tutorial, we design two different HTML pages. The first is a compound report with a single input parameter. This style of report can be used as the basis for key performance indicator (KPI) dashboards where the user might request the KPIs for a specific country, product type, and so on. This type of report is often designed by IT and deployed to senior management and executives within a company. The second report that we design is a single, highly parameterized active report. Again, this report is typically developed by IT but, in this case, is often deployed to business analysts or disconnected users who want to highly segment the data they are analyzing. This tutorial assumes that you have completed the Active Reports tutorial (Chapter 8, Active Reports on page 229) and understand those concepts. Here we take an existing active report and initiate it from an HTML page that contains a large number of input parameters in a user friendly manner.
289
7214chHTML.fm
290
7214chHTML.fm
1. Open Developer Workbench. You see WebFOCUS Environments under Developer Studio Desktop. You may or may not see Windows Desktop. This is an optional setting described in Chapter 9, Developer Workbench on page 249. 2. Expand WebFOCUS Environments your environment Managed Reporting Domains Common Domain Reports Tutorials. 3. In your Tutorials folder, navigate to the graph GA3_Trend, right-click, and select Copy (Figure 11-2).
4. Keeping your cursor in the same pane (the list of your reports), right-click and select Paste. You now have a report titled GA3_Trend1 in the Tutorials folder. Restriction: When accessed by Developer Studio, Report Assistant does not currently support the Save As capability. This is a known requirement. As a workaround, we use Copy and Paste to place the report into the same directory. 5. Right-click your new report GA3_Trend1 and select Rename. Give the report the name HTML1_KPI_LINE. Tip: Even though you rename the report in the window to HTML1_KPI_LINE, if you look in the integrated file system or look at the properties of the new report, you see that the object name is still ga3_trend1.fex. You have changed only the display title of the report, not the physical name on disk.
291
7214chHTML.fm
6. Right-click HTML1_KPI_LINE and select Edit in Developer Studio Tool (Figure 11-3).
7. DB2 Web Query knows which tool was used to create your report. Selecting the default option opens the report in either Report Assistant or Graph Assistant, whichever is appropriate. Power Painter is not directly supported in Developer Workbench. In this example, Graph Assistant opens. 8. In Graph Assistant, choose the Selection criteria tab. 9. On the Selection criteria tab (Figure 11-4): a. b. c. d. Delete all existing selection criteria. Drag PRODUCTTYPE to the Selection pane. Click Select values. In the EQ Values window, select Parameter and then click the Auto Prompt button. Accept all the defaults for PRODUCTTYPE prompting. Click OK. e. Back on the EQ Values window, click OK.
292
7214chHTML.fm
Notice in the Selection pane (Figure 11-5) that the Select values link has changed.
10.Remove the months from the X axis labels to free more room in the small output frame for the graph itself. a. Click the Properties tab and the X axis subtab (Figure 11-6). b. On the X axis subtab, clear the Show axis labels check box.
293
7214chHTML.fm
294
7214chHTML.fm
c. Click the Options subtab (Figure 11-7). d. From experience, we know that the frame for our graph is about 350 pixels wide by 250 pixels high. This can be an iterative process. You might need to design your HTML page, see how much room you have for your graph, and then return to the output options for the graph to ensure that it will fit in the designated space. Set the output size to 350 pixels wide (Horizontal) by 250 pixels high (Vertical). e. Save your graph.
295
7214chHTML.fm
11.We repeat the previous steps for the existing bar chart GA1_Bar. If you need more detailed assistance, refer to the previous steps and figures. a. Copy and paste the GA1_Bar and rename it HTML1_KPI_Bar. b. Add a PRODUCTTYPE parameter, accepting the auto prompting defaults. Your report should have only one parameter. c. Set the output size to 350 pixels wide by 250 pixels high. d. Click the Field selection tab (Figure 11-8). e. Click Show - Field options. To save space for our graph, for the X axis field label field, delete Country. f. Save your graph.
296
7214chHTML.fm
3. Right-click the Tutorials folder and select New HTML File (Figure 11-9). Tip: To create a text report or graph, select New Procedure. You then see a window that allows you to choose between using Report Assistant, Graph Assistant, and the SQL Wizard to create your new report.
297
7214chHTML.fm
In the next subsections, we explain how to include a line chart, a bar graph, and the gross profit report. Figure 11-10 shows the final layout design of our compound report. The sections that follow refer to this figure unless noted otherwise.
3
Figure 11-10 Design layout for HTML report
6. Draw a box similar to the box in the upper left corner labeled 1 in Figure 11-10. Look at the properties box in the right pane. Your box should be 250 pixels high and 350 pixels wide. This is the size we designed our graph for.
298
7214chHTML.fm
7. Right-click box 1 and select Reference existing procedure (Figure 11-12). This not only shows how the graph will look in this frame, but it also references any parameters that are used by the graph.
8. Open your HTML1_KPI_Line file in the Tutorials folder. Notice that the actual file name is displayed (Figure 11-13).
299
7214chHTML.fm
9. In the New Parameters window (Figure 11-14), the system presents a list of the parameters used in HTML1_KPI_Line. a. For Control Type, accept the default of Drop-down list. b. For Parameter grouping options, select Do not create a form. New form element: If you accept the default New form element, the system creates a panel that contains your parameter label, the drop-down box, a run button and a refresh button, like the following example. We said no to this because we want to be able to move each of these elements separately on our page. c. Click OK.
10.Delete the label PRODUCTTYPE. We reference Product Type in our overall report heading. 11.Move the drop-down list and the Run button as shown in Figure 11-10 on page 298. Your Run button looks slightly different at this stage.
300
7214chHTML.fm
12.Select the line graph. In the Properties pane on the right, change Name to LineGraph (Figure 11-15).
301
7214chHTML.fm
13.Click the drop-down control box in the report (circled in Figure 11-16). Click the Parameters tab in the lower right corner. Select the Add ALL option and specify to display All Products.
302
7214chHTML.fm
20.Again select frame 2 and then frame 1 and click the Align top icon ( 21.In the Properties pane on the right, change the name to BarGraph.
).
23.Draw a box similar to the box in the upper right corner in Figure 11-10 on page 298 labeled 3. 24.Right-click the frame and point to the RA4_Advanced report. 25.In the Properties pane on the right, set Size and Scrolling to No. This automatically adjusts the size of your frame so that your report fits in it and you do not have to scroll within the frame. Change the Name to GrossPftReport.
b. Draw a box in the pane where you want the report title to be. c. Enter the text Product Type Indicators. 30.Click your text box so that it is surrounded by a straight line frame and not slashes.
Chapter 11. HTML Composer
303
7214chHTML.fm
31.In the Properties pane on the right, click the ellipsis button (...) next to Styling: Font. 32.Define the styling for your heading by selecting the following options: arial, 18pt, bold, underlined, and blue.
37.Save your report and then run it by clicking the Run button (circled in Figure 11-20).
304
7214chHTML.fm
Tip: You can return to the DB2 Web Query home page and run this dashboard. The easiest method is for a developer to stay within Developer Workbench and test from there. Do not forget that the page should be designed small enough to be viewed within the context of the DB2 Web Query home page. Your dashboard or KPI should look like the example in Figure 11-21.
305
7214chHTML.fm
Tip: If your active report is in the accordion format, open the report, go to Report options, choose Active Report Styling and select Tabular for Report view. Save your report.
To create the report: 1. Open Developer Workbench. 2. Expand WebFOCUS Environments your environment Managed Reporting Domains Common Domain Reports Tutorials. 3. In your Tutorials folder, navigate to the AR1_GrossPft report, right-click, and select Copy. 4. Keeping your cursor in the same pane (the list of your reports), right-click and select Paste. You now have a report titled AR1_GrossPft in the Tutorials folder. 5. Right-click AR1_GrossPft and select Rename. Give the report the name HTML2_Parm_AR.
306
7214chHTML.fm
6. Open the new report. In the right pane, right-click HTML2_Parm_AR and select Edit in Developer Studio Tool (Figure 11-23).
7. Click the Selection criteria tab and enter, in sequence, the parameters shown in Table 11-1. Based on this table, all the conditions are WHERE conditions. The table shows the field name to drag to the Selection criteria pane and the condition to use. For all parameters, click Select values. In all fields, but ORDERDATE, select the Autoprompt wizard. In the Autoprompt pane, choose Select multiple values. Then click OK.
Table 11-1 Parameters for WHERE conditions Field name WHERE PRODUCTTYPE Condition EQUAL to Select values Select parameter Autoprompt Select multiple values Select parameter Autoprompt Select multiple values Select parameter Autoprompt Select multiple values Select parameter Autoprompt Select multiple values Select parameter Autoprompt Select multiple values Select parameter Autoprompt Select multiple values Select parameter Autoprompt Select multiple values Select parameter Enter field name From_Date under Parameter (do not autoprompt) See Figure 11-24
WHERE
PRODUCTCATEGORY
EQUAL to
WHERE
SALESREP
EQUAL to
WHERE
COUNTRY
EQUAL to
WHERE
REGION
EQUAL to
WHERE
STATE
EQUAL to
WHERE
PLANTNAME
EQUAL to
WHERE
ORDERDATE
307
7214chHTML.fm
Select values Select parameter Enter field name To_Date under Parameter (do not autoprompt)
8. For the date fields, instead of using the Autoprompt wizard, enter a parameter name that you want to use (Figure 11-24). We use From_Date for the first date parameter and To_Date for the second date parameter.
The finished Selection criteria pane should look like the example in Figure 11-25.
308
7214chHTML.fm
11.In the window that opens (Figure 11-27), enter a report name of HTML2_Parm and click Create.
12.In this example, we create an HTML page that contains the various parameters and a Run button. When the Run button is clicked, a new window opens that contains the active report. We must import the report onto the HTML page so that DB2 Web Query automatically brings in all the parameters that are defined in the report, saving us from adding them manually. We remove the report frame itself after we import all the parameters. Click the report icon (circled in Figure 11-28) and draw a small box in the upper left corner of the pane.
309
7214chHTML.fm
13.Right-click the report (the box that you just drew) and select Reference existing procedure (Figure 11-29).
14.Select the HTML2_Parm_AR report that you just created. 15.You are presented with a list of parameters that are referenced by this report (Figure 11-30). a. b. c. d. e. For SALESREP, change the control type to Double list control. For COUNTRY, change the control type to Radio button. For PLANTNAME, change the control type to Check box. For both dates, change the control type to Calendar. Under Parameter grouping options, select Do not create a form.
310
7214chHTML.fm
The system lays out all the chosen parameters in a column on the HTML page similar to the layout in Figure 11-31.
311
7214chHTML.fm
16.Making sure that you keep the headings and controls together, drag the parameters into a layout similar to Figure 11-32. You must scroll to see the entire page of parameters. See the following steps to size the Country control box. Make sure that you leave enough room at the top of the report for a report heading. Some of the boxes, such as SALESREP, require resizing. Keep any frames that are within a panel, in the panel when they are moved or resized.
Note: This exercise is designed to introduce you to many of the controls and capabilities of HTML Composer. Is it not intended to teach window design. Do not design a window that has this many different controls and looks like this in production applications. 17.We want to change Country from one column wide to two columns wide (Figure 11-33): a. Highlight the Country control box. b. From the Properties pane, select columns and type 2. 312
Getting Started with DB2 Web Query for i
7214chHTML.fm
Parameter controls
In this section, we illustrate how to define the sequence in which the cursor moves from cursor to cursor also known as parameter controls: 18.Highlight the Producttype control box. 19.In the Properties pane on the right, select Tab index and enter 1. Tab index controls the sequence in which the cursor moves from field to field.
313
7214chHTML.fm
20.Click the Parameters tab at the bottom of the right pane. This is where you can override options such as your type of control box or the text to go with the ALL option. Select the add ALL option for every parameter except the dates. 21.Highlight the Productcategory control box. 22.Click the Properties tab (Figure 11-34), and under Tab index, enter the value 2.
314
7214chHTML.fm
25.Highlight the Salesrep control. In the Properties pane, for Tab index, type 3. 26.Highlight the Country control. In the Properties pane, for Tab index, type 4. 27.Highlight the Region control. In the Properties pane, for Tab index, type 5. 28.Highlight the State control. In the Properties pane, for Tab index, type 6. 29.We want the Country parameter to control or filter the Region parameter, and we want the Region parameter to filter the State list box. To chain Country to Region to State: a. Select the Country control box. b. Hold down the Shift key, and select the Region control box. Still holding down the Shift key, select the State control box. c. Click the Add chain button shown in Figure 11-35. 30.Highlight the Plantname control. In the Properties pane, for Tab index, type 7.
315
7214chHTML.fm
36.Right-click the Run report1 control box and select Hyperlink Properties.
316
7214chHTML.fm
37.In the Hyperlink Properties window (Figure 11-37), complete these steps: a. Change Display Text to RUN. b. Change Target Type to Window. This runs the report in a new window instead of in the frame drawn on the current HTML page.
38.Delete the original frame you drew when importing the report. It is located below all the parameters. 39.Select the RUN control box. In the Properties pane, for Tab index, type 10. 40.Resize the Run button by dragging the frame. 41.Add a heading to the report: a. Click the text icon on the toolbar and draw a box to contain your heading (Figure 11-38). Note: In addition to text and reports, you can import images to your page using the icon to the left of the text icon. You can use define cascading style sheets to tailor the look of your page.
42.Enter a title of Gross Profit Active Report. 43.Click your text box so that it is surrounded by a straight line frame and not slashes. 44.In the Properties pane on the right, select the ... button next to Styling: Font.
317
7214chHTML.fm
45.In the Font window (Figure 11-39), select the styling for your heading: a. b. c. d. e. For Font, select Arial. For Font Style, select Bold. For Size, select 18pt. For Effects, select Underline. Click OK.
46.Click the background area of the HTML layout. 47.In the Properties pane, click the ... button next to Background color and select a pale color (Figure 11-40).
318
7214chHTML.fm
48.When we modified all the parameter control boxes, we changed the tab index in the Properties pane. This controls the sequence that the users tab through the fields in the window. We still have a problem in that some of the other elements on the page have a tab index that might conflict with our sequence numbers. Starting with the title, highlight the frame, and find the tab index number. If it is less than or equal to 10, change it to an arbitrary number above 20. The Run button had a tab index of 10 and we want it to be last in our normal sequence. Do not forget to check the arrow elements in Salesrep. Tip: If you hover over the icon second from the left that looks like a hand and multiple small boxes, you should see the text Tab Order. Selecting this shows the sequence of your tabs for the user. Make sure that you do not have duplicates and the order is left to right, top to bottom for INPUT capable fields. 49.Save and run the report.
319
7214chHTML.fm
50.For our first test, select ALL for Salesrep and 2006/01/01 to 2006/12/31 for the dates (Figure 11-41). Tip: Having chosen the double list control for Salesrep means that you always have to select at least one item for SALESREP. This can be ALL, but there must be a value in the output list.
320
7214chHTML.fm
51.Click RUN. Figure 11-42 shows the output of running this report.
At this point, you can try and run the report taking advantage of the parameter chaining. Selecting a product type changes the product categories list box. Similarly choosing a region changes the state displayed. Then go back to your parameter design page and start tailoring the page to look like a more practical report that you might show to a user.
321
7214chHTML.fm
The report opens in Report Assistant development tool. 2. Go to the Report options tab and change the Generate report as setting from AHTMLActive Report to PDF - Portable Document Format as shown in Figure 11-44.
3. Create a new copy of the report by clicking Save As and name the report HTML_PARM_PDF as shown in Figure 11-45 on page 323.
322
7214chHTML.fm
4. Return to the HTML2_PARM file already open in DB2 Web Query Developer Workbench 5. As shown in Figure 11-46, click the Push button icon to create a new button on the form.
6. Use the crosshairs to draw the new button on the palette. The new button will be simply labeled Button. This is demonstrated in Figure 11-47 on page 324.
323
7214chHTML.fm
7. To define the action that occurs when user presses it, Right-mouse click on the new button and select Create hyperlink as shown in. Figure 11-48
8. From the Hyperlink Properties dialog window, change the Display Text to PDF and click on the new Action icon as demonstrated in Figure 11-49 on page 325.
324
7214chHTML.fm
9. Select External procedure as the Action, click on the ellipsis icon under Source, and (from the list of presented procedures) select HTML2_PARM_PDF as the report to run. An example is displayed in Figure 11-50.
10.Click the Open button to accept this report as the source and return to the Hyperlink Properties dialog. 11.To display the PDF report in a new browser window, select Window for the Target Type setting and New Window for the Target/Template Name. When finished, it should look like the example shown in Figure 11-51 on page 326.
325
7214chHTML.fm
12.Click OK to accept the changes. 13.Click the Save icon to save your changes 14.Run the report and click the new PDF button to test. You should see the report displayed in PDF format as shown in Figure 11-52.
15.For additional output formats such as Excel spreadsheet, repeat above steps and substitute the new output format for PDF. 16.Close the window.
326
7214chHTML.fm
2. Go to the Selection criteria tab, and add PRODUCTNUMBER as a screening condition. Define it as a multi-value prompt control parameter that is based on PRODUCTNUMBER in CEN_ORDERS. An example is provided in Figure 11-54 on page 328.
327
7214chHTML.fm
3. Save the report as ra6_parm 4. Run the report with No Selection. It should look like the example shown in Figure 11-55 on page 329.
328
7214chHTML.fm
5. Return to the Developer Workbench tool and create a new HTML file in your Tutorials folder as shown in Figure 11-56. Name the new html file html3_parm.
6. In the HTML Composer tool select the report icon to add a new report to the layout (Figure 11-57 on page 330).
329
7214chHTML.fm
7. Using the crosshairs, draw/outline the location of the report on the canvas. 8. Right-click on the report outline and select Reference Existing Procedure. 9. From the list of reports displayed, select ra6_parm. The New Parameters dialog window is presented. 10.From this window, select Do not create a form under Parameter grouping options and click OK.
11.Move the elements around on the canvas as shown in the example in Figure 11-59 on page 331.
330
7214chHTML.fm
12.Select the parameter listbox element and on the Properties dialog, select the Parameters tab on the bottom (see Figure 11-60).
331
7214chHTML.fm
The properties for the PRODUCTNUMBER parameter are displayed as shown in Figure 11-61.
From the list of field names displayed, select/highlight the PRODUCTNAME field and drag it into the area under Display field. An example is shown in Figure 11-62 on page 333.
332
7214chHTML.fm
13.Click the Run icon to test the report Notice that the drop list is populated with Product Names rather than the Product Numbers. 14.Select multiple product names in the list (by selecting them and holding down the Ctrl key on your keyboard) and click Run Report1 button. Your results should look similar to the example provided in Figure 11-63 on page 334.
333
7214chHTML.fm
Figure 11-63 Example of report that displays one column as parameter but passes another
The drop down list on the HTML page is populated with product names, yet the value of the correlating ProductNumber column is passed to the underlying report. Because ProductNumber is the parameter that report is expecting, the report is able to find and display the appropriate rows 15.Close the browser window 16.Back in the HTML Composer session, save the report 17.Close the HTML Composer session
334
7214chHTML.fm
3. Drag LINETOTAL into the Sum pane and specify column formatting of commas and floating currency. An example is shown in Figure 11-64.
Figure 11-64 Using a procedure to sort the parameter list - base report
4. Set up the a prompt control parameter over ORDERDATE column by doing the following a. Drag ORDERDATE field from list of available fields into the Screening conditions pane. b. Click <Select Values> link c. Select Parameter setting and click the AutoPrompt icon d. Select ORDERDATE from list of fields These steps are shown in Figure 11-65 on page 336.
335
7214chHTML.fm
5. Click OK twice. 6. Save your report as Revenue for Selected Order Date 7. Run your report. Use the prompt control. Notice that OrderDates are listed in the drop down list and are sorted in ascending order as shown in Figure 11-66.
The behavior that you really want for this drop down list is to present the OrderDates in descending order. You would also like to filter this list so that only order dates for the year 2007 are presented and can be selected by the user.
336
7214chHTML.fm
To obtain this behavior, you must create another report (procedure) and use it to handle the parameter sorting and filtering. Important: The procedure must return a name and value pair for each parameter value that will populate the list. The first value is the submission value which is passed to the form control when you click the Submit button. The second value is the display value which is what you will see in the control. These two values can be the same or different. The procedure must return the two data values in XML output format. 8. From the Tutorials folder, launch Report Assistant to create another report 9. Select the CEN_ORDERS synonym 10.From the list of available fields, specify ORDERDATE as the Sort by field. Do this again so that there are two ORDERDATE columns in the Sort by pane. Change the Sorting of the first ORDERDATE column to Descending order as shown in Figure 11-67.
Next filter the list so that only entries for 2007 appear. 11.Go to the Selection criteria tab and select the ORDERDATE_YEAR column as a screening condition. Click the <Select Value> link and specify the value 2007 as a Constant. This is demonstrated in Figure 11-68 on page 338.
337
7214chHTML.fm
Figure 11-68 Filter the drop down list for year 2007
The last step is to specify XML as the output format. 12.Select the Report Options tab and select Show unstyled formats from the drop down list at the top. Taking this action will cause the list of report output formats to change. From this re-populated list, find and select XML - eXtensible Markup Language. This is demonstrated in Figure 11-69.
338
7214chHTML.fm
13.Save this report as Parm Sort Procedure The final piece of the puzzle is building the HTML layout. This component will use the procedure to sort and filter the drop down list and will reference the base report to execute the query and display the results. From DB2 Web Query Developer Workbench, create a new HTML file in the Tutorials folder as shown in Figure 11-70.
14.In the HTML Layout canvas, insert a report and reference the existing procedure Revenue for Selected Order Date 15.On the New Parameters dialog, select Do not create a form and click OK as shown in Figure 11-71.
16.Select the ORDERDATE parameter element displayed on the canvas and select the Parameters tab at the bottom right of the window as shown in Figure 11-72 on page 340.
339
7214chHTML.fm
The Parameters pane appears on the right. 17.Under Control Values, select Procedures and click the ellipsis icon to present a dialog from which you can select the procedure. From this dialog, select the procedure named parm sort procedure and click the Open button.
340
7214chHTML.fm
With this setting, the list of parameter values displayed in the drop down list will be controlled by the parm sort procedure report. This includes the sorting and filtering defined in this report. 18.Save the HTML 19.Close the HTML Composer session 20.Return to the web browser and run the report Notice that the list is sorted in descending order by order date and only dates for the year 2007 appear on the list.
341
7214chHTML.fm
342
7214chMRDextra.fm
12
Chapter 12.
SQL Wizard We provide a short tutorial for each feature so you can see how to use it. There are many more capabilities within each of the features than is described in this chapter. See the online help text in Developer Workbench for more details.
343
7214chMRDextra.fm
344
7214chMRDextra.fm
The window changes to show the different attributes of the table that are stored in the metadata (Figure 12-2). Look at the file attributes that are available. Some of the attributes, such as DBSPACE, are not applicable to DB2 for i5/OS. Important: The Synonym Editor does not allow you to make any changes that render the Master file unusable.
345
7214chMRDextra.fm
346
7214chMRDextra.fm
3. Highlight LINETOTAL to see the metadata attributes of the field displayed (Figure 12-3). In this example, we want LINETOTAL to display in reports with commas and a floating dollar sign. When we make this change, the report will use these settings by default. Tip: The display in Figure 12-3 also allows users to specify a description and title for a column. Users can set up multiple titles for a column based on the language of the user. Selecting the ellipsis (three dots) next to these attributes allows you to specify which title you want displayed based on the language chosen.
347
7214chMRDextra.fm
Another interesting attribute on this display is the USAGE attribute (Figure 12-4). To demonstrate this, highlight and select ORDERDATE in the Column pane.
In the Attribute pane, ACTUAL refers to how a column is stored in DB2 for i5/OS. USAGE refers to how the user sees and works with a column. USAGE allows us to override or change the length and attributes of a column from how it is stored and displayed by default. For many System i customers, USAGE becomes important for date fields. If you have a field defined to DB2 as an integer 8 field that happens to contain the value 20070901, there is no automatic way for DB2 Web Query to know that this is a date field. The ACTUAL for this column displays as integer 8. Using the powerful USAGE attribute allows you to specify a USAGE of type Date with a format of YYMD. This enables many of the date and time functions, calculations, and formatting options that are available in DB2 Web Query to work with your integer field.
348
7214chMRDextra.fm
4. Right-click the ORDERDATE field and select Decompose Date (Figure 12-5).
5. In the Decompose Date Column window (Figure 12-6), select all four subcomponents of ORDERDATE to be created for you. Click OK.
349
7214chMRDextra.fm
In the results shown in Figure 12-7, notice that the system has generated four new fields for the users to access.
Note: You can manually create these fields by right-clicking a column or the table and specifying Add Virtual column. This allows you to create any new column that you normally create during the report definition stage. Creating it here means that it is available to all reports. Creating a column, such as PROFIT, in the metadata means that the definition of the column is standard across all your reports.
350
7214chMRDextra.fm
Having made these changes, your users can now do basic date formatting. In a report, the user can choose to format the field as a YYMTRD field. This prints the date in the report as 2007, SEPTEMBER 14. The user can also create separate year, month, and day fields from this date. To use various date functions and date arithmetic, you create a true DATE field. That is, you create a define field with your new date field name; the format is similar to YYMD. The expression is your original numeric or alpha date field that you formatted as A8YYMD. As shown in Figure 12-9, you can now use the PROPERDATE field to do date arithmetic or use date functions such as adding seven business days to a date or finding the end of the next quarter. These functions are described in DB2 Web Query date built-in functions on page 555.
If you use two-digit years, you can use the DEFCENT and YRTHRESH column attributes to define your century. If the year is greater than or equal to the threshold (YRTHRESH), then the two additional significant digits in the year become equal to the default century value (DEFCENT). If your two-digit year is less than YRTHRESH, then the additional two digits equal DEFCENT plus one. Assume YRTHRESH equals 40 and DEFCENT equals 19. Any year from 40 to 99 is translated to 1940 - 1999. Any year from 00 to 39 is assumed to be 2000 - 2039. If you use a century field, you can create your own formula in a define field to calculate a new date field correctly. If you store year, month, and day in individual fields, you must first create an interim field that has the format of A8YYMD (or A6YMD) and equals YRFLD | MTFLD | DAYFLD. Then, using this interim field, you create a new date field as shown in Figure 12-9.
351
7214chMRDextra.fm
After you create your new date field, this is the one that the users use in all their reports. This format opens up many additional date formatting and arithmetic functions.
7. In the Filter Calculator window (Figure 12-11 on page 353, go to Column, type Europe, and define it as an I1 (integer one long) column. This means that we can test if for true or false in our reports. Double click on COUNTRY under the STORES segment to add it to the filter. Change the Relations to CONTAINS because we need to provide multiple countries for the value.
352
7214chMRDextra.fm
8. Double-click on the countries or use the > button to move the selections to the right hand side in the Value(s) Selection window (Figure 12-12). Click OK to close the Value(s) Selection window and then click OK to close the Filter Calculator window.
9. Verify that it looks like the filter in Figure 12-13 on page 354.
353
7214chMRDextra.fm
10.The filter is displayed in your list of column names when you create a report. Drag the filter to the Selection criteria pane. A WHERE filter is true statement is generated by default. This report now includes only the countries that are defined in the Europe filter (Figure 12-14).
354
7214chMRDextra.fm
2. In the Create Synonym window (Figure 12-16), since our table is a normal DB2 for i5/OS table stored on our local system, select *LOCAL and click OK.
355
7214chMRDextra.fm
3. In the next window (Figure 12-17), specify that the candidates for synonyms are the list of tables in the QWQCENT library. Select the Tables check box and make sure that the Views check box is cleared. For Library, select qwqcent. Then click Next.
356
7214chMRDextra.fm
4. In the next window (Figure 12-18), for Select application, ensure that baseapp is selected and select only the ORDERS table. Do not select with foreign keys. We do not need to create a synonym for the INVENTORY table as we did that in an earlier exercise. Click the Create Synonym button.
5. After you see the window that indicates that the synonym for the ORDERS table was created successfully, click Open (Figure 12-19).
357
7214chMRDextra.fm
6. In Developer Workbench, right-click ORDERS and select Add Segment from Existing Synonym (Figure 12-20). Note: You can add your join from the Modeling view tab at the bottom of the window as well as from the Tree View. Most of the steps are identical. From the Modeling view, right-click the table icon and select Add Segment from Existing Synonym. If metadata for INVENTORY is not yet created, you can select Add Segment Via Metadata Import.
358
7214chMRDextra.fm
7. In the Select Synonym window (Figure 12-21), select cen_inventory as the table to join to ORDERS. Click Select. DB2 Web Query creates a default join between the two tables.
359
7214chMRDextra.fm
8. In the Developer Workbench window (Figure 12-22), in the right pane, for SEGTYPE, the join defaults to Multiple or a one-to-many join. If you want to specify a one-to-one join, change Multiple to Unique. In the left pane, to see and possibly modify the join type and join conditions, right-click CEN_INVENTORY and select Join Properties. Tip: If you are using the Modeling view, you can either click the file icon or you can double-click the arrowed lines between the files to see the Join Properties.
360
7214chMRDextra.fm
9. In the Join Properties window (Figure 12-23), notice that DB2 Web Query has chosen an Inner Join, where Product Number from both tables is equal. From this window, you can override the Join Type and Join Conditions you require. Click OK.
361
7214chMRDextra.fm
contain system variables such as &DATE or the current user name. The current user name can be retrieved using the GETUSER function. 1. From the Synonym Editor (Figure 12-24), right-click cen_orders and select Create Business View.
2. In the next window, you can create folders (right-click) and drag columns, defined fields, computed fields, or filters to your view. Create the business view shown in Figure 12-25.
362
7214chMRDextra.fm
This view is now available to the user who is creating reports just like the original Orders table cluster is. Tip: If you create a business view for a user, the user can open Power Painter and drag the entire business view to the Power Painter palette, instantly creating a report that uses all the columns in the view. This allows the user to basically create a one-step report.
363
7214chMRDextra.fm
4. In the Open window (Figure 12-27), double-click baseapp to see all our tables and views. In the baseapp folder, select Cen_orders.mas and click Open.
364
7214chMRDextra.fm
5. At this point, you can either analyze the impact of modifying individual fields or find any report that references the cen_orders table. In the Developer Studio - Impact Analysis window (Figure 12-28), click Analyze to find all reports that access any column in the cen_orders table. All reports in the Common Domain that use the Cen_orders table are listed in the bottom pane.
Tip: To find the business views that use a specific master file or column, open the table in the Synonym Editor and right-click the table or column name and choose Impact Analysis.
365
7214chMRDextra.fm
366
7214chMRDextra.fm
3. A summary report is produced like the example shown in Figure 12-30. Notice that the fields in blue contain hyperlinks. Click POSTALCODE to see output similar to that shown in Figure 12-32 on page 368. You can profile an entire table, receive this type of a summary, hyperlinked chart, and drill down into the various options. Another way to obtain these options is to directly profile the field.
367
7214chMRDextra.fm
4. Return to the list of columns shown in Figure 12-31. This time we profile an individual column rather than the entire file. Right-click POSTALCODE and select Data Profiling Statistics. Notice the different choices you have when profiling a field.
In the Data Profiling window (Figure 12-32), you can see either the values and patterns associated with POSTALCODE by selecting them from the data profiling submenu or by clicking the appropriate columns in the output report from the statistical analysis.
368
7214chMRDextra.fm
5. To see data outliers, switch to the QUANTITYINSTOCK column. Return to the list of columns (Figure 12-33), right-click QUANTITYINSTOCK, and select Outliers. Data outliers are the ten highest and ten lowest values for a column.
369
7214chMRDextra.fm
Running SQL statements from a file requires the file to be in the DB2 Web Query directories in the integrated file system. Although there are many ways to copy your SQL statement there, we use the functionality in Developer Workbench. 2. Make sure that your Windows Desktop is displayed in your Developer Workbench explorer tree. If it is not displayed, see the Explorer options in 9.2, Setting Developer Workbench default options on page 254. 3. Open your explorer tree and expand down to Common Domain Other Files. 4. Navigating in your Windows Desktop tree, highlight SQLStmt.sql and drag it from your PC to Other Files in Common Domain (Figure 12-34).
370
7214chMRDextra.fm
5. Now that we have the SQL that we want to run in the System i environment, start the DB2 Web Query SQL Wizard. Right-click your Tutorials folder, and select New Procedure (Figure 12-35).
6. In the Create window (Figure 12-36), for File name, create a file called SQL1. For Create with, select SQL Report Wizard. Then click Create.
Tip: You can go directly to the prompt in Figure 12-36 by using the Quicklinks option of SQL-based reports and graphs.
371
7214chMRDextra.fm
7. In the Welcome to WebFOCUS SQL Report wizard window (Figure 12-37), you are presented with three options: Include an external .sql file The .sql file must be located in the DB2 Web Query directories in the integrated file system. The SQL statements in the file should generate a single result set. Type SQL commands directly This option allows you to directly enter an SQL command that will create a result set that can be used by DB2 Web Query Import an existing .sql file and modify This is the same as the first option except you are presented with an additional display where you can edit the SQL statements in the file All options generate an internal, temporary file to hold the results of the SQL execution called SQLOUT. Select Included from an external '.sql' file.
Tip: SQL stored procedures are not included in the SQL wizard because importing SQL stored procedures is part of the base product. You can do this through the Create Synonym functionality in either the base product or optionally through Developer Workbench.
372
7214chMRDextra.fm
8. In the next window (Figure 12-38), accept the default options for accessing the database. Click Create.
9. As shown in Figure 12-39, for the external SQL file name, click Browse. In the Open window, navigate to Common Domain Other Files. Select the .sql file SQLStmt and click Open. Then click Next. Tip: Prior to continuing, you have the option to test the SQL statement against a limited number of records. The output is sent, in default HTML format, to your display.
Figure 12-39 Browsing for your .sql file Chapter 12. Additional features of Developer Workbench
373
7214chMRDextra.fm
10.In the Summary window (Figure 12-40), review your options. Then either select Report Assistant or Graph Assistant. Instead of selecting a table you want to query, you are presented with the output from the SQL. Click Finish.
11.In the window shown in Figure 12-41, notice that the input fields to Report Assistant are the output fields from your SQL execution. You can now choose to format the fields, create additional calculated fields, such as PROFIT = REVENUE - COGS, apply style sheets, and do anything else that you normally do to query a table in Report Assistant. Make some formatting changes, add a heading, and run your report.
374
7214chMRDextra.fm
12.3 Summary
Between Chapter 9, Developer Workbench on page 249, Chapter 10, Online analytical processing on page 257, Chapter 11, HTML Composer on page 289, and this chapter, you have been introduced to many of the features of Developer Workbench. Developer Workbench is a complete GUI development environment. We highly recommended Developer Workbench to DB2 Web Query developers. You have now completed all the tutorials for DB2 Web Query. Now it is time for you to start using this query and reporting tool against your own data. We have tried to introduce you to the more common features within this product. There are many additional features that we have not touched upon. Feel free to experiment and remember that you can always turn to the help text if you need assistance. The help text accessed in Developer Workbench is much more detailed and complete than the basic help text that is available for the other Web components.
375
7214chMRDextra.fm
376
7214chSpreadsheetClient.fm
13
Chapter 13.
377
7214chSpreadsheetClient.fm
13.1 Overview
DB2 Web Query has always had the ability to "push" data out to Microsoft Excel. However, by using the Spreadsheet Client, users can now pull data from Web Query directly from within Excel. This allows them to avoid the trip out to the web browser to request the report and have it directed to Excel output. Instead, the user simply launches Excel and requests the data from there.
13.2 Installation
First make sure you have the latest copy of the Web Query media. If you are unsure, you can download the image from IBM's ESS website. Do a RSTLICPGM LICPGM(5733QU2) DEV(OPT01) OPTION(5), where OPT01 is the name of your optical drive. Install the latest PTFs for Web Query listed in the Info APAR. Finally, do not forget to add your license key for this option. After installing the new feature, an Excel add-in is made available to clients in the IFS, in the same manner the Developer Workbench is provided. End users simply copy the wqsclient.xla and wqsclient.cfg files from /QIBM/ProdData/WebQuery/ibi/webfocus76/utilities to the Microsoft Office Add-in directory on their PC. For Windows XP that is C:\Documents and Settings\userid\Application Data\Microsoft\AddIns\ and for Windows Vista that is C:\Users\userid\AppData\Roaming\Microsoft\AddIns\ where userid is the user name they are logged into the PC as. Once the XLA file is in the correct directory, launch Excel and go to the Add-ins Manager. In versions below 2007, this is off of the Tools > Add-ins menu. In Excel 2007, click the Office button, Excel Options, Add-ins. Make sure the Web Query Spreadsheet Client option is checked. Now the setup is complete and we will move on to usage.
# Web Query server: SERVER_START PROTOCOL = "http" HOST = "myi.mycompany.com" PORT = "11331" HTML_ALIAS = "/webquery_html" CLIENT_PATH = "/webquery/WFServlet" SERVER_END 378
7214chSpreadsheetClient.fm
The only line that was changed was the HOST line. Everything else, protocol, port, alias, and path, are always the values that are entered. The line that starts with # is just a comment. Simply add one of these blocks for each connection that you want. Besides DNS names, you can also enter IP addresses as shown in Example 13-2:
Example 13-2 IP addresses example
# Web Query server: SERVER_START PROTOCOL = "http" HOST = "192.168.2.1" PORT = "11331" HTML_ALIAS = "/webquery_html" CLIENT_PATH = "/webquery/WFServlet" SERVER_END
13.3 Usage
To pull data into Excel, simply right click on the first cell you want to import data into or select the cell and use the Web Query menu or ribbon item. Select Create Query. The first dialog box will ask you for your server's name. The next dialog will ask you to sign in with your user id and password. At this point we will get one of two options, depending on your user licensing.
379
7214chSpreadsheetClient.fm
380
7214chSpreadsheetClient.fm
WF Console (http://yoursystem:11331/webquery_html/wfconsole.htm), logged in as QWEBQRYADM, to select the domain and folder that contain the forms. You cannot set more than one folder so you must place all forms to be used via the SAF mode into this one designated folder. For complete details, see the manual referenced at the end of this chapter.
Once the data is returned into Excel, the end user can do what they want with it. In order to make integration into Excel templates easier, we automatically name the data ranges. This allows for access to various regions of the report without knowing the exact size. So if your data set contains 5 rows or 500 rows in the Sales column, you can refer to them all simply as QDATA1__Sales. There are several new features in Excel 2007 that make it more powerful than ever for data analysis. Check out features such as themes for building dashboards with consistent formatting. Look to the data bar feature of conditional styling to quickly pull out visual values
Chapter 13. DB2 Web Query Spreadsheet Client
381
7214chSpreadsheetClient.fm
for numbers. And of course, don't forget the increased limits on rows and columns; from 65,536 rows by 256 columns (16,777,216 cells) to 1,048,576 rows and 16,384 columns (17,179,869,184 cells).
382
7214chMSSQLAdapter.fm
14
Chapter 14.
383
7214chMSSQLAdapter.fm
14.1 Installation
To begin, you must install the product option 5106 from media. You will also want to make sure you have the latest PTF group installed for DB2 Web Query. This option does have a 70 day trial. If you are installing before purchasing, please proceed. If you have already purchased this option, please use the ADDLICKEY command to add the key to your system. Due to Microsoft's licensing agreements, we are unable to ship required code as part of the Web Query package. Therefore, to complete the installation you must install a version of Microsoft's JDBC driver for SQL Server on your system. To determine which version to download, we need to have a brief conversation about versions. Microsoft currently offers three levels of its JDBC driver. Version 1.1 is designed for SQL Server 2000, version 1.2 for SQL Server 2005, and 2.0 for SQL Server 2008. At the time of publication, Web Query only supports the 1.1 and 1.2 versions of the JDBC driver. Microsoft only finalized the 2.0 version just before the General Availability date for this option. Because of this, we are still working on adding official support for version 2.0 of the driver. When configuring Web Query, we can only configure it for one level of driver; either 1.1 or 1.2. If you have only SQL Server 2000 servers, we recommend using version 1.1. If you have only SQL Server 2005 servers, you must use version 1.2. Luckily, version 1.2 is also backwards compatible to SQL Server 2000 and forwards compatible to SQL Server 2008. Therefore, if you are in doubt as to which version of driver to choose, we recommend the 1.2 version as that will work with all levels of SQL Server. As we are discussing configuration settings, it is important to note that the settings are tied to the driver level and not the level of SQL Server. Let's assume you are using the 1.2 version to connect to both SQL Server 2000 and 2005 servers. Even when you are defining the connection to the SQL Server 2000 server, you follow the settings for the 2005 server since those correspond to the 1.2 version of the driver you are using. So now that you know which version of the driver you want to download, use your favorite search engine or Microsoft.com to find links to the 1.1 or 1.2 version of the JDBC driver. Searching for Microsoft SQL Server JDBC Driver" usually returns the correct page at the top of the results. If prompted, download the Unix version of the driver, not the Windows version. This will download a tar/gz package containing the required Java Archives (JAR) files. Use your favorite decompression utility, such as the open source 7-Zip, to extract the required files. For version 1.1 of the driver, the files are: msbase.jar, mssqlserver.jar, msutil.jar. For version 1.2 of the driver, it is just one: sqljdbc.jar Once you have the JAR files, you need to FTP them in binary mode or use a mapped drive to them onto the system. The JAR files must be placed into the Java Extensions directory located at /QIBM/UserData/Java400/ext. By placing them in this directory, we do not have to worry about setting the proper classpath. This directory is always included.
384
7214chMSSQLAdapter.fm
2. Expand the Domains folder and then select and expand a domain. 3. Expand Reports folder in the domain, right click on a folder and choose Metadata from the menu. 4. You will see an Adapters folder as seen in Figure 14-1. Right click on Adapters and select Add or click the New Adapter menu item.
5. Under the Add Adapter Configuration in the Select Adapter to Add frame, Expand SQL and then the MS SQL Server option. You will see two possible MS SQL Server versions (2000 for version 1.1 of the driver or 2005 for version 1.2 of the driver) represented. Again, choose the version that matches the level of driver you installed, which may not be the same as the level of SQL Server you are connecting to. 6. Click on the appropriate 2005 or 2000 version for your installation. This opens the Configuration pane as seen in Figure 2.
385
7214chMSSQLAdapter.fm
7. In the configuration panel, you name your adapter as desired. In this example the Connection Name is called SQLTEST. This can be any name you want. 8. Enter the URL location for your SQL Server data source. This consist of the driver prefix, the separator ://, and followed by the host name (location) of the SQL Server, the separator:, and the port, in the format as follows. prefix://hostname:port If you are using the 1.1 version of the driver (2000), the prefix is jdbc:microsoft:sqlserver. If you are using the 1.2 version (2005), the prefix is jdbc:sqlserver. The host name for your system can be either the DNS name (sqlserver.mycompany.com) or dotted IP address (1.2.3.4). If you use a DNS name, make sure the IBM i can resolve it by doing a simple PING from the command line to the SQL Server's DNS name. The final piece of this URL is the port number. The default port for the SQL Server is 1433. However, not all SQL Servers run on that port. To find your SQL Server's port number, do the following. First open up the Windows Task Manger. Add the PID (Process ID) column by clicking View > Select Columns > Check the PID option > OK. Find the image name sqlservr.exe and record it's PID. Then open a command prompt and run "netstat -a -n -o" and look for the matching PID number. Under the Local Address column will be 0.0.0.0:xyz. The value xyz after the colon is the port number. Assume the DNS name of our SQL server is sqltest.rchland.ibm.com, the port is 1547, and the version of the driver is 1.2. The URL would then be: jdbc:sqlserver://sqltest.rchland.ibm.com:1547
If the above were the same but using the 1.1 version of the driver, the URL would then be:
386
7214chMSSQLAdapter.fm
jdbc:microsoft:sqlserver://sqltest.rchland.ibm.com:1547
9. Select for Security the option Explicit and provide a SQL Server user and password necessary for authentication. All connections to the SQL Server will use this profile. Therefore it is important that this profile is granted access to all tables to be accessed in the SQL Server. In this example, a User of sqlserver and corresponding Password was provided. This will be unique to your location. 10.The final step is to enter the driver name. Yep, you guessed it. This, too, varied with the version of the driver. If you are using the 1.1 driver, enter com.microsoft.jdbc.sqlserver.SQLServerDriver for the driver name. If you are using version 1.2 of the driver, enter com.microsoft.sqlserver.jdbc.SQLServerDriver for the driver name. 11.Do not be concerned that the CLASSPATH is NOT SET, provided you posted the JDBC driver JAR file in the above directory location - Web Query will find the necessary driver. 12.Click on Configure once the appropriate information is provided. Note that at the time of this Redbook publication, Test was not functional. 13.Once you have configured the new adapter you should restart the DB2 Web Query servers before moving on to create metadata. Use the ENDWEBQRY and STRWEBQRY commands.
387
7214chMSSQLAdapter.fm
3. To define this synonym is a two step process. You will first see a panel similar to Figure 14-4. First identify the target database on the SQL Server. Remember, SQL Server is different from the IBM i in that is has a concept of multiple databases. Within each of those databases are then the schemas which contain the tables. In this example, we have downloaded the Microsoft's AdventureWorks sample database so it shows up in the Select database list. In this example only table objects are requested from selected database. Click the Next button to advance to the second step.
4. In the second step, you select the tables you are interested in querying. In this example, the selection is key employee and department tables and specifying the With foreign keys option. Provide the prefix or suffix if desired and click on Create Synonym once you have selected the tables of interest. As a best practice, we recommend using the schema name followed by an underscore as the prefix and a suffix such as _mssql. This way, your Employee table will show up as HumanResources_Employee_mssql. This will group all items from the HumanResources schema together and provide you with a quick reminder that this data source is from a SQL Server as shown in Figure 14-5
388
7214chMSSQLAdapter.fm
Figure 14-5 Selected tables of interest from the AdventureWorks sample database
5. You will see a summary completion panel similar to Figure 14-6 on page 389. Close that window.
6. You now have a synonym that is specific to tables located in a database on a MS SQL Sever. You can now use this new synonym to build reports using Report Assist, Graph Assist, Power Painter or Developer Workbench, exactly the same way you do with local data synonyms.
389
7214chMSSQLAdapter.fm
390
7214p04.fm
Part 4
Part
Companion products
In this part, we explain more specific topics on DB2 Web Query. This part includes two of the companion products of DB2 Web Query: Chapter 15, Report Broker on page 393 Chapter 16, Software Development Kit on page 417
391
7214p04.fm
392
7214chReportBroker.fm
15
Chapter 15.
Report Broker
DB2 Web Query Report Broker is a separate licensed program product (5733QU3) that builds on the strengths of the web based query and reporting tool, DB2 Web Query. With Report Broker you can automate the process of running your reports and schedule them for distribution to individuals, distribution lists, printer destinations or for storage in a Web Query folder for shared on-line viewing or archival purposes. Although Report Broker is a separate licensed product, once installed, it is tightly integrated with DB2 Web Query. The scheduling function and the ability to view and change existing schedules, create and view distribution lists, view distribution server log entries, establish schedule blackout dates and other Report Broker services are all presented to a Report Broker scheduler or administrator by logging in to DB2 Web Query. To be a Report Broker scheduler or administrator you need the corresponding MRSCHEDULE or MRADMIN as a group profile in your user profile. Also, a scheduler (MRSCHEDULE authority) needs to have developer access to one or more report domains. This tight integration extends to the maintenance of Report Broker services as well. Regularly applying DB2 Web Query maintenance fix packs will also keep you up to date with any existing Report Broker fixes or new function. Report Broker services are included in the DB2 Web Query on-line help. Report Broker help text is context sensitive and will position you to the appropriate help for the corresponding screen or topic. Look for icons with the question mark. Report Broker help text is available in the same language translations as DB2 Web Query. A final point of integration between Report Broker and DB2 Web Query is the starting and ending of the Report Broker distribution server. All three CL commands used to start or end of Web Query services, Start Web Query (STRWEBQRY), End Web Query (ENDWEBQRY) and Work Web Query (WRKWEBQRY) include the Report Broker distribution server as part of the command default '*ALL'. To see how the Report Broker distribution server fits into the DB2 Web Query architecture, see Figure 1-1 on page 11 in the architecture overview on Chapter 1. In this tutorial, we will go in to detail on how to schedule a report for distribution, view the various frequency options when scheduling a report, show how to get failure notifications,
393
7214chReportBroker.fm
create a distribution list, enable a report for a capability known as intelligent bursting and view the log entries for a scheduled distribution. In addition, we will cover some Report Broker capabilities specific to the MRADMIN authority level. We will show how to set schedule blackout dates, do a global update and import a distribution list from another Broker server.
394
7214chReportBroker.fm
1. The first step is to establish the Connection settings needed by the Report Broker repository. Click on Connection and provide the QWEBQRYADM profile and password and then click Save at the bottom of the screen. To test the connection profile and password are correct, click Test Repository in the side panel. You will get a pass or fail indication. You may need to click Test Repository a couple of times before getting a Pass indication. If you persist in getting a Fail, it could be the password in not correct. Tip: Because the Report Broker Distribution Server will regularly connect to the local database to poll for schedule requests using QWEBQRYADM profile and password, if that password is changed, due to password policies at your location, you must immediately update the Report Broker configuration with the new password. Failure to do so will quickly render QWEBQRYADM profile disabled and that will prevent both Report Broker schedule requests and DB2 Web Query user logins from being successful. 2. The next step is to create the underlying DB2 tables used by Broker. Click the option Create All Tables. You will receive a message when the tables are successfully created. The final step is to set the necessary Report Broker configuration settings. See Figure 15-2 on page 396. It is on this screen that you determine key aspects of how the distribution server will run on your IBM i. For example, the name of your E-mail server, how often you want the distribution server to wake up and look for scheduled requests, how far back you want the distribution server to recover 'missed' reports should the server be down, what name and email reply address you want to default on the delivered reports, and a handful of other settings. 3. Click on Configuration. It is recommended you minimally set the Default Mail From value, the Default Mail Reply Address value and most importantly, your email host server name in the Mail Host value. The Notify Mail Host will be equivalent to the Mail Host value unless you designated a different server. You have the ability to request email notification for reports that fail to distribute. Click Save.
Chapter 15. Report Broker
395
7214chReportBroker.fm
The distribution server also keeps a detailed log of all distribution activity, what reports were generated and distributed and when, who received the reports, and any problems encountered during distribution. The Log Purge Period is the number of days the log entry is retained. The Log Purge Time is the time of day when Report Broker purges expired log entries. By default the configuration setting allows 30 days log retention. You also have the ability to automatically recover missed report distributions should the Report Broker distribution server be down. To determine the appropriate configuration setting options for your environment, click Help to get additional information about the settings provided.
396
7214chReportBroker.fm
397
7214chReportBroker.fm
Clicking Schedule will present the Report Broker Schedule panel as is illustrated in Figure 15-5 on page 399. Note that along the top you have a menu bar with several options. You can Save the schedule, Run the schedule, view schedule Log entries, or request Help or the panel. If you exit the panel without doing a save, you will be asked if you are sure..
398
7214chReportBroker.fm
The Description supplied at the top of the schedule panel is primed with the name of the report selected and the current date and time. This description becomes the name by which this schedule request will be known on the Report Broker tab for any future actions on this request. You can change this description to reflect key aspects of the report. For example if this is the monthly gross profit report by product type sent to upper management, you could designate that in the description by providing 'Monthly Management Gross Profit Product Report'. The schedule panel consists of five key sections: Distribution Frequency Report Options Notification Advanced Note that all required fields in all of these sections are designated by an * asterisk The Distribution section indicates how and where the report will be distributed. You have the choice of Email, Printer or a Web Query distribution. These are reflected in the Distribute report by option. The Web Query option allows you to schedule and store the resulting report in a Web Query folder. The folder name is supplied by the schedule request and will become part of the same report domain as the original scheduled report. Using the Web Query distribution option, generated reports can be viewed by multiple Web Query users without
399
7214chReportBroker.fm
each rerunning the report. The Web Query option is also a good way to generate an archive of reports. In this example, however, we are going to distribute a report by email. 1. Under Distribute report by, select the Email option 2. On the Distribution list pull down, select Single Address and supply your own email address in the required field location designated by *. 3. The From and Reply Address of the report are primed with the values supplied when you configured the Report Broker server (see Figure 15-2 on page 396). You can override those values if you wish. 4. The Subject of this report distribution is primed with the name of the selected report being scheduled and the current date and time. It is unlikely that you would want the subject of a repeatedly distributed reports to reflect the initial create time of the schedule request so clear that portion of the subject line or clear the entire subject and provide a more meaningful subject, like 'My first Report Broker schedule request". 5. By default, the report is Sent as an attachment. 6. You have the option to add reports to the zip file, by clicking the Add Reports to Zip File. As this report is small, we will leave that box unchecked. Tip: If you receive a popup message of MSGV0004 on the Save or Run of a scheduled distribution by Email it means your the Mail Host server was not properly configured. See Figure 15-2. The Frequency section determines when and how often the report is distributed. By default the Run Interval is Once on a create and it is primed with the current date and time. For now, we will leave that frequency setting to Once. We recommend that newly schedule reports be set to run Once and to a test distribution email address (like yours) to make sure the subject and additional report options are at desired settings before scheduling a report to deliver to multiple people. Under the Report options section you designate how you want the report to be distributed. We will talk about the Burst this Report option in another example but another important option here is the Send the Report in this Format designation. Based on the type of report being distributed, a Report or Graph, different format options will present themselves. As the RA4_Advanced report was created with Report Assist, you see the allowable options for distributing a text based report. Even though RA4_Advanced was defined as an HTML report in Report Assist, we will choose to distribute the report as an Excel spreadsheet as shown in Figure 15-6 on page 401.
400
7214chReportBroker.fm
7. Take the pull down and select EXL2K FORMULA - Microsoft Excel 2000 Formula. Tip: If you have trouble with your distributed report not opening or displaying correctly, verify that this format option is compatible with the initially created report, particularly for Graph reports or reports targeting printers. 8. Because this report is scheduled to be delivered as an attachment, an attachment name is predetermined. You can choose a different name if a more meaningful one would be helpful for you target audience. Note: Although this report being scheduled does not have any input parameters, the Report Options section allows you to Check and select parameter values required as input parameters when a report is defined with inputs. In fact, if the input parameters were defined in the report as Prompted, those same prompted values will be displayed here for your selection. The name of the parameter field(s) and value(s) when provided would be stored with the report. By scheduling a parameterized report multiple times with different input values, designating different target distribution lists and in a preferred format and on a scheduled basis that works best for that target audience, you further extend the value of your highly parameterized reports 9. Expand the Notification and Advanced sections of the schedule panel. Click on the Notification will be sent out and the Type drop down to view the options available. For this example, we will leave these two sections at the default values of no notification, default priority and enabled. The Notification section allows you to specify if and when you want failure notification and who should receive that notification. You can Always get a notification, Never get a notification or get one only On Error. If you designate notification, you will be required to provide a To and From email address, Full Notification and Reply Address. Note that the Subject is populated with the subject of the original report. You should change the subject to indicate the appropriate notification state. The Advanced section allows you to temporarily disable a schedule report or change the priority of a schedule. A schedule's priority determines which report is served first when multiple reports are scheduled at the same time. The Delete this schedule option gives you the capability to schedule a report designed to run once, at some future date and time, and then is deleted. Refer to Figure 15-7.
Chapter 15. Report Broker
401
7214chReportBroker.fm
Now that we have defined our report to run Once and distribute to a single email address which is your own. 10.Click the Save button at the top of the schedule panel. This will both save your report for future use and run your report once. You will see confirmation of your create as shown in Figure 15-8.
Within a minute or two, check your email, the RA4_Advanced report should be in your email. Open the email and you will see a spreadsheet attachment that reflects the Gross Profit by Product Type report.
402
7214chReportBroker.fm
Notice there are two menu bars in Figure 15-9. The top menu bar lists various thing you can do in Report Broker like work with Schedules, work with Distribution lists, check current running Status, do Global Updates, perform some Change Mgmt and work with Blackout Dates. By default, working with Schedules is the active option and you see the existing schedules. The second menu bar relates to existing Schedules. From this menu bar you can Open a schedule, view a schedule's Log, Delete a schedule, Purge log entries, Clone (copy) a schedule, Run a schedule, view the schedule list by applying a Filter option. By default you see all the scheduled requests you creates as a profile with MRSCHEDULE authority. Note that if you have MRADMIN authority, you have the ability to see ALL schedule requests by clicking on the Filter option. 12.Open the scheduled request by double clicking on the selected schedule. Again you will again see the Schedule panel. Now let's play with the various frequency options available to you. 13.View the various schedule option under the Run Interval tab and select Weeks as shown in Figure 15-10.
14.To schedule a report to run every day of a normal work week, Monday through Friday, at 6AM, select the settings as seen in Figure 15-11.
403
7214chReportBroker.fm
15.Now, lets change the Run Interval to Months 16.To designate that a report run on the 1st and 15th of each month, select both dates in the setting as seen in Figure 15-12.
Another option on this same screen is to designate that a report run on The (radio button) first Monday of the month or the third Thursday. To schedule the same report to run on both a first Monday and a third Thursday, two separate schedule requests would be necessary. To facilitate copying the same schedule request for slight alterations, use the Clone option mentioned above under the main Report Broker Schedules menu. Note that cloned schedules are automatically marked disabled until you enable them under the Advanced settings section. In addition to a primary schedule, you have the ability to schedule a secondary run interval 17.Click on the Apply secondary run interval illustrated in Figure 15-13 on page 405. You can apply a secondary run interval every n minutes or hours after the initial Run Interval is triggered. The secondary run interval is available for schedules that run daily, weekly, per month, quarter or year.
404
7214chReportBroker.fm
18.In order to make schedule change permanent, you must save the schedule request. Change the report back to Run Interval - Once 19.Click Save.
405
7214chReportBroker.fm
Under the main options bar, you will notice the options available for working with Distribution Lists. You can create a distribution list (New), Open for edit or view, and Delete a distribution list 3. Click the New button to create a new distribution list. The create distribution list panel looks as follows in Figure 15-15 on page 406. Distribution lists can be public or private. A private distribution list is only available to the scheduler who creates it. Distribution lists can also be of type Email or Printer. In the case of a Printer list, multiple line protocol printers can be the target for your reports, where the printer name is designated as queue@printserver. Note that Printer distribution lists can also be the target of bursted reports. In this case we will be creating an Email distribution list.
4. Provide a name for you Distribution list, such as ProductTypeDist. 5. Keep the Access as public and the Distribution method as Email. 6. List the various product types (Audio, Video, etc) in the Burst Value column and provide a corresponding Destination email address or addresses for that burst value. Similar to example in Figure 15-16 on page 407. Tip: Note that the match of the burst values in the distribution list to the corresponding section of the report noted by the first Sort by is case sensitive and an exact match is required
406
7214chReportBroker.fm
7. Once you have complete filling in the distribution list, click Save.
You can maintain a distribution list, inserting and deleting list entries, by clicking within the list and selecting the Insert or Delete menu option.
407
7214chReportBroker.fm
5. Click Save. After confirmation of the save, you now have a schedule request saved that bursts a report and targets a distribution list. 6. To run this report, click Run immediate on the Schedules menu bar. You will be prompted to confirm that you want to run the report Off schedule as shown in Figure 15-18 on page 409. Click Yes.
408
7214chReportBroker.fm
If you are quick enough, you can click the Status option along the main menu bar and see you running report. From the status screen you can view currently running distribution requests and you have options such as removing a running report or changing a priority as shown in Figure 15-19 on page 409.
Note that a distribution list is not required for selecting intelligent bursting. If a distribution list is not provided with Burst values and the Burst this Report is checked, the report will still be segmented in to the leading Sort by sections and sent as individual attachments to the designated email addresses. Also note that a distribution list with Burst values can be used if no bursting is requested on the schedule. Each member of that distribution list would receive the full report. Tip: Burst values can be embedded in the subject line of a distribution by using '%burst' in the subject. Similarly, with parameterized report, the supplied input value(s) can be embedded in the subject line of the distributed report by using '&parmname'. For example, if Country was a required input in to the report, '&Country' would provide that country value in the subject line.
409
7214chReportBroker.fm
Each log entries look similar to Figure 15-21 on page 411. The entry designates the report that was distributed, the time and the target distribution. If problems were encountered generating the report or connecting to the email server or connecting to a remote database, that information will be denoted in red.
410
7214chReportBroker.fm
Report Broker also allows you to provide parameter values on a schedule request. In fact if the report is parameterized you must provide valid parameters within the schedule request so the report can be generated in the batch distribution environment. With Report Broker you can schedule that same highly parameterized report multiple times and just by selecting different input values and designating a different target distribution list you can reuse the same created report to meet the needs of lots of report consumers. In fact, your report consumers can get the report they want, when they want it, just by using Report Broker. Figure 15-23 illustrates how a report scheduler selects the appropriate report parameters. By clicking on each specified input parameter, you will either be provided an auto prompt pulldown list for your selection or an input box for providing manual values. If auto prompting
Chapter 15. Report Broker
411
7214chReportBroker.fm
was made possible on the report creation, that same prompting is available during the report scheduling. Note that when you manually enter report parameters, the values provided must be an exact match of the data stored or your report could come up short on data. In this example, Country, Region and State are auto prompted and the From and To date range is manually designated by the scheduler.
412
7214chReportBroker.fm
4. Click the Save button when you have determined the desired blackout dates MRSCHEDULE authorized Broker users can view the scheduled blackout dates but cannot alter them. As an administrator, you can perform a limited type of global update. These updates are unqualified, so they are an ALL or nothing determination. So, for example, if Tom is leaving the company and all his existing reports should now go to Sue, you could perform that type of update by doing the following: 5. Click the Report Broker tab 6. Click the menu bar option Global Update 7. Provide the Old Value email address and a New Value email address for Tom and Sue. Then click Update. You will be prompted to confirm the update as shown in Figure 15-25 on page 414, click OK.
413
7214chReportBroker.fm
The global update request will change the appropriate columns in the DB2 repository tables that reflect email addresses, and will report back the number of changes performed. If a printer changes or an existing email server changes, you can update all existing reports to the new value with one global update request. The final administrator task is one of change management. Say, for example, that instead of creating the distribution list used previously you want to import that distribution list from another Report Broker server. Change management allows you to poll another Report Broker repository, via a DB2 connection, and present the existing public Distribution lists from that other server by the user that create the lists. Figure 15-26 on page 414 show how you configure the connection to that other server.
414
7214chReportBroker.fm
2. Provide the necessary connection information by providing the location of the other broker server in the Source URL and a User Id and Password needed to connect to the repository, then click OK. 3. Click the user whose distribution list you want to import and you will be presented with the corresponding distribution lists. Click the desired distribution lists and click Insert. as shown in Figure 15-27. 4. A summary panel reflecting the import will display the results of the transfer request. Click to close that window. You can now use this distribution list on future schedule requests.
415
7214chReportBroker.fm
416
7214chSDK.fm
16
Chapter 16.
417
7214chSDK.fm
418
7214chSDK.fm
16.3 Requirements
To use the SDK for development work, the purchaser would need the base product at level R111 or higher. They would also need at least one copy of the Developer Workbench product. To use an application written in the SDK, the end user system would require a system with the base product at level R111 or higher. They also need the RunTime User Enablement Feature (5733QU2 Option 4) to allow for unlimited runtime users. Assuming the developers of the code would like to test it, developers will also need the RunTime User Enablement feature. To summarize, to Develop using the SDK you need: DB2 Web Query R111 or higher (5733QU2 *BASE) Developer Workbench (5733QU2 option 3) RunTime User Enablement (5733QU2 Option 4) DB2 Web Query Report Broker (5733QU3) - Optional - only needed if the application will invoke the Report Broker Features. DB2 Web Query SDK (5733QU4) To run an application developed with the SDK you need: DB2 Web Query R111 or higher (5733QU2 *BASE) RunTime User Enablement (5733QU2 Option 4) DB2 Web Query Report Broker (5733QU3) - Optional - only needed if the application will invoke the Report Broker Features.
419
7214chSDK.fm
16.4.4 Samples
To help illustrate how the SDK can be used, we are including three sample screen shots below. The first is of a VB.net application that uses most of the functions described above. The user interface shows the various options discussed in the previous section.
420
7214chSDK.fm
The second is of the enhanced SugarCRM screen as shown in Figure 16-2 on page 422.
421
7214chSDK.fm
Finally, the example screen shot provided in Figure 16-3 shows an RPG based application enhanced to use the SDK. These last two items are some of the possible ideas discussed in 16.2, Uses of the Web Query SDK on page 418.
422
7214chSDK.fm
For a detailed discussion on using the SDK to integrate DB2 Web Query content into a PHP application see the white paper titled DB2 Web Query Integration from PHP - Leveraging DB2 Web Query web services from IBM i applications which can be downloaded from the following URL: http://ibm.com/partnerworld/wps/whitepaper/i/php_db2/webquery This white paper explores the usage of the DB2 Web Query for i Software Development Kit (SDK) with PHP applications running on IBM i. Included in this paper is a reusable PHP application that may be used as a starting point for PHP application providers to integrate DB2 Web Query web services into their web applications.
423
7214chSDK.fm
424
7214p05.fm
Part 5
Part
425
7214p05.fm
426
7214ch11.fm
17
Chapter 17.
427
7214ch11.fm
Report appearance: Based solely on report appearance, a basic user is unable to tell if the
report that is running is based on a DB2 object or a QRYDFN object. The information and appearance of both final reports based on QRY/400 metadata versus DB2 file metadata are identical.
Spooled file output: If your QRYDFN object is defined with the output option of Printer,
DB2 Web Query sends the output to a spooled file.
Database file output: If your QRYDFN object is defined with the output option of Database file, when DB2 Web Query runs that report, it sends the output to a Database file. Batch capabilities: It is common to submit a CL program to batch that performs several RUNQRY commands. DB2 Web Query can also perform this functionality. The eventual goal in some shops might be to completely replace their QRYDFN objects with DB2 Web Query reports. With this in mind, DB2 Web Query has a thread-safe command that allows all your reports developed in DB2 Web Query to be used in your batch jobs. Right Join: WRKQRY does not support Right Join and neither does DB2 Web Query.
Just as DB2 Web Query supports Query/400 functions, likewise the reverse is true. With the exception of what we discussed in Chapter 5, Report Assistant on page 97, all Report Assistant functions can be used on Query/400 metadata. Recall that DB2 Web Query sees the Query/400 result set much like a table.
428
7214ch11.fm
Parameter passing
It is possible to create a QRYDFN object that can accept parameters at run time. This is done by using a variable in the selection clause. Figure 17-1 shows how this is used. Then the QRYDFN object is called by using the STRQMQRY ALWQRYDFN (*YES) command, which prompts the user for parameters.
As noted earlier in this chapter, DB2 Web Query sends the RUNQRY command to the server. It does not send any version of STRQMQRY. This limitation means that QRY/400 queries that were coded for use as STRQMQRY ALWQRYDFN(*YES) to allow parameter input must instead use the DB2 Web Query parameter passing. First, you must change your QRYDFN object to not accept parameters. After you create the metadata, you can use Report Assistant to code the parameters into the selection criteria. See 5.4.1, Parameterized reports on page 133, for creating a parameterized report.
Chapter 17. Using DB2 Web Query to run existing Query/400 reports
429
7214ch11.fm
430
7214ch11.fm
2. In the Query Synonym for Query iSeries pane (Figure 17-3), enter the library where the QRYDFN object resides. In this case, we enter the RMMASON library. Click Submit.
3. In the Select Synonym candidates for Query iSeries pane (Figure 17-4), complete these steps: a. Select the Query/400 object on which you want to create metadata. b. If you previously created a synonym on this object and want to replace it, select Overwrite existing synonym. c. In this case, this is the first time for creating metadata on QRYDFN in this library. Therefore, we select Default synonym name. By selecting this option, every QRYDFN in the entire library is selected.
d. You see a warning message like the one in Figure 17-5, which says that the synonym creation process can take a long time. Click OK to indicate that you want to continue.
Chapter 17. Using DB2 Web Query to run existing Query/400 reports
431
7214ch11.fm
e. Click Create Synonym. 4. In the Create Synonym for Query iSeries pane (Figure 17-6), if synonyms creation was successful, you see a status of Create successfully. Click Next.
5. In the Create Synonym for Query/400 File: Save Reports pane (Figure 17-7), notice the Report Name column. Click Next. This is the last pane on which you must click Next. DB2 Web Query creates a report from your QRYDFN.
432
7214ch11.fm
6. In the Create Synonym for Query/400 File: Save Reports Status pane (Figure 17-8), notice that the status indicates Created successfully for the Query/400 metadata creation. Close this window.
Figure 17-8 Created successfully message - Conversion from Query/400 to DB2 Web Query
Now if you go back into your DB2 Web Query domain, notice that the metadata is already created as a report. You can click this report to run it or right-click it for the editing options.
Chapter 17. Using DB2 Web Query to run existing Query/400 reports
433
7214ch11.fm
434
7214ch12.fm
18
Chapter 18.
Performance considerations
Minimizing the processing time for report requests and maintaining the accuracy and integrity of the report data are major goals for most organizations. In this chapter, we discuss DB2 Web Query performance considerations and recommendations. We include a case study that is intended to demonstrate steps that you can take to tune a DB2 Web Query report.
435
7214ch12.fm
436
7214ch12.fm
The process of running a DB2 Web Query request consists of two phases: The execution phase The report production phase Figure 18-1illustrates the flow of the request through these two phases.
Execution phase
HTTP Clients
437
7214ch12.fm
c. Translates (optimizes) the DB2 Web Query request to the appropriate SQL statement or statements d. Passes the SELECT statement or statements to the DB2 for i database engine 5. The database engine component handles the following tasks during this phase: a. b. c. d. Analyzes and optimizes the SQL statement or statements Chooses the appropriate access path and retrieval method Retrieves the data Creates the database result set
438
7214ch12.fm
Table 18-1 displays the DB2 Web Query operations and the SQL equivalent.
Table 18-1 DB2 Web Query operations and SQL equivalent Operation Retrieve rows for columns specified SQL equivalent SELECT SELECT DISTINCT(.) Identify the table from which to report FROM
WHERE
Ordering rows
ORDER BY
HAVING
FROM...WHERE...
439
7214ch12.fm
Selection is the process of retrieving the table rows that meet the request criteria. Selection is translated to various predicates of the SQL WHERE clause except those expressions listed in Table 18-2.
Table 18-2 Selection disablers Selection disabler Non-translatable DEFINE fields Description Certain DEFINE expressions can be translated to SQL as part of aggregation or record selection operations. In some circumstances, they can be used as part of a define-based join. The following examples are of translatable DEFINE expressions: For selection, the DEFINE expression must be an arithmetic valued expression, a character string valued expression, or a logical expression. For aggregation, the DEFINE expression must be an arithmetic or character string valued (COUNT) expression. These expressions are based on what is built (for example, on the right side of the equal sign) in the DEFINE expression, not on the format of the field that is being defined. Table 18-3 provides more information about the DEFINE field expressions that can be translated to SQL. Non-translatable DATE fields Spanned DEFINE fields DATE fields with formats other than YMD or YYMD DEFINE fields that span more than one segment in a joined structure
Table 18-3 lists the DEFINE expressions that can be translated to SQL.
Table 18-3 DEFINE expressions that can be translated to SQL Expression Arithmetic expressions NEWSAL/D12.2 = ((CURR_SAL + OTIME_SAL) x 1.1) - 100; SQL translatable conditions Real-field operands of numeric data types (I, P, D, F) Numeric constants Arithmetic operators (**, *, /, +, -) Subtraction of one DATE field from another DEFINE-field operands satisfying any of the above Real-field operands of alphanumeric data types. (TEXT field formats are not supported with DEFINE expressions) String constants String concatenation operators DEFINE-field operands satisfying any of the above Real-field operands of any DB2 Web Query-supported data type (including DATE fields) Constants with same data type as field(s) in the predicate Relational operators (EQ, NE, GT, LT, GE, LE) Logical operators (AND, OR, NOT) Arithmetic or character string expression operands (above) DEFINE-field operands satisfying any of the above
Logical expressions (Expressions that are evaluated as true, 1, or false, 0.) SALES_FLAG/I1 = (DIV_CODE EQ 'SALES') OR (COMMISSION GT 0); QUOTA_CLUB/I1 = (SALES_FLAG) AND (UNITS_SOLD GT 100);
440
7214ch12.fm
For more information about creating DEFINE fields, refer to Defining and computing fields on page 115. Projection Projection is the process of retrieving the table columns that meet the request criteria. Projection is translated to be objects of the SELECT statement as follows: Columns referenced in PRINT, SUM or COUNT commands. Columns used as objects in JOIN or DEFINE operations. PRINT * and SEG.fieldname return all columns in the Master File only. Note: SELECT * is never generated by DB2 Web Query. It is important to understand the DB2 Web Query selection and projection operations because they are both processes that reduce the volume of data that is returned from the database, which helps to improve performance, efficiency, and report response time.
Optimization hierarchy
In addition to individual operations being optimized, a progressive optimization hierarchy affects the SQL that is being generated. Figure 18-2 shows the order of adapter optimization.
If the join optimization fails, so does the sort and aggregation optimization.
Aggregation optimization occurs only if the join and sort operations were optimized and aggregation was required.
Translation to SQL: Regardless of the hierarchy in Figure 18-2, the adapter always tries to translate row selection (WHERE) and projection operations to their SQL equivalents. This hierarchy is mentioned because it is important for you to know what to focus on first. If your reports ordering or aggregating is not being performed by the database engine and you are unable to determine why, it might be because join optimization is failing. Therefore, if you
441
7214ch12.fm
have a poorly performing report that is joining two or more tables, your analysis should begin with join optimization.
Join optimization
A join operation is a complex function that requires special attention in order to achieve good performance. Again, it must be stressed that the goal is to allow the database engine to perform as much of the optimization and processing as possible. Due to their potential complexity, this is especially true for join operations. If the join is processed by the database engine, the following steps occur: 1. The DB2 Web Query request is optimized and is translated to a single SQL select statement. 2. The database engine retrieves the data from the tables specified in the select statement. 3. The database engine merges the rows using its chosen join implementation 4. Screening conditions are applied, if any. 5. The columns in the request are applied. 6. Any column function values or expressions are calculated. 7. One result set is produced. Table 18-4 illustrates the strengths of DB2 Web Query as well with the corresponding strengths of DB2 for i.
Table 18-4 Quick guide to strengths of DB2 Web Query and DB2 for i DB2 Web Query strengths DB2 for i federated joins Complex calculations Sophisticated formatting Generate graphs DB2 for i strengths Joining on local tables (SELECT...FROM...WHERE) Row and Column selection (SELECTWHERE) Sorting (SELECTORDER BY) Aggregation (SELECTGROUP BY)
Referential integrity and constraint awareness: As of V5R3, the SQL Query Engine also has referential integrity and constraint awareness. This means that the optimizer is capable of using the referential integrity conditions to rewrite the queries to eliminate unnecessary join combinations. This can result in significant performance gains for queries with complex joining and is another compelling reason to try to achieve full DB2 Web Query optimization. DB2 for i usually handles the join if all the DB2 Web Query commands (where possible) are translated to their SQL equivalent. However, because of the processing hierarchy, sorting and aggregation can still fail.
442
7214ch12.fm
DEFINE fields that span more than one segment in a joined structure Multiplicative effect
Federated joins
When you create a join connection (via the join tab) between tables, DB2 Web Query might choose to generate and run multiple SQL statements to compute the correct output for your report. In some cases, DB2 Web Query can reduce these multiple SQL statements to a single SQL statement thereby improving DB2 Web Querys performance considerably. In particular, when the joined in table (called the target table on the right of the join panel) is joined via a unique join, DB2 Web Query can process the entire report in one underlying SQL query. A unique join is one where given a row from the initial table or tables (called host tables on the left of the join panel) matches at most one row in the joined in target table (on the right tab). The join must be unique over the entire set of target table joined columns. Note that no one column must be unique in the target table.
443
7214ch12.fm
To determine whether it is safe to select the Use database optimization check box and avoid the multiplicative effect, you can use one of two verification methods: Database constraint verification If either a primary or unique database constraint is in place for a table against a specific column or combination of columns, the database guarantees data uniqueness based on that constraint. In such cases, it is safe to select the Use database optimization check box for that join. Manual verification Tables might have unique data without strict database constraint enforcement. You can also verify that the data is unique by inspection or knowledge of the data. The database administrator can run queries similar to the following example to see if the current state of the data is unique: SELECT CASE WHEN count(*) = count(distinct JoinColumn1||JoinColumn2||...||JoinColumnN) then 'Unique' else 'Not Unique' END FROM target_table If the state of the data is currently unique, the administrator must use their judgement and knowledge of the data to decide if future states of the data are also unique. If you are not sure if future states of the data will be unique over the join columns, then it is better to err on the side of caution and not select the Use database optimization check box.
444
7214ch12.fm
Sorting optimization
If any of the conditions listed in Table 18-6 are true, DB2 Web Query performs the sorting.
Table 18-6 Sorting and aggregating disablers Sort disablers DB2 Web Query managed join Sort on a non-translatable DEFINE field Interface-managed join Description See Table 18-5 on page 443 Any request that contains a sort on a non-translatable DEFINE field SQL sorts the answer set by the tables primary key, causing DB2 Web Query to re-sort for the display report.
Aggregation optimization
If any of the conditions listed in Table 18-7 are true, DB2 Web Query performs the aggregation.
Table 18-7 Aggregation disablers Aggregation disablers DB2 Web Query managed join or sort DB2 Web Query managed row selection Non-direct SQL operators Aggregation on a non-translatable DEFINE Description See Table 18-5 on page 443 and Table 18-6. Some WHERE clauses are not passed to the database engine. The request contains direct operators, such as PCT., TOT. that cannot be translated into SQL. Aggregating on a DEFINE field that cannot directly translate to SQL.
445
7214ch12.fm
The advantages of using views are many. The following list gives an idea of what SQL views can do: Provide the ability to specify additional join types that are not supported by the DB2 Web Query product DB2 Web Query allows you to specify inner joins and left outer joins. With SQL views, you can define those and the following join types: Right Outer Left Exception Right Exception Allow you specify CASE statements to handle more complex, conditional logic Provide fullselect support An SQL fullselect is the term for generating an SQL result set by combining multiple SELECT statements using the UNION, INTERSECT, or EXCEPT operators. This is a feature that helps you solve more complex business requirements. Provide Common Table Expression (CTE) and recursive SQL support CTEs can be thought of as temporary views that exist only during the execution of an SQL statement. When defined, the CTE can be referenced multiple times in the same view. This can be used to reduce the complexity of the view, making it easier to comprehend and maintain. Among the V5R4 enhancements for DB2 for i was the ability for a CTE to reference itself. This feature provides the mechanism for recursive SQL, which is especially useful when querying data that is hierarchical in nature, such as bill of materials, organizational charts, and airline flight schedules. For more information about recursive CTEs, refer to the article V5R4 SQL Packs a Punch, which you can download from the Web at: http://www-03.ibm.com/servers/eserver/iseries/db2/pdf/rcte_olap.pdf Allow business logic to reside in the database layer, making it available to all users and all SQL interfaces Provide an database abstraction layer Provide security granularity When the views are in place, you can restrict users from accessing tables directly and only allow access through the views. Because both selection and projection can be specified on the views, you can control specific rows and columns that users (or groups of users) can access. Important: Views should not be confused with indexes. They are implemented as non-keyed logical files. This means that views, unlike indexes, have no access paths and thus, no access path maintenance. If you or your database administrator (DBA) are concerned about access path maintenance, this is not an issue with views.
7214ch12.fm
relationships, DB2 Web Query is able to understand the join syntax that needs to be created and generates the appropriate SQL statement. The process of creating synonyms with foreign key relationships is discussed in Referential Integrity on page 56.
447
7214ch12.fm
4. In the Create Synonym for DB2 cli pane (Figure 18-5), specify a prefix and suffix, select the MQTs that are listed, and click the Create synonym button.
After the synonyms are created for the MQTs, you can create reports against them as you would for any other table object on the system. While their potential performance efficiencies are appealing for DBAs, query developers, and report users, MQTs have several attributes and limitations that must be understood prior to implementation. Probably most important, you must know that MQTs are not automatically maintained. This means that as the base tables used to populate the MQT change, the data in the MQT does not also change. If the data in your reports must be up to date, the MQT must first be manually refreshed. Therefore, before implementing MQTs, you must be willing to accept some level of data latency. This is can be acceptable for queries that report on data that is historical in nature. However, if your report requires data that is dynamic and up-to-theminute, you might come to the conclusion that an MQT is not the right fit. For more information about MQTs, see the white paper Creating and using materialized query tables (MQT) in IBM DB2 for i, which you can find on the Web at: http://www-304.ibm.com/jct09002c/partnerworld/wps/servlet/ContentHandler/ SROY-6UZ5E6
448
7214ch12.fm
However, you must be aware of the performance implications if the data is spread across two or more System i machines or partitions. In this scenario, DB2 Web Query generates a separate SQL statement for each connection and submits the statement to each connection. The answer set from each of these multiple sources is then joined together by the Reporting Server. Depending on how the joins are specified, this can be a lengthy and time consuming process. Consider the following scenario. A fact table (ORDERS) has 32,283 rows and is joined to a dimension table (STORES) that has 116 rows. If both of the tables are on the local (or even remote) system, DB2 Web Query generates a single SQL statement and submits it to DB2 for i. Example 18-1 shows how the statement looks.
Example 18-1 Single SQL statement
SELECT T2."Country",T2."State", SUM(T1."LineTotal") FROM CENTURY/ORDERS T1,CENTURY/STORES T2 WHERE (T2."StoreCode" = T1."StoreCode") GROUP BY T2."Country",T2."State" ORDER BY T2."Country",T2."State" FOR FETCH ONLY Since one statement is generated and the database engine handles all the joining, grouping, and ordering, you can expect this report to run quite efficiently. However, if the dimension table STORES resides on another system and Report Assistant is used to create a nearly identical report (the only difference being a cross system join specification to STORES), DB2 Web Query now creates two SQL statements, one for each system. Local system
Example 18-2 Local system SQL statement
SELECT T5."Country",T5."State" FROM "CENTURY"/"STORES" T5 WHERE (T5."StoreCode" = ?) FOR FETCH ONLY Inefficiencies occur because the remote SQL statement is submitted multiple times on the remote system. The local system fetches each row from the (local) ORDERS table result set and generates the appropriate local selection to return the matching row from the remote STORES table. With this implementation, the report takes significantly longer before the results are displayed to the browser. If the report is modified to specify STORES (with only 116 rows) as the base table, the join fan-out is greatly reduced. This results in a report that runs significantly faster, but is still not nearly as fast as when all tables are on same system. Therefore, we generally recommend that you avoid creating reports with cross-system joins when the tables have a substantial
449
7214ch12.fm
number of rows. However, if such an implementation is required, consider the following suggestions to enhance the reports performance: Eliminate the reports requirement of multiple connections by making local copies of the remote tables. After all tables are on one system, join optimization can be enabled and DB2 Web Query attempts to generate a single SQL statement. Determine which of the tables has the smallest number of rows (after applying local selection) and make that the base table of the report. This reduces the fan-out effect of the join, thereby reducing the number of rows that must be retrieved from the other (larger) tables. Edit the report source and add the following line: SQL DB2 SET JOINTYPE SORTMERGE Figure 18-6 shows an example of this setting specified in the report source. This setting impacts the number of FOR FETCH lines when one of the tables is remote. In effect, it turns all of the tables into local internal tables and sort merges them.
450
7214ch12.fm
Because the adapter is running the existing query, you are limited in the tuning that can be done to make each of the DB2 Web Query processes perform better. In most cases, the sole tuning knob ensures that the appropriate indexes are in place for the optimizer to use when creating the access plan for the query. Refer to 18.4.3, Indexes on page 461, to learn about approaches for implementing an indexing strategy. As we mentioned earlier in this chapter, Classic Query Engine (CQE) processes non-SQL database requests such as those from Query/400 queries. CQE provides index advisory information for query selection. Missing from CQE is the ability to create index advisories for joining, grouping, and ordering. Analysis and tuning, which are more manual in nature, are required for these types of requests. If your Query/400 reports are not performing to your satisfaction, make sure that the indexes exist over all join fields, order by fields, and fields that are aggregated.
451
7214ch12.fm
Lacks flexibility The database is difficult to maintain, adapt, and expand. Repeating groups must be squeezed into a single record, which places limits on the number of repeating groups that can fit into a single record format. Less optimal access methods Performance of these reports can suffer because of the database complexity. Programmatic selection, joining, ordering, and grouping are often implemented with a row-at-a-time coding techniques. Record blocking and set-at-a-time processing are not used, and therefore, the report performance is not maximized. If this describes your current database design, you might want to consider investing in a robust data modeling tool that can help you implement a database design that is both functional and efficient.
Sort sequences Non-SQL Interfaces (OPNQRYF, Query/400, QQQQRY API) Logical File reference on FROM Clause Select/Omit Logical Files defined on tables User Defined Table Functions (UDTFs), UPPER & LOWER functions Read Triggers
ICU 2.6.1 Sort Sequences Non-SQL Interfaces (OPNQRYF, Query/400, QQQQRY API) Logical File reference on FROM Clause Select/Omit Logical Files defined on tables
Important: While as of 6.1, the SQE optimizer is still unable to utilize Select/Omit logical files when building query plans, IBM did change the default value for the Ignore_Derived_Index QAQQINI parameter to enable more SQE usage. This QAQQINI parameter was first added back in V5R3 to allow the SQL Query Engine to be used in environments where SQL statements are referencing DB2 objects created with DDS. Prior to 6.1, the default value for this parameter was *NO causing the SQE optimizer to reroute execution of any SQL request to the Classic Query Engine (CQE) anytime a derived logical file was encountered during the query optimization process. The default value in 6.1 for the Ignore_Derived_Index QAQQINI parameter has been changed to *YES. This value allows the SQE query optimizer to ignore any keyed logical files that contain select/omit criteria during optimization and process the query instead of rerouting execution to CQE. Your goal as a database administrator or DB2 Web Query administrator/developer should be to ensure that each DB2 Web Query request is processed by SQE. Why is this so important? Because SQE is IBMs strategic optimizer, and as such, it will be the one that the IBM development team focuses on. Enhancements that add new features and boost performance 452
Getting Started with DB2 Web Query for i
7214ch12.fm
will only be applied to SQE, and not CQE. Consequently, when a query is processed by SQE you can expect vastly superior performance over the same query handled by CQE. Some of the reasons for this include: Enhanced optimization techniques a smarter, faster, and more efficient optimizer Self learning query optimization Ability to self-adjust during query execution Better/faster database primitives to access the data In addition, SQE provides many more features than CQE. Among them are the following: Materialized Query Tables (MQTs) Maintained Temporary Indexes (MTIs) SQE plan cache Ability to cache results Achieving SQE processing for every DB2 Web Query request is quite simple: avoid SQE Inhibitors! What could be easier? All kidding aside, the following list provides the major things to look out for in a proactive mode: Avoid creating metadata for DDS logical files Only create metadata over tables/physical files, SQL views, or MQTs. If you need the filtering or joining provided by a DDS Logical File, create an SQL View that performs the equivalent filtering/joining Watch out for Select-Omit logical files against physical files Again, this is not as important in 6.1because the default behavior is for SQE to ignore Select-Omit logical files. But if you are at 5.4 of the IBM i operating system, and you need to create metadata over a physical file that has Select-Omit logical files against it, you will can instruct the optimizer to ignore this derived logical file by using the IGNORE_DERIVED_INDEX parameter in the QAQQINI query options file. This process is documented in the tech tip Maximize SQL Query Engine (SQE) Usage of Your DB2 Web Query Reports which can be access from the following URL: http://www.mcpressonline.com/database/db2/maximize-sql-query-engine-sqe-usage-o f-your-db2-web-query-reports.html Use the DB2 CLI adapter whenever possible! Keep in mind that both the Heritage File and Query/400 adapters use CQE Recreate Query/400 reports as new reports that use synonyms based on DB2 CLI adapter No way to avoid it for multi-format files (must use Heritage File adapter) Use SQL Aliases to access multiple members
453
7214ch12.fm
Navigator. Visual Explain is then launched against the statement to produce a graphical representation of the optimizers chosen access plan for the query, as well as a wealth of information about the plan. Part of the information provided in this process is which query engine is used. To implement this method, take the following steps: 1. Right-mouse click on the report and select Run w/SQL Trace
Figure 18-7
Rather than running the report and displaying the results, this option displays the generated SQL statement. 2. As shown in Figure 18-8, copy this statement to your clipboard
3. In System i Navigator open a connection to your system and launch a Run SQL Scripts window. 4. Paste the statement from your clipboard into the Run SQL Scripts window. This is shown in Figure 18-9 on page 455.
454
7214ch12.fm
Tip: Depending on your configured naming convention (*SQL or *SYSTEM in the format tab of the JDBC settings for your System i Navigator connection), you may have to edit the statement after you paste it into the window. The naming conventions are: *SQL naming convention uses a period (.) between the library and object names. *SYS naming convention uses a forward slash (/) between the library and object names. This means that you may have to the replace the / character with a . for all qualified object references. 5. As shown in Figure 18-10, swipe/highlight the statement and click the Explain icon in the tool bar.
455
7214ch12.fm
This action launches the Visual Explain utility. Visual Explain provides information about the optimizers chosen access plan. It also renders a graphical representation of the query access plan. 6. Select the Final Select icon on the plan and scroll down to the bottom of the Attribute pane on the right. This is shown in Figure 18-11.
The Query Engine Used attribute appears at the bottom. The value of this attribute provides the information you are looking for. In this case, SQE was used.
456
7214ch12.fm
3. On the SQL Performance Monitor Wizard dialog window, specify the following: Name: DB2 Web Query Redbook monitor Type: Detailed Schema for data: QGPL Click the Next button. An example screen is provided in Figure 18-13.
The second dialog window for SQL Performance Monitor Wizard is presented. This window allows you to specify pre-filtering criteria for the monitor collection. Using pre-filtering is strongly recommended because it can greatly reduce the amount of monitor
Chapter 18. Performance considerations
457
7214ch12.fm
data collected. This will help keep your analysis simple. In this example, you pre-filter on the user profile running the request and the schema (library) name of the object being queried. This should keep the collection small - ideally to a single SQL statement. 4. As shown in Figure 18-14, specify the following prefilter criteria and click the Next button: Check the box for Current user and specify your user profile name Check the box for the setting Statements that access these objects: and under Schema, enter QWQCENT
5. On the third dialog window for SQL Performance Monitor Wizard, select the radio button for All jobs and click the Next button. An example is displayed in Figure 18-15.
On the final dialog window for SQL Performance Monitor Wizard, click the Finish button.
458
7214ch12.fm
6. Return to your DB2 Web Query browser session and run the report. At this point the monitor data has been collected for the report run. The monitor can now be ended. 7. Return to the System i Navigator session. Under the connection, select Databases <name_of_your_database>SQL Performance Monitors A list of available SQL Performance monitors are displayed. 8. Find the monitor you just started and select End from the right-click menu (Figure 18-17).
9. Now you can analyze the results. Again, right-click on the monitor entry. This time select the Analyze option as shown in Figure 18-18 on page 460.
459
7214ch12.fm
The SQL Performance Data Analysis dashboard window is launched. Under the Overview category, find the lines for SQE and CQE. As displayed in Figure 18-19 the dashboard shows the value of 1 for SQE and 0 for CQE. This means your query was processed by SQE.
460
7214ch12.fm
18.4.3 Indexes
Like any other application that accesses information from the database, efficient DB2 Web Query performance heavily depends on having the right indexes in place. When your database is in production, it might be difficult to implement recommended database design practices such as database normalization. However, at this point, you can still implement an indexing strategy that helps to optimize the performance of your query reports. Indexes over your database tables have the following advantages: Provide statistics to the optimizer Indexes against the queried tables give the optimizer a better opportunity to select the most efficient access method. This is because they provide relevant statistics and information, such as the average number of duplicate values and column cardinality of the tables being queried. Such useful information provided to the optimizer results in a better access plan and a better performing query. Improve efficiencies The optimizer can choose to use the index during implementation, thus avoiding more costly implementation alternatives such as table scans or creation of temporary structures. If a table scan is performed, every row in the database table must be read. Depending on the size of the tables and the complexity of the query, this an be a lengthy process and can consume a significant share of system resources. Ensure uniqueness A unique index on a column ensures that no duplicate values exist for that column. Using indexes might result in the following ramifications: As mentioned previously, indexes can speed data retrieval. In some cases, requests might only need to use the index, never accessing the actual data (a condition referred to as Index Only Access). Even secondary indexes can be used in the case of data selection statements. Indexes add overhead to a database. Indexes must be maintained by the database whenever the data in the underlying table changes. Sometimes DBAs are reluctant to add indexes for reporting application efficiency if the database is one that is not dedicated to reporting purposes. Indexing strategies is a broad topic that is covered in detail in the white paper Indexing and Statistics Strategies for DB2 for i. You can download this paper from the Web at the following address: http://www.ibm.com/servers/enable/site/education/ibo/record.html?indxng In addition, the following tips can help you get started: Take a proactive approach and make sure there are indexes available over all of the selection, joining, ordering, and grouping columns of your queries. In a reactive mode, run your queries and use the available database feedback mechanisms to determine what indexes the optimizer wants created. When a query is executed, the database engine provides index advice during the optimization phase. This occurs when it determines that a useful index does not exist against the table or tables that are being queried. It makes a recommendation that the
461
7214ch12.fm
index be created. Afterward, this advice can be obtained from various sources, including the following sources: Index Advisor SQE Plan Cache SQL Plan Cache snapshot, 3020 record SQL Performance Monitor, 3020 record Visual Explain
The index advisories can be extracted from these sources of optimizer feedback and used to create the recommended indexes. Important: When an advised index is created and the query is run again, you might observe that the optimizer does not use that index during implementation. Indexes are sometimes advised for the information they can provided to the optimizer. This information is used to help the optimizer cost each access method. It might also help the optimizer determine that the advised index is not the optimal one to use during query execution. For more information about SQL and database performance analysis, refer to OnDemand SQL Performance Analysis Simplified on DB2 for i5/OS in V5R4, SG24-7326.
A balanced system
While sufficient hardware resources to run your workloads is critical factor, it is also important that you have a balanced hardware configuration. What does this mean? It means that simply adding more memory or another processor to your system may not improve overall performance and create an unbalance in the environment. This is because when it comes to driving workloads, the ultimate goal is to keep the processor busy while minimizing wait times (queueing). To help illustrate this, consider the following dish washing analogy: Lets say you own a restaurant and one of the workloads to be performed is washing dishes. In this subsystem the busser (term used for both busboy and busgirl) brings the dirty dishes and places them in the sink and the dishwasher (a person) takes the dishes out of the sink and washes them. Each component in this process can be analogous to a component in your hardware configuration: The dishwasher - the processor The sink - memory The bussers - disk units/arms
462
7214ch12.fm
The goal is to keep the dishwasher busy (as long as there is work to be done) so that the dishes are cleaned as fast as possible. Therefore, acceptable performance and a balanced system are largely dependent on the following: The speed of the dishwasher The number of dishes to be washed Performance expectations Lets say the process is not going as fast as you would like and not enough dishes are being cleaned. Your performance expectations are not being met. So you take the following steps: 1. You walk into the kitchen and discover that Frank, the dishwasher is waiting for work. This means that queueing is occurring earlier in the process. You observe that there are 4 bussers (working frantically) and they cannot bring dishes into the sink fast enough (queueing at the disk I/O level is occurring). So you hire four more bussers. 2. This corrective action helps and Frank becomes busier but is still waiting for work. So, again, you hire four additional bussers. This has no effect on performance because now the bussers are queued up, waiting to place dishes in the sink because the sink is full (not enough memory). This is an example of an unbalanced system. 3. Showcasing your sharp business acumen, you purchase a bigger sink (more memory). This eliminates the queuing at the sink and Frank stays busy all the time. You now have a balanced system, but you are still not satisfied with the pace of which the dishes are being washed. 4. What the heck, you think to yourself it worked before. So you trade in that sink for one that is even larger. You then observe that many more dishes can be placed in the sink, but it does not help overall performance whatsoever, This is because the dishes are piled up in a big heap in the sink and poor Frank can not work any faster (too much memory). At this point the system is again out of balance. 5. Evaluating the situation, you ascertain that hiring more bussers will not help. And an even bigger sink would a foolish purchase. You conclude that there are two choices: you can either fire Frank and hire a faster dishwasher (upgrade) or you can hire another one to help Frank out (add another processor). Frank is a good guy and has never called in sick once in the three years he has been employed, so you decide to help him out and hire his third cousin Gus. This new hire proves to be the right move: Frank and Gus become a formidable dishwashing duo, producing clean plates at a brisk and more than acceptable pace. The number of bussers is optimal as is the size of the sink, thus here is no queueing. You finally have a balanced system that meets your performance expectations. This simple analogy is meant to illuminate the fact that the amount of work to be done, performance expectations, and a balanced system must be considered when it comes to evaluating your hardware resource needs.
463
7214ch12.fm
Once you are into the DB2 Web Query WLE, you define the workload characteristics to the tool. Information such as the following should be included: 1. Users Includes the number of concurrent users and developers and the types of users (heavy, medium, light), 2. Environment Attributes about the environment the DB2 Web Query product will be running in. This include factors such as the size of your database 3. Specifics of production environment, if applicable. Specify whether queries are running in a shared Environment (for example, against production databases) or a dedicated Environment (for example, a data warehouse) Once you have completed these steps, the sizing guide will provide an estimate of the minimum hardware configuration necessary to run the defined DB2 Web Query workloads Note: Although DB2 Web Query does not require Power6 hardware, the DB2 Web Query WLE produces Power6 hardware recommendations only Figure 18-21 on page 465 provides an example of the output produced by the DB2 Web Query WLE.
464
7214ch12.fm
Figure 18-21 Sample output of work load estimator for DB2 Web Query
Important: The use of the Workload Estimator and its results are restricted to the purpose of helping you predict a possible system solution. These results are estimates and averages based on certain assumptions and conditions, and are based on measurements and analysis with a variety of workloads (internal to IBM and by third parties), performance characterizations of systems hardware and software, and best performance practices. Please ensure that realistic inputs have been provided for the high-level configuration, the workload definitions, and user options. Actual customer results may differ significantly. The system recommendations are based on measurements of a fixed set of reasonably well-tuned queries. Resource requirements for any specific user workload will vary depending on the complexity of the queries, the make-up of the database and the extent to which the queries have been tuned.
465
7214ch12.fm
dishes that need to be washed. Frank and Gus may need some help, perhaps in the form of more bussers, a larger sink, or another dishwasher. The balanced system may need an adjustment. Much of this is obvious, but you may find it difficult to find the right balance. This again is where the DB2 Web Query WLE can prove to be helpful, because it does consider the number of concurrent users in its calculations.
466
7214ch12.fm
When the report is run using the Run w/SQL Trace option, the SQL trace information is displayed as HTML output to the browser as shown in Figure 18-23. This trace reveals a couple of interesting points. First, it shows that part of the report cannot be translated to SQL. In this case, translation failed for the Defined field DAYS_DIFF because of an unsuccessful IF/WHERE Test. Second, notice how the trace shows the SQL statement that is generated (and what is ultimately submitted to the database engine). Even though part of the translation failed, the Reporting Server was able to construct a meaningful SQL statement.
Using the trace, you can conclude that the problem with this report is the use of the define field DAYS_DIFF. The line in the trace FOCUS IF/WHERE TEST CANNOT BE PASSED TO
Chapter 18. Performance considerations
467
7214ch12.fm
SQL. DAYS_DIFF indicates that DB2 Web Query attempted (and failed) to generate an equivalent search condition for the SQL statements WHERE clause (Figure 18-24).
Anytime a define field can be passed to the database engine, a more efficient report results, particularly when the define field is part of the selection process, which it is in the case of our example. If the define field cannot be passed to the database engine, then all the rows from the result set of the generated SQL statement are returned to the Reporting Server, which now is responsible for the selection (and sorting if the report is sorted by the define field). This kind of behavior that can negatively impact performance and should be avoided if at all possible. Again, it must be emphasized that the report is more efficient if the entire database access portion of the report definition can be pushed down to the database engine for processing.
7214ch12.fm
DAYS('1998-01-31') - DAYS(T1.SHIPDATE) AS DAYS_DIFF To create the new view: 1. From a System i Navigator, open a connection to the System i environment and open a Run SQL Script window. 2. Type the CREATE VIEW statement or use the SQL selection statement that is displayed in the trace as a base for this view definition and make the necessary modifications. Copy and paste the statement into the Run SQL script window and begin making the changes. For the copy and paste method, Figure 18-25 shows more details about what to add and remove from the selection statement to form the CREATE VIEW statement.
Notice that the local selection is removed from the CREATE VIEW statement. This is added to the statement that references the view. Also observe that the ORDER BY clause is removed. This is because views cannot be ordered. Ordering is specified in the report definition. After all the necessary modifications are made, Example 18-5 shows how the CREATE VIEW statement should look.
Example 18-5 Create SQL view
469
7214ch12.fm
FROM STAR1G.ITEM_FACT T1, STAR1G.CUST_DIM T2,STAR1G.TIME_DIM T3 WHERE (T2."CUSTKEY" = T1."CUSTKEY") AND (T3."DATEKEY" = T1."SHIPDATE") 3. Execute the statement to create the view. 4. From the browser, open the DB2 Web Query metadata window and create a synonym against the new view.
3. Continue creating the new report with the view, specifying the same field format and selection criteria fields (as the original report). Examples are shown in Figure 18-27 on page 471 and Figure 18-28 on page 472.
470
7214ch12.fm
471
7214ch12.fm
4. Save the report and click Quit. 5. Run the new report. 6. Record performance measurements. In the case of this example, significant improvements in performance are observed. In fact, simple benchmark measurements reveal that the report, using the view, runs over 10 times faster than the original version of the report. This is not meant to imply that you will experience the same improvements if you conduct such a tuning exercise. It is only intended to serve as an example of the kinds of efficiencies that you can obtain. Many factors can affect report performance, so your results might vary.
7214ch12.fm
Visual Explain Visual Explain provides a graphical representation of the optimizer implementation of a query request. The query request is broken into individual components with icons that represent each unique component. Visual Explain also includes information about the database objects that are considered and chosen by the query optimizer. Visual Explains detailed representation of the query implementation makes it easier to understand where the greatest cost is incurred. Index Advisor Introduced in V5R4, this feature provides an easy and quick interface to index advisories that are issued by the optimizer. If the optimizer determines that a permanent index against a reference table might be beneficial, it returns the key columns necessary to create the suggested index. The data of the system-wide Index Advisor is placed into the SYSIXADV table in the QSYS2 schema. Database monitor The Database Performance Monitor is a set of integrated tools that is used to collect database-specific performance information for all SQL requests. It can be thought of as an SQL tracing facility, one that tracks all SQL statements, access plans used to implement the statements, resources used, and subsequent performance results. All this information is stored in a database tables, where it can be analyzed and used to identify and tune performance problem areas. Materialized query tables As mentioned previously, an MQT is a DB2 table that contains the results of a query, along with the querys definition. Because the selection, joining, and aggregation have already been performed and the results stored in the MQT, great efficiencies can be gained if the optimizer uses this table for implementation. Index Only Access The database optimizer can use Index Only Access if all of the columns specified in the SQL statement are represented in the index as key columns. Because all of the columns that are necessary to satisfy the request are present in the index, the database engine does not have to perform random access to the table to retrieve this data. The elimination of this additional I/O operation can result in significant improvements in query response times. Database performance analysis and tuning are rather broad topics that are briefly discussed in 18.4, DB2 for i optimization on page 451. For a more extensive discussion about this subject, refer to OnDemand SQL Performance Analysis Simplified on DB2 for i5/OS in V5R4, SG24-7326. For this exercise, feedback from the optimizer (obtained by locating the statement in the SQE plan cache and launching Visual Explain) suggests the creation of the indexes shown in Example 18-6.
Example 18-6 Indexes created for the case study
CREATE INDEX STAR1G.CUST_DIM_CUSTKEY_CUSTOMER ON STAR1G.CUST_DIM ( CUSTKEY ASC , CUSTOMER ASC ) PAGESIZE( 64 ) ; CREATE ENCODED VECTOR INDEX STAR1G.ITEM_FACT_CUSTKEY_EVI ON STAR1G.ITEM_FACT ( CUSTKEY ASC ) WITH 65355 DISTINCT VALUES ; CREATE INDEX STAR1G.ITEM_FACT_CUSTKEY_SHIPDATE
Chapter 18. Performance considerations
473
7214ch12.fm
ON STAR1G.ITEM_FACT ( CUSTKEY ASC , SHIPDATE ASC ) PAGESIZE( 64 ) ; CREATE ENCODED VECTOR INDEX STAR1G.ITEM_FACT_SHIPDATE_EVI ON STAR1G.ITEM_FACT ( SHIPDATE ASC ) WITH 65355 DISTINCT VALUES ; CREATE INDEX STAR1G.TIME_DIM_YEAR_MONTH ON STAR1G.TIME_DIM ( "YEAR" ASC , "MONTH" ASC ) PAGESIZE( 64 ) ; These indexes are created and the report is run again. Simple benchmark testing reveals modest improvements to the runtime after these indexes are created.
18.6.1 Objectives
The benchmark had the following objectives: Measure the overhead and resource usage of using DB2 Web Query product to execute existing Query/400 reports Measure the overhead and resource usage of running DB2 Web Query reports versus equivalent SQL statements
18.6.2 Scenarios
The benchmark test bucket included six scenarios, each with a set of eight different queries or statements. Each query was run with ten different sets of host variable values to measure variances in selectivity and cardinality. We measured the following scenarios of queries: Query/400 *QRYDFN objects (using the i5/OS RUNQRY command) DB2 Web Query running the *QRYDFN objects Direct SQL statements DB2 Web Query reports using the DB2 CLI adapter Direct SQL statements with all full open and re-optimization DB2 Web Query reports using the DB2 CLI adapter with all full open and re-optimization For each measurement, we captured the following data: Total execution time for a given number of loops of the executed queries and reports Performance monitor data Task-profile trace, also known as TRPOF This is a sample-based trace that queries the processor, at user-defined intervals, to gather data on what is currently running on the processor (or processors).
474
7214ch12.fm
18.6.4 Metrics
The measurement data was summarized into four key metrics: Minimum average response time per query Maximum throughput CPU usage Memory usage
Figure 18-29 shows that there is a moderate response time increase for *QRYDFN objects that are run through DB2 Web Query compared to *QRYDFN run through Query/400. Some response time increase is expected when running from a remote client. As expected, the direct SQL statements have the fastest response time. The response time of the DB2 Web Query reports, although longer than the direct SQL statements, is significantly faster than the response time of the *QRYDFN objects. This is primarily due to the efficiencies of the SQL generated by the DB2 Web Query running through SQE. With all queries incur full open and optimization, more like ad hoc queries, the DB2 Web Query response time is only slightly increased. This is the case due to server jobs being recycled after each DB2 Web Query
475
7214ch12.fm
report. The extra overhead of more full opens is incurred in the base DB2 Web Query response time numbers as well.
Maximum throughput
The objective of measuring maximum throughput is to show the maximum number of queries per second that ran before reaching a system bottleneck, such as processor or disk utilization. See Figure 18-30. This limit is measured by increasing the number of users who are running queries until no additional throughput is gained.
The maximum throughput for *QRYDFN objects that run through the Web Query interface is almost equivalent to the maximum throughput of running the *QRYDFN objects through Query/400. As expected, the executed SQL statements have the greatest throughput. DB2 Web Query introduces additional overhead compared to SQL. However the maximum throughput for the DB2 Web Query reports is much greater than the throughput of the DB2 Web Query *QRYDFN runs. This is due to the efficiencies of the SQL generated by the Web Query product running through SQE. With all queries incurring full open and optimization, more like ad hoc queries, the Web Query maximum throughput is only reduced slightly. This is the case due to server jobs being recycled after each Web Query report. Therefore, the extra overhead of more full opens incurs in the base Web Query throughput numbers as well.
476
7214ch12.fm
Figure 18-32 shows a small increase in CPU resource used when *QRYDFN objects are run through the Web Query interface compared to the CPU used by *QRYDFN objects run through Query/400. The chart also shows the dramatic reduction in CPU used by Web Query reports and SQL compared to the *QRYDFN objects. This is due to the efficiencies of SQL running in SQE. The Web Query reports use more CPU than the equivalent plain SQL.
477
7214ch12.fm
Figure 18-33 lists the data used in the graphs in this section.
18.6.5 Conclusions
We used the results of the benchmark to derive the following conclusions: Comparisons of the DB2 Web Query *QRYDFN versus the Query/400 *QRYDFN show an increased response time. This result is expected when running to a client application as is the case with DB2 Web Query. The server CPU used is 9% more, and more memory is required. Comparisons of DB2 Web Query (using DB2 CLI adapter) reports to Query/400 *QRYDFN are positive. Even with running to a client, the DB2 Web Query reports run faster, use less much less CPU, and require about the same amount of memory. This can primarily be attributed to the DB2 CLI adapter generating SQL and using the new SQL Query Engine (SQE). Comparisons of Web Query to SQL show that DB2 Web Query has longer response times, which again is expected when running to a client, and uses more resources. The CPU used by Web Query is two to four times the CPU used when running SQL, depending on whether the full open re-optimization was forced every time. Note that Web Query recycles the server jobs for every query. If you are using DB2 Web Query to modernize Query/400 queries (by creating new reports), there is little additional overhead. If you are creating new reports, always keep in mind that SQL is being generated. Therefore, an understanding of SQL performance basics is vital.
478
7214ch13.fm
19
Chapter 19.
479
7214ch13.fm
We are happy with our Query/400 reports. Is there any reason to move to this new product?
There are several reasons why you might want to consider using this new technology: Query/400 does not leverage the latest query optimization technology in DB2 for i5/OS, which is called SQL Query Engine (SQE)). DB2 Web Query offers the ability for the queries to use the query optimization features that have been added to DB2 for i5/OS over
480
7214ch13.fm
the last few years. DB2 Web Query leverages the improved performance, automation, and monitoring capabilities of SQE. The parameterized reporting feature of this new product can substantially reduce the number of reports that must be maintained individually, reducing the backlog of report writing requests. Todays requests for information demand that the data be delivered in many different formats and on a request, scheduled, or alert basis. Information must be provided via easy to interpret graphical representations, dashboards, or scorecards or dumped into spreadsheets. Query/400 is limited in its ability to meet these demands.
Why a Web-based query and report writing function? Is a Windows-based solution not more robust?
The product is based on the latest Web 2.0 and AJAX Web technologies. It allows you the functionality and usability that is usually associated with a Windows environment, but is now available to browser-based applications. The zero footprint solution reduces complexity and costs. It also allows any enterprise browser to be leveraged as the user interface. The AJAX framework allows sophisticated report building capabilities including modeless and modal dialogs, menus, multiple coordinated windows, partial panel updates, and more. A Web-based solution offers the following benefits: Lower installation costs Lower maintenance costs Easy, incremental upgrades to existing applications User administration savings Simpler and more controlled document backup and archiving Simpler and more controlled security and compliance administration Software updates controlled on the server making them available to all users concurrently
481
7214ch13.fm
built-in analytical processing to the product's robust and scalable enterprise reporting and information delivery capabilities. Note: In order to leverage the OLAP functionality, metadata that defines data relationships is required. This metadata is created with Developer Workbench. Therefore, we recommend that either you have a license of Developer Workbench or another mechanism, such as an ISV-supplied metadata layer, provides the metadata. Developer Workbench The DB2 Web Query Developer Workbench feature is an open and intuitive environment that allows for rapid development of more customized Web-based reports. It includes an HTML Composer for building compound reports or dashboards, combining multiple reports onto a single view. The Developer Workbenchs synonym editor is used for building metadata to hide complexities of the data from end users, such as decomposing date fields, applying preand post-calculation rules, or any of the hundreds of data manipulation functions. You can use the metadata interface to define relationships in the data, such as defining the hierarchy of dimensions that automates the drill-down function of the OLAP feature. Run Time User Enablement This option provides an alternative way to grant DB2 Web Query access for run time users (those that only run reports and perform no report development activities). With the base licensing model, each of these types of users must be explicitely registered to DB2 Web Query. This means that each one consumes a user license. With Run Time User Enablement, you can instead register the group profiles that secure the DB2 Web Query domains. Any run time user that is a member of one of those group profiles can gain access to DB2 Web Query without being explicitely registered. They are simply allowed access through the group profile license (think of it as a family pass). This can greatly reduce the number of user licenses that are required and provides an attractive option for customers that need to support a large community of users that run reports. This new feature provides a solution that can be more cost effective and reduce maintenance DB2 Web Query Adapter for Microsoft SQL Server With this adapter you can extend the reach of DB2 Web Query with access to Microsoft SQL Server 2000 or 2005 databases. Prior to the availability of this adapter, the only supported DB2 Web Query data source was the IBM DB2 for i database. You can access multiple instances of SQL Server with a single DB2 Web Query Adapter and standardize on a single query and reporting solution for the enterprise. DB2 Web Query Spreadsheet Client Although you can create Excel spreadsheet reports with the base DB2 Web Query product, this Excel Spreadsheet plug-in provides another level of integration by allowing you to start within the Excel framework and pull data into a spreadsheet using DB2 Web Query reports. The following features are provided with this plugin: Access your DB2 for i or Microsoft SQL Server data from within Microsoft Excel 2002, or later. Build spreadsheet reports that are automatically refreshed with updated data. Combine multiple reports from various data sources in a single worksheet. Create new queries while working within Excel. Burst data into multiple worksheets within the workbook. Refresh data in a server-based Excel application or template.
482
7214ch13.fm
In addition, the following products are available to extend the base products functionality: DB2 Web Query Report Broker DB2 Web Query Report Broker (5733-QU3) adds a new level of scheduled report distribution, enabling more report consumers to automatically receive reports in the formats they most prefer. Report Broker enhances the number of output options available when reports are run in a batch mode. The GUI-based scheduler makes it easy to automate the report execution, with many options for running recurring reports. Leveraging e-mail distribution lists, the resulting output of the scheduled report can be distributed automatically. And with intelligent bursting, Report Broker lets you run a report once but distribute portions of it to users based on the first sort field in the report. DB2 Web Query Software Developer Kit (SDK) The DB2 Web Query SDK (5733QU4) provides an API like interface to allow application developers to seamlessly integrate DB2 Web Query content into other applications.
Is there any integration with the Rational tools with this product?
No, there is no IBM WebSphere or Rational integration.
Do I need to download data to a PC server or install a Windows server to sit between the client and the System i server?
Many enterprise reporting tools on the market force you to move your data out of DB2, or require multiple servers to support various reporting functions. The IBM product is an i5/OS and thin client implementation, which simplifies the whole reporting infrastructure for System i customers. Software upgrades are simplified, reliability can be increased, network traffic is reduced, and security and auditing can be simplified.
Is there a DB2 Web Query community where questions can be answered and ideas shared?
Yes, there is. IBM hosts a developerWorks site for DB2 Web Query. The URL is: http://www.ibm.com/developerworks/spaces/DB2WebQuery This website has things like an FAQ, links to the KnowledgeBase (where many tips and techniques are documented), links to manuals. It also has a forum where you can post questions. It is not intended to be a support site, just a place you can come to get and share ideas.
I have several ideas on how DB2 Web Query could be improved. How do I submit a new request for product enhancement?
There a couple of ways to submit New Feature Requests: Go to the following website for IBM i design change requests: https://www-912.ibm.com/r_dir/ReqDesChange.nsf/Request_for_Design_Change?OpenFo rm Post a thread on the developerWorks forum website mentioned previously.
483
7214ch13.fm
When I access the DB2 Web Query web console, I only see a limited number of options. What happened to the other options?
If you sign into the DB2 Web Query web console (http://systemname:11331/webquery_html/wfconsole.htm) and only see limited configuration options, you are probably not signed in as the user profile QWEBQRYADM. Only this profile is able to see and use all of the web console configuration options
Is the server-based processing performed by the WebSphere Application Server or something that requires less overhead?
A lighter weight integrated application serving environment is used, one with more specific and limited functionality. The product does not require any WebSphere Application Server instances to be running.
484
7214ch13.fm
Given that this is browser-based access, how is security established for users?
First, users must log into DB2 Web Query using their i5/OS user profiles and passwords. If that user has been registered as a named user, access is allowed to the DB2 Web Query launch page. From the launch page, a user is allowed to work with reports within a DB2 Web Query domain. Each domain is associated with two group profiles: one for report developers and one for report users. User profiles are then added to the appropriate group profile. If a user profile is a member of the report developer group profile associated with the domain, that user can create, edit, and run reports within that domain. Similarly, user profiles that are members of the report user group profile can (only) run all reports within the associated domain. The developer class named users are members of a group user profile name prefixed by MD, and user class named users are members of a group user profile name that is prefixed by MU. For example, if your domain is named SALESREP, the developer group profile is named MDSALESREP, and the user level group profile is MUSALESREP. In addition, when the report is executing, normal i5/OS object-level security is enforced. Therefore, if the user who running the query does not have the appropriate authority to the underlying database object, the query execution fails accordingly.
My user profiles are already members of a group profile. Since this user profile parameter (GRPPRF) is already specified, how can domain authority be established?
Use the Supplemental Group (SUPGRPPRF) parameter of the CRTUSRPRF/CHGUSRPRF command. This parameter accepts multiple values and can also be used to establish the association of a user with a domain.
Can a more granular level of security be established, for example, to limit a report for a specific user?
From the perspective of which reports are displayed to the user on the DB2 Web Query launch page, the answer is No. Domain level is the lowest level of security and determines which reports are displayed to a particular user. However, object-level security that is implemented in the IBM i environment is honored. This means that users might see a report. However, if they are not authorized to the underlying database objects used by the report, the report execution will fail.
485
7214ch13.fm
If there is a known join relationship that is not defined to the database using DB2 for i5/OS referential integrity features, is there a way to define such a relationship in the metadata?
Yes, you can do this by creating synonyms from the Developer Workbench toolset. Refer to 12.1.4, Joining tables on page 354, which provides an example of how to define this relationship. Alternatively, to define the relationship, you can create SQL VIEWs, add the referential integrity definitions at the database level, or manually add the Join specifications for the reporting.
Is there a way to automate the generation or refreshing of the metadata, for example by using an API?
No, there is neither metadata automation nor an API to build or rebuild the metadata. It must be done manually. Therefore, if you already have metadata against a table in place, and that table has been altered (for example, new columns have been added), you must manually refresh the tables metadata before the new columns can be used in your reports. IBM and Information Builders are investigating ways that might help you keep your metadata in synch with the tables that it is based on. The DB2 Web Query Developer Workbench tool does have an option to Refresh the metadata. This will update the synonym by adding any new columns (added to the underlying table) and removing columns (deleted from the table). Any customization made to the synonym (virtual columns, OLAP dimensions, etc) will be preserved during this process.
486
7214ch13.fm
WRKLNK command From this interface, you can only delete existing synonyms. Developer Workbench From the Developer Workbench client, you can do much more than simply deleting the synonyms. By right-clicking the selected synonym, you see the list of available options as shown in Figure 19-1.
The following options are some of the more useful options that are available through this interface: Synonym Editor The Synonym Editor provides exclusive features such as: The ability to decompose date fields. An interface for defining filters, virtual fields, and business views. The ability to define appropriate dimensions for the OLAP module.
Refresh Synonyms Refreshing a synonym enables you to update field information while preserving the original synonym title, description, usage, virtual field, and database administrator (DBA) information. The action also synchronizes the Master File with the table on which the synonym is based. Domain-level report movement Use the drag features to move your domains from one system to another.
Within my reports, how can I simulate a library list-like behavior when accessing the base tables and views?
During the report development and testing phases, you might prefer to create your reports against tables or views in a test library, verify that the reports are correct, and then at some
Chapter 19. Frequently Asked Questions
487
7214ch13.fm
point, change the report to point to data in a different (perhaps production) library. Typically, this is implemented easily from many System i interfaces by using and manipulating your library list. However, by default, your synonym is based on a table or view that is selected from a specific library; therefore, the library list behavior does not occur. Creating separate versions of the report for each data library is one approach to consider, but is likely not desirable or practical if you have many reports to create and maintain. To obtain the library list behavior and avoid creating a separate report for each data library, you must select the One part name synonym setting as shown in Figure 19-2.
Specifying one part name for the synonym prevents DB2 Web Query from hard coding the library name in the meta data. When the report (based on a one part name synonym) is run, the requesting users library list is searched for the table or view names on which the synonym is based. This means that you must either log in as a different user profile in order to have the report access data in a different library, or use an easier technique to change the library list of the job description that is defined to the user profile. As long as the formats of the files in the different libraries are the same, this method is possible to carry out. For more information on this subject, see the following articles: Making Better Use of DB2 Web Query with *LIBL http://www.mcpressonline.com/database/db2/making-better-use-of-db2-web-query-wi th-libl.html TechTip: Simulate One-Part Names for DB2 Web Query Synonyms over Stored Procedures http://www.mcpressonline.com/tips-techniques/database/techtip-simulate-one-part -names-for-db2-web-query-synonyms-over-stored-procedures.html
488
7214ch13.fm
Note: From a DB2 Web Query perspective, the users library list is determined and controlled by the system values QSYSLIBL and QUSRLIBL as well as the job description that is defined for the user profile. Any other method of setting the library list is not recognized by DB2 Web Query. For example, if you are using the initial program (specified in the user profile) to manipulate the library list when the user signs on, this method will fail because the initial program is not executed during the DB2 Web Query session.
Can I query DB2 for i databases, either on another partition or in another server, without requiring multiple licenses of DB2 Web Query on each of these partitions or servers?
With additional adapters as add-ons to DB2 Web Query, you can build a federated query that combines data from many different back-end databases into a single DB2 Web Query report. You can also combine data from multiple DB2 for i5/OS databases running on different servers or logical partitions (LPARs), without requiring any additional adapters since the base product ships with the DB2 for i5/OS adapter. For more information about setting up a cross-system join, see 3.6.2, Setting up a cross-system join on page 72.
Query/400 supported exception joins. How do I specify that type of join with DB2 Web Query?
The DB2 Web Query development tools available through the Web browser interface (Report Assistant, Graph Assistant, and Power Painter) do not support the specification of left
489
7214ch13.fm
exception, right exception, and right outer join types. If you need this functionality in your report, you must take the following steps: 1. Create an SQL view with the appropriate tables and join syntax. Here is an example of creating a view with an exception join: CREATE VIEW century/examplejoin AS ( SELECT a."StoreName", b."LineTotal" from century/stores a LEFT EXCEPTION JOIN century/orders b ON a."StoreCode" = b."StoreCode") Here is an example of creating a view with a right outer join: CREATE VIEW century/examplejoin AS ( SELECT a."StoreName", b."LineTotal" from century/stores a RIGHT OUTER JOIN century/orders b ON a."StoreCode" = b."StoreCode") 2. Create a synonym against that view. 3. Base your report on the synonym of the view.
Will the imported Query/400 definition start using SQL, so that the SQL Query Engine versus the Classic Query Engine will be used?
No. The reports based on Query Definition objects are generated from the metadata that is available from the query object itself and will continue to be run using the RUNQRY which uses the Classic Query Engine (CQE). A new Web Query should be created to replace an existing query, to enable an SQL interface to the data. This is the only way to have the query processed by the SQE.
Will a Query/400 object that was previously imported still function as an imported report, even after the original query definition has been changed?
Yes, the object will still function as an imported report as long as the definition of the original Query/400 object is not changed to remove fields or existing fields are changed to an incompatible type with those in the existing metadata.
Can an imported Query/400 query be saved with removal of reference to the existing query; effectively creating an actual Web Query report from the imported query?
No. To fully detach the reference to the original query definition, a new DB2 Web Query report must be created without reference to metadata from a query definition object.
Some Query/400 definitions are scripted in a CL program, so that one query produces output that will be used by the next query for input. Will that be possible with DB2 Web Query?
You can accomplish the same thing, but use of the QTEMP library might be an inhibitor. The browser initiated work runs in the QSQSRVR jobs, and there is no assurance that the QTEMP for one query will be the same as for the next query. A permanent library must be specified.
7214ch13.fm
I have my own style sheets that I want to use for my reports. How do I make them available from Report Assistant?
In Report Assistant, on the Reporting options tab, you can specify a style sheet under the Apply an existing WebFocus Stylesheet field. To add your own style sheets to this list: 1. Copy your stylesheet files to the integrated file system directory \QIBM\UserData\webquery\ibi\webfocus76\basedir\import. After they are in that directory, they are available to every domain for importing. 2. To import, open the desired domain, right-click the Other Files folder, and select Import. 3. In the Select Files to Add dialog window that opens, from the list of style sheets, select the stylesheet files and click Save. The style sheets are now available from Report Assistant. Tip: Many sample style sheets are provided as part of the base product and can be used in your reports. They have the file extension .STY and can be found in the integrated file system directory \QIBM\UserData\webquery\ibi\webfocus76\template. To make these style sheets available in the Report Assistant interface, copy the .STY files to the directory specified in step 1 above and follow the remaining steps.
Attention: Although custom style sheets should work in DB2 Web Query, IBM Support does not provide assistance if you should experience problems.
How can I limit the number of rows that are retrieved during the report development phase?
If you are developing reports that are retrieving large numbers of rows from the database, you might find it useful to restrict the number of rows that are returned and avoid waiting for all this information to be returned to the client. To obtain this behavior: 1. Open the report. 2. Select Report options tab. 3. As shown in Figure 19-3 on page 492, in the Content and generation pane, specify the number of records that you want retrieved. 4. Click Save. Important: Do not forget to remove this setting prior to moving your report into production. Failure to do so results in a report that does not retrieve all of the rows that satisfy the selection criteria of the report.
491
7214ch13.fm
Can DB2 Web Query handle stored procedures with input parameters?
Yes, DB2 allows your stored procedures to have input parameters. However, you must specify a value for the input parameter during the synonym creation process. Although it must be specified here, this value is not stored with the synonym definition and is not passed to the procedure during execution. When creating the report against the stored procedure, you see the input parameter listed in the list of available fields. From the Selection criteria tab, select this field as shown in Figure 19-4 on page 493.
492
7214ch13.fm
If you want the input parameter that is passed from the report to the stored procedure to be selected from a list, you must specify a different source synonym than the stored procedure. For more information on using stored procedures as synonyms, see the following article: TechTip: Use a Stored Procedure as Your Data Source in DB2 Web Query for i (http://www.mcpressonline.com/tips-techniques/database/techtip-use-a-stored-proced ure-as-your-data-source-in-db2-web-query-for-i.html)
How can the SQL that is produced for the report be viewed?
You can view the SQL by using the Run w/SQL option. This option sends the SQL statement generated by DB2 Web Query to the browser. In addition, the i5/OS database features in iSeries Navigator, such as the SQE Plan cache and Database Monitor, can be used to determine which SQL statement was produced and submitted to the database engine.
In parameterized reports, can more than one item be selected from the list?
Yes, more than one item can be selected as long as the parameter was defined to allow multiple selections. By using the standard Windows selection method, press Ctrl and click to add or remove a selected entry.
493
7214ch13.fm
Can I drill down to different reports based on the value of the column?
Yes, this is called conditional drill-down. For example, lets say you have a parent report that shows the columns Country and Revenue (as a percentage of total). If the user drills down on the United States, you would like to show a detail report showing the columns Region and 494
Getting Started with DB2 Web Query for i
7214ch13.fm
Revenue as US dollars. If the user drills down on Germany (or any other European country), you would like to show a detail report with Region and Revenue as Euro dollars. To set this up, you would create two separate detail reports - one that shows currency as US dollars and the other as Euro dollars (to learn how to do this see Can the currency symbol be set at the report level? on page 494 above). In the parent report, set up Conditional Styling on the Country column, add conditions to check for Country EQ United States and Country NE United States, attach them, and define drill downs for each of these conditions. Each drill down would execute the appropriate detail report (procedure). This overall design is shown in Figure 19-6.
495
7214ch13.fm
When building a dashboard, can graphics be included, for example a company logo?
Yes, you can include graphics when building a dashboard by using the HTML Composer tool (part of Developer Workbench) or Power Painter. The dashboard is a Web page, which can have a large variety of elements placed for viewing.
UNTITLED
WP QPRINT *CURRENT
In order to run a report using this command, you must specify the appropriate domain and folder HREFs of the desired report. To obtain this information: 1. Open a DB2 Web Query session using your Web browser. 2. Expand the tree until you see the report. Right-click the domain that contains the report and select Properties. 3. In the Properties window that opens, you see the Href value, which you specify in the DOMAIN parameter of the RUNWEBQRY command. For example, let us assume that you see the following value: db2wbqry/db2wbqry.htm In this case, you specify the value db2wbqry in the DOMAIN parameter. 4. Right-click the folder that contains the report and select Properties. 5. In the Properties window, you see the Href value. This is the value that you specify in the FOLDER parameter of the RUNWEBQRY command. If the Href has a leading number (#)
496
7214ch13.fm
character, do not include this in the parameter value. For example, let us assume that you see the following value: #visiblea56gb In this case, you specify the value visiblea56gb in the FOLDER parameter. 6. Right-click the report and select Properties. You see the Filename value in the displayed Properties window, for example: app/newReport.fex Excluding the leading app/ and trailing .fex characters, this is the value that you specify in the REPORT (FEX) NAME parameter of the RUNWEBQRY command. Therefore, in the case of the above example, the value specified is newReport. Putting it all together and using the example values that we provided, your command looks like the example shown in Figure 19-8. RUN JAVA BATCH IN WEBQUERY (RUNWEBQRY) Type choices, press Enter. DOMAIN NAME, OR HREF . . . . . . > db2wbqry FOLDER NAME, OR HREF . . . . . . > visiblea56gb REPORT (FEX) NAME . . . . . . . > newReport OUTPUT FORMAT . . . . . . . . . OUTPUT QUEUE . . . . . . . . . . RUN WITH USER ID . . . . . . . . WP QPRINT *CURRENT Character value Character value
When I prompt (F4) the RUNWEBQRY command, I do not see Database file as an option for output format. I thought this was one of the supported output formats.
The RUNWEBQRY CL command does support output to a database file. This output option must be defined in the report itself. If you have Database file specified in the DB2 Web Query report definition, this setting is always honored in the RUNWEBQRY command, even if you specify a target output queue in the commands OUTQ parameter. Any other output format specified in the report definition results in the report output being sent to a spooled file when the CL command is invoked.
Do I have to be registered as a named user before I can use the RUNWEBQRY command?
Yes, use of the RUNWEBQRY command requires the submitting user to be registered as a DB2 Web Query named user. However, if you are not a named user and you have sufficient authority to submit a job on behalf of another user profile, you can specify a valid named user in the USER parameter of the RUNWEBQRY command. When you do this, the batch jobs submitted for this request run under the user profile that you specified. If this user profile is a valid DB2 Web Query named user, the request is allowed to continue.
497
7214ch13.fm
percentage of total. In these cases, you can use an SQL view or the SQL wizard to create a report with these requirements.
When a report is generated to HTML, I am having a dickens of a time getting my reports to print with the proper formatting and page breaks. Are there options to control the formatting when printing an HTML report?
HTML is the suggested output format when you want to display the results interactively in a web browser. It is really not a good option when you want to print reports. The recommended output format for printing is PDF. With PDF you can control the formatting and get the page breaks you are looking for.
I am generating reports to PDF output. The columns in the PDF document are too wide (there is much unused white space) and as a result, the columns are wrapped and shown on the next page. Is there any way to condense the report so that all columns are displayed on a single page?
Yes, you can squeeze the columns together and eliminate the unused white space by using a style sheet that contains the statement SQUEEZE=ON. You may also want to include the following statement so that the report is printed in landscape mode: ORIENTATION=LANDSCAPE Example 19-1shows an example of using these statements at the top of a style sheet.
Example 19-1 Stylesheet with statements to improve PDF output
UNITS=IN, PAGESIZE='Letter', LEFTMARGIN=0.500000, RIGHTMARGIN=0.500000, TOPMARGIN=0.500000, BOTTOMMARGIN=0.500000, SQUEEZE=ON, ORIENTATION=LANDSCAPE, PAGECOLOR='WHITE', $ TYPE=REPORT, BORDER=1, FONT='ARIAL',
498
7214ch13.fm
On the top of eachtotal numberreport, I would like to include thespecify page number and page of my of pages in the report. How do I curent this?
This can be done by specifying the system variables TABPAGENO and TABLASTPAGE in the page header or page footer sections of the report. These variables are described below: TABPAGENO Displays the current page number(s) in text. Overrides the default page number position of top left corner. TABLASTPAGE Displays the last page number of the report in the heading (or footing) text. For example, you would specify this in the page header section of the report: Page <TABPAGENO of <TABLASTPAGE Note: Both variables must be preceded by the < character.
How do I open my Excel spreadsheet reports in Microsoft Excel instead of the Web browser?
By default, whenever you open a report whose output format is defined as an Excel spreadsheet, your browser attempts to open the XLS file in the same browser session (using an XLS plug-in). If you prefer to have the spreadsheet opened in Excel: 1. Open Windows Explorer. 2. Select Tools Folder Options. 3. Select the File Types tab (Figure 19-9 on page 500). On this tab, complete these steps: a. In the Registered file types list, find and select XLS (Microsoft Excel Worksheet). b. Click the Advanced button.
499
7214ch13.fm
c. In the Edit File Type window (Figure 19-10), make sure the Confirm open after download and Browse in same window options are not selected. Click OK.
d. In the Folder Options window, click Close. 4. Close the Windows Explorer window and try again. Attention: Be aware that when you configure your browser to behave this way when opening an Excel spreadsheet, you reports lose the ability to drill down to other reports.
500
7214ch13.fm
I have created a report with output to an Excel spreadsheet. Does drill down (clicking an active link) access another spreadsheet?
Yes, drill down accesses another spreadsheet, but only if the spreadsheet is opened in the browser window. The drill down is active while in a browser, using an Excel plug-in to place the data from the referenced report in the browser window.
One of the report output options is Excel with formulas. What does that really mean?
Calculations and summaries are output to the Excel spreadsheet as formulas instead of literal values. This way the recipient of that spreadsheet can do row or column manipulations, for example delete a row, and the results of cells with formulas are automatically recalculated and updated.
Does DB2 Web Query support integration with Microsoft Excel 2007?
Yes, Excel 2007 is supported.
What versions of Microsoft Excel will support the DB2 Web Query Spreadsheet client?
You can use the DB2 Web Query spreadsheet client within Microsoft Excel 2002, or later.
I am using Windows Vista and can not get drill-downs to work in my Excel Spreadsheet output. It seems that Internet Explorer launches the spreadsheet outside of the browser. This worked prior to Vista - is it no longer supported?
This happens in both Vista (OS Level Change) and Office 2007 (Office Product Change). Unfortunately, neither will allow the embedded viewing any more. Hence the session cookie in iexplore.exe does not work for the full msexcel.exe product.
The OLAP feature is enabled by defining dimensions for the database. How does DB2 Web Query get those dimensions?
The dimensions must be defined in advance using the Developer Workbench.
When cascading through data in an OLAP report, is the data limited based on prior selections?
Yes. For example, specifying country as United States limits the States/Provinces list to only the states in the United States, so that no data associated with Canada is available to cascade in the list.
In an OLAP report, can the columns be sorted on demand (as they can be in Active Reports?)
Yes, you can re-sort the report, based on any of the displayed columns.
501
7214ch13.fm
Does a copy of the Developer Workbench come with the base product?
No. The Developer Workbench is a feature of the IBM product, but is not part of the base product.
Can an Active Report be saved with the active visualizations and any other changes made by the user?
Yes. The Active Report file can be saved with the current formatting and visualizations specified by the user.
I understand that Active Reports can be sent to others via e-mail. In order to run the report, do the e-mail recipients have to be named users as well?
No. Only the user that originally ran the report and generated the Active HTML output needs to be a named user. After the Active HTML output file is created, it can be distributed to an unlimited number of recipients, none of which have to be named users (or even connected to the System i environment). The recipients open the HTML file using a browser and can work with the Active Report in the same way as the original (named) user that created the HTML output can.
How can I execute reports in batch and distribute automatically in PDF form via an e-mail distribution list?
The DB2 Web Query Report Broker product (5733QU3) provides thie capability. With Report Broker, you can set up schedules to run your reports in a batch mode during off-shift hours (when more system resouces are available). You can distribute reports via email or printer or you can have the report output saved to a folder in the reports domain. You can also specify the report output format you want generated and distributed. For more information on DB2 Web Query Report Broker, refer to Chapter 15, Report Broker on page 393.
Can a report developer create reports based on manually entered or imported SQL statements?
Yes, the SQL wizard feature of Developer Workbench provides an interface from which report developers can manually enter or copy and paste SQL statements, as well as point to SQL script files that exist on the integrated file system. As long as these SQL statements contain valid SELECT statements, they can be used as the basis for DB2 Web Query reports.
Why am I having trouble saving my Active Reports so that I can redistribute them?
First of all, you must be using a browser that supports ActiveX technology. This means that only Internet Explorer can be used if you want to save your Active Reports to your hard drive. Firefox has no native ActiveX capability, and consequently, cannot save the HTML file. Second, you must make sure that your Internet Explorer browser settings are configured to enable ActiveX for Internet Explorer (version 6.x and 7.0). To set this up correctly: 1. In the browser, from the menu bar, select Tools Internet Options.
502
7214ch13.fm
2. In the Internet Options window, click the Security tab. 3. On the Security tab, click the Custom Level button. 4. In the Security Settings window, scroll through the menu and Select the Enable radio button for the following menu choices: Run ActiveX Controls and Plugins Script ActiveX Controls Marked Safe for Scripting Initialize and Script ActiveX Controls not Marked as Safe for Scripting 5. Click OK to exit and save. 6. Click OK again to exit the Internet Options window. 7. Close and re-open the browser. Active X is now enabled and you can save your Active Reports.
Does Active Reports allow you to sort on more than one column?
Yes, but it is a multi-step process. If you take an action to sort by a column and that column has duplicate values, Active Reports will sort those values by the previously selected sort. Each sort action will honor the previous sort specification to resolve the ordering of duplicate values. In Figure 19-11, the user first selected to sort by Revenue in descending order. The user then sorted by Model in ascending order, followed by Product Category in ascending order. Notice that the rows with the same Product Category value (such as Organizers) are sorted first in ascending order by Model and those with the same Model (VO-800) are ordered in descending order by Revenue.
503
7214ch13.fm
If I add Comments to an Active Report, will they be there the next time I run that report?
No. When you run a report that goes to AHTML (Active Report) output format, DB2 Web Query generates an HTML file. When you display that HTML file in the browser and add comments, the comments are added to that HTML file - they are not stored anywhere on the IBM i server. You can save that HTML file or even E-mail it and it will still have the comments. But when you rerun the report, a brand new HTML file is generated and the comments do not appear in this new version of the report (but they do still exist in the original HTML file that you saved/emailed).
I have important business information scattered about various columns in my DB2 for i database as well as PDF documents and Excel spreadsheets. I would like to be able to perform full text-searching over these data sources for relevant information. For example, I would like to find all PDF documents and spreadsheets that contain the search string 2007 Financial Reports. Does DB2 Web Query provide any full text-search capabilities? If so can it search these data sources?
DB2 Web Query does not have built-in full text search capabilities, however, it can be easily integrated with the IBM OmniFind for DB2 for i product (5733OMF) to provide the features you are looking for. Here are some links with more information about OmniFind and DB2 Web Query integration: Exploring the IBM OmniFind Text Search Server http://www.ibm.com/partnerworld/wps/servlet/ContentHandler/whitepaper/i/omnifin d/search OmniFind, Part I: Add Sizzle to Your SQL with OmniFind Text Search Server for DB2 for i http://www.mcpressonline.com/database/db2/omnifind-part-i-add-sizzle-to-your-sq l-with-omnifind-text-search-server-for-db2-for-i.html OmniFind, Part II: Integrating OmniFind Text Search Server with DB2 Web Query http://www.mcpressonline.com/database/db2/omnifind-part-ii-integrating-omnifind -text-search-server-with-db2-web-query.html
What is the recommended save and restore process for DB2 Web Query?
From a save and restore perspective, you must be concerned about the following components of DB2 Web Query: Synonyms (also referred to as metadata) All synonyms are stored in the integrated file system directory QIBM\UserData\webquery\ibi\apps. If you find that you are regularly creating or refreshing metadata information, we recommend that you save this directory frequently.
504
7214ch13.fm
For example, to save all metadata into a savefile named SYNONYMS created in the QGPL library, you enter the following command: SAV DEV('/QSYS.LIB/QGPL.LIB/SYNONYMS.FILE') OBJ(('\QIBM\UserData\webquery\ibi\apps' *INCLUDE)) To restore this metadata on the target system, you specify the following command: RST DEV('/QSYS.LIB/QGPL.LIB/SYNONYMS.FILE') OBJ(('QIBM\UserData\webquery\ibi\apps' *INCLUDE 'QIBM\UserData\webquery\ibi\apps')) ALWOBJDIF(*ALL) Reports (also referred to as Focus Execs, FOCEXECs, and FEXs) All reports are stored in the integrated file system directory QIBM\UserData\webquery\ibi\webfocus76\basedir\domain_name (where domain_name equals the name of the domain in which the report was created). To save all reports (distributed throughout the various domains), save the directory QIBM\UserData\webquery\ibi\webfocus76\basedir. For example to save all reports in all domains into a save file named ALLREPORTS created in the QGPL library, you enter the following command: SAV DEV('/QSYS.LIB/QGPL.LIB/ALLREPORTS.FILE') OBJ(('\QIBM\UserData\webquery\ibi\webfocus76\basedir' *INCLUDE)) Similar to the synonyms, we recommend that you save this directory periodically or more frequently if reports are created and updated on a regular basis. To restore all the domains, folders, and reports to the target system, you specify the following command: RST DEV('/QSYS.LIB/QGPL.LIB/ALLREPORTS.FILE') OBJ(('\QIBM\userdata\webquery\ibi\webfocus76\basedir' *INCLUDE '\QIBM\userdata\webquery\ibi\webfocus76\basedir')) ALWOBJDIF(*ALL) Note: If you are looking for the report files in the Common (untitled) Domain, you can find them in the QIBM\UserData\webquery\ibi\webfocus76\basedir\untitled\app directory. If you want to save both synonyms and reports in one step, simply save the directory QIBM\UserData\webquery\ibi as shown in the following example: SAV DEV('/QSYS.LIB/QGPL.LIB/ALLSTUFF.FILE') OBJ(('\QIBM\UserData\webquery\ibi' *INCLUDE))
505
7214ch13.fm
Note: When moving or copying domains to another system, problems might occur if your reports reference (via drill downs, hyperlinks, and so on) other reports or procedures that reside in another domain. In addition, you can use Windows Explorer with mapped network drives to move domains: 1. Manually create the domain on the target system (from DB2 Web Query home page or Developer Workbench). The name of the target domain must match the name of the source domain. Attention: Domain movement does not work from Windows Explorer if you skip step 1. 2. From Windows Explorer, map a network drive for both the source and target systems. 3. From Windows Explorer, drag the source domain directory to the target directory T:\QIBM\userdata\webquery\ibi\webfocus76\basedir (where T is the target mapped network drive letter). 4. In the Confirm Folder Replace window, you see the message This folder already contains a folder named... Click the Yes to All button.
506
7214ch13.fm
highly active forum for Web Query. Use the forum to submit your questions to a wide range of Web Query users and IBM experts. You can access the Web Query Space at: http://www.ibm.com/developerworks/spaces/DB2WebQuery In addition, System i eLearning training is available on the Information Builder Web site at: http://education.informationbuilders.com/edu/Systemi.html Registrants to the training have access to the site for 30 days. Following the 30-day trial, the service is available on an annual subscription basis for a nominal fee.
I have noticed that there are many articles, white papers, best practices, and general tips/techniques published for the DB2 Web Query product. Is there a centralized website that contains links to all of these publications?
Yes, there is! Go to this website: http://www.ibm.com/developerworks/wikis/display/webquery/DB2+Web+Query+for+i+Artic les
507
7214ch13.fm
508
7214p06.fm
Part 6
Part
Appendixes
In this part, we explain more specific topics on DB2 Web Query. This part includes the most frequent asked questions and the following appendixes: Appendix A, Metadata in the integrated file system on page 511 Appendix B, ate and time functionality on page 513 Appendix C, Processing differences between the define and compute fields on page 563 Appendix D, Change Management considerations on page 565 Appendix E, Additional material on page 569
509
7214p06.fm
510
7214ax01.fm
Appendix A.
Master file: This file identifies the fields of the table or, if the object is a QRYDFN, the
fields of that querys result set. The master file has an extention of .mas. The fields are described in terms of length and data type. This file is similar to the information in a DSPFFD file, but the information is described in a way in which DB2 Web Query understands. Figure A-1 shows a master file for table QWQCENT/ORDERS.
511
7214ax01.fm
Access file: This file identifies the object name and type on which the metadata is created. The access file has an extention of .acx. If the object is a QRYDFN, it says QIQRY. If the object type is a table, it says TABLENAME. Figure A-2 shows an access file for table QWQCENT/ORDERS.
The Heritage adapter does not have access files when created over physical files, but does when created over logical files with an access path. For QRYDFN objects, there are three additional metadata files: .fex, .txt and .inf.
Deleting metadata
There is no interface in DB2 Web Query to delete metadata. If you know that there are no more reports based on this object, nor will anymore be written, you can manually delete the metadata. 1. From the System i command line, enter the following command: WRKLNK '/QIBM/USERDATA/IBI/APPS/BASEAPP' 2. Select option 5 by BASEAPP. 3. Browse the BASEAPP directory for the metadata that you want to delete. When you find it, select option 4 and press Enter to delete. If you change the underlying table or QRYDFN, and if you recreate the metadat with the overwrite option, the master file is correctly updated. A new master file is not created. Therefore, you do not need to manually delete any metadata if you only used the overwrite option.
512
7214ax02.fm
Appendix B.
513
7214ax02.fm
Date format
The various date formats enable you to define a field as a date and work with it as a date. Using the date format, you can perform the following tasks: Define date components, such as year, quarter, month, day, and day of week, and extract them easily from the date fields. Sort reports into date sequence, regardless of how the date appears. For example, January sorts before April even though, without date smarts, April alphabetically comes before January. Do arithmetic with dates and compare the dates without resorting to special date-handling functions.
514
7214ax02.fm
Table B-2 Date format options Display option D M Y YY T Meaning Day Month Year Four-digit year Translate month Effect Displays a value from 1 to 31 for the day. Displays a value from 1 to 12 for the month. Displays a two-digit year. Displays a four-digit year. When used with M in a date (MT or TM), the three-letter abbreviation for the month in uppercase is displayed. When used with M in a date (Mt or tM), the three-letter abbreviation for the month is displayed, capitalizing only the first letter of the month or day. TR is like T, but displays the full name in uppercase. tr is like t, but displays the full name in mixed case. Displays the quarter Q1 - Q4. On its own, W displays the number of the day of the week (1-7, Mon=1). Used in combination with other date options, W displays a three-letter abbreviation of the day of the week in uppercase. Functions as uppercase W (described previously), except that the first letter is uppercase and the following letters are lowercase. Functions the same as uppercase W (described above), except that the entire day name is displayed instead of an abbreviation. Functions the same as lowercase w (described above), except that the entire day name is displayed instead of an abbreviation. Displays date in Julian format. Displays a Julian format date in the format YYYYDDD. The 7-digit format displays the four-digit year and the number of days counting from January 1. For example, January 3, 2001 in Julian format is 2001003.
Translate month
TR tr Q W
Day-of-Week
WR
Day-of-Week
wr
Day-of-Week
JUL YYJUL
Table B-3 shows samples of output for various date formatting options.
Table B-3 Sample output for date formatting options Translation MT Mt MTR Mtr WR Display JAN Jan JANUARY January MONDAY
515
7214ax02.fm
Translation wr Q YQ
7214ax02.fm
For example, NEWQUARTER and THISQUARTER both have FORMAT specifications of Q, and the value of THISQUARTER is 2. In this case, consider the following statement: NEWQUARTER = THISQUARTER + 3 This statement gives NEWQUARTER a value of 1 (that is, the remainder of 5 divided by 4). The following example calculates the number of days elapsed since January 1, 1999: YEARTODATE = ORDERDATE - 'JAN 1 1999' ;
517
7214ax02.fm
518
7214ax02.fm
5. Save the report as Revenue by Order Date 6. Run the report In this report (Figure B-2 on page 519), you see Revenue and Cost of Goods Sold ordered and grouped by order date.
519
7214ax02.fm
This is a useful report, but suppose your users really want the order date shown in MDYY format. Because the order date field in your database is defined as YYMD format, you need to take additional steps to override this attribute when displaying the date field in a DB2 Web Query report. These steps involve changing the usage value of the order date field as defined in the synonym of the file this report is based on. To update the synonym you will use DB2 Web Query Developer Workbench. 7. Open DB2 Web Query Developer Workbench and open a connection to your environment 8. Expand Data Servers EDASERVE Applications baseapp' 9. Find and right-click on the cen_orders.mas synonym file and select Edit in Synonym Editor from right click menu The synonym editor is opened. 10.Select the ORDERDATE field. Notice that this is a "true" DATE field (see the ACTUAL attribute) and its USAGE value is YYMD (which is how it is defined in the database). As shown in Figure B-3 on page 520, override this attribute by selecting MDYY from the Date Order setting under USAGE
11.The USAGE field changes to MDYY. Click the save icon to save this change. 12.Return to your DB2 Web Query browser session and click on the Revenue by Order Date report again to run it. Notice that the Order Date column is now presented in MDYY format (Figure B-4).
520
7214ax02.fm
521
7214ax02.fm
4. From the list of displayed synonyms, select CEN_LEGACY_ORDER_HEADER as the data source as shown in Figure B-5.
d. In Report Assistant, create a New define field by clicking on the down arrow by the calculaor icon and selecting New define field as shown in Figure B-6 on page 522.
To convert the packed decimal fields to dates, use the DATECVT function. This function converts the field value of any standard date format or legacy date format into a new date, in either the desired standard date format or legacy date format. These are the parameters for this function: date is the input legacy field to be converted.
522
7214ax02.fm
in_format is the format of the input legacy date. Examples: P8MDYY, I8MDYY, I6YMD, A8MDYY. output_format is the output date format. Examples: YYMD, YQ, M, DMY, JUL. 5. From the Define Field Creator window, specify the following and click OK: Field: OrderDate (this is the new virtual column name) Format: MDYY (this is the output date format of the new virtual column) Expression: DATECVT( ORDDAT, 'P8MDYY', 'MDYY' ) An example is provided in Figure B-7 on page 523.
Note: ORDDAT is a Packed Decmial (8,0) field. If you inspect the DB2 Web Query synonym for the this field, you will notice that it is defined as P9 (rather than P8). This is normal - the extra digit is used to store the decimal point. For the purposes of date conversion, always ignore extra digit(s) when specifying the value of the input format parameter. So, in this case the value should be P8MDYY 6. Create another define field to display just the year of the OrderDate column. Specify the following attributes and click OK: Field: OrderYear Format: YY Expression: OrderDate An example is provided in Figure B-8 on page 524.
523
7214ax02.fm
7. Create another define field to display the day of the week (MON, TUE, etc.) of the OrderDate column. Specify the following attributes and click OK: Field: OrderDayOfWeek Format: WT Expression: OrderDate An example is provided in Figure B-9.
524
7214ax02.fm
Attention: A full list of date display formats can be found in Date format display options on page 514. 8. Finish the report by performing the following: a. Drag the new OrderYear field into the Sort by pane. b. Drag OrderDayOfWeek field into the Sort across pane. c. Drag the ORDAMT field into the Sum pane and select it. Click on the Show field options icon for this field. d. Add comma inclusion and floating currency formatting to the ORDAMT field by adding CM to the end of the Format in report as setting. e. When finished, the report definition should look like the exampe provided in Figure B-10.
9. Run the report. It should look like the example displayed in Figure B-11.
525
7214ax02.fm
Figure B-11 Results of report that uses define fields for date conversion
10.Save your report as Date conversion using Web Query functions. 11.Press the Quit icon to exit Report Assistant
526
7214ax02.fm
The result is a very efficient date conversion implementation and a faster-running report. Figure B-12 on page 527 illustrates how the join to the date conversion table works:
With this technique, each date format (column) in the date conversion table is available to the DB2 Web Query development tools and therefore can be easily be included in any report. This gives the report developer the ability to effortlessly do some interesting customized analysis. For example: What are the profit margins on days before and after holidays? How many bags of corn chips are sold the week before the Super Bowl? What is the rate of product returns on the day after Christmas as compared to any other day of the year? Are more galoshes sold in the spring or the fall? How many boxes of diapers are sold on days when there is a full moon? The usefulness of a date conversion table goes well beyond DB2 Web Query. I can be implemented in any application or tool that has access to DB2 for i. If you have RPG programs, you can join to this table (using either embedded SQL or native Record Level Access operations such as CHAIN) to perform quick and easy date conversions. It can even be used in your Query/400 reports. Implementing the date conversion method is relatively simple and can be performed in the following four steps: 1. Create the date conversion table. 2. Populate the date conversion table 3. Add join segment to the synonym 4. Create reports.
527
7214ax02.fm
CREATE TABLE DATE_CONV ( DC_DATE DATE DEFAULT NULL , DC_JDE_JULIAN_DATE FOR COLUMN DC_JDE_JUL DECIMAL(6, 0) DEFAULT NULL , DC_MDYY_DEC FOR COLUMN DC_MDYY_P DECIMAL(8, 0) DEFAULT NULL , DC_MDYY_ZONED FOR COLUMN DC_MDYY_Z NUMERIC(8, 0) DEFAULT NULL , DC_MDYY_CHAR FOR COLUMN DC_MDYY_C CHAR(8) CCSID 37 DEFAULT NULL , DC_YYMD_DEC FOR COLUMN DC_YYMD_P DECIMAL(8, 0) DEFAULT NULL , DC_YYMD_ZONED FOR COLUMN DC_YYMD_Z NUMERIC(8, 0) DEFAULT NULL , DC_YYMD_CHAR FOR COLUMN DC_YYMD_C CHAR(8) CCSID 37 DEFAULT NULL , DC_CC_CHAR CHAR(2) CCSID 37 DEFAULT NULL , DC_YY_CHAR CHAR(2) CCSID 37 DEFAULT NULL , DC_MM_CHAR CHAR(2) CCSID 37 DEFAULT NULL , DC_DD_CHAR CHAR(2) CCSID 37 DEFAULT NULL , DC_YEAR INTEGER DEFAULT NULL , DC_DOW INTEGER DEFAULT NULL , DC_DOY INTEGER DEFAULT NULL , DC_WOY INTEGER DEFAULT NULL , DC_QOY INTEGER DEFAULT NULL , DC_CC NUMERIC(2, 0) DEFAULT NULL , DC_YY NUMERIC(2, 0) DEFAULT NULL , DC_MM NUMERIC(2, 0) DEFAULT NULL , DC_DD NUMERIC(2, 0) DEFAULT NULL , DC_DAY_NAME FOR COLUMN DC_DAY_NAM CHAR(9) CCSID 37 DEFAULT NULL , DC_QUARTER_NAME FOR COLUMN DC_QTR_NAM CHAR(6) CCSID 37 DEFAULT NULL , DC_WEEKEND CHAR(1) CCSID 37 DEFAULT NULL , DC_SEASON CHAR(6) CCSID 37 DEFAULT NULL , DC_FISCAL_YEAR FOR COLUMN DC_FIS_YR INTEGER DEFAULT NULL , DC_FISCAL_QUARTER FOR COLUMN DC_FIS_QTR INTEGER DEFAULT NULL , DC_MONTH_NAME FOR COLUMN DC_MO_NM CHAR(9) CCSID 37 DEFAULT NULL , DC_MONTH_ABRV FOR COLUMN DC_MO_ABV CHAR(3) CCSID 37 DEFAULT NULL , DC_JULIAN NUMERIC(7, 0) DEFAULT NULL , DC_CYYMMDD DECIMAL(7, 0) DEFAULT NULL , DC_EXCEL_DATE FOR COLUMN DC_EXCEL INTEGER DEFAULT NULL , DC_WEEK_STARTING_DATE FOR COLUMN DC_WKSTR DATE DEFAULT NULL, DC_WEEK_ENDING_DATE FOR COLUMN DC_WKEND DATE DEFAULT NULL, DC_SAME_DAY_LAST_YEAR FOR COLUMN DC_SDLY DATE DEFAULT NULL, DC_CURRENT_DAY FOR COLUMN DC_CDAY CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_WEEK FOR COLUMN DC_CWEEK CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_MONTH FOR COLUMN DC_CMONTH CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_QUARTER FOR COLUMN DC_CQTR CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_YEAR FOR COLUMN DC_CYEAR CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_DAY_LAST_YEAR FOR COLUMN DC_LDAY CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_WEEK_LAST_YEAR FOR COLUMN DC_LWEEK CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_MONTH_LAST_YEAR FOR COLUMN DC_LMONTH CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_QUARTER_LAST_YEAR FOR COLUMN DC_LQTR CHAR(1) CCSID 37 DEFAULT NULL, DC_CURRENT_YEAR_LAST_YEAR FOR COLUMN DC_LYEAR CHAR(1) CCSID 37 DEFAULT NULL); LABEL ON COLUMN DATE_CONV ( DC_DATE TEXT IS 'Date (date format)' , 528
Getting Started with DB2 Web Query for i
7214ax02.fm
DC_JDE_JULIAN_DATE TEXT IS 'JDE Julian Date (CYYDDD decimal)' , DC_MDYY_DEC TEXT IS 'Date (MMDDYYYY packed decimal)' , DC_MDYY_ZONED TEXT IS 'Date (MMDDYYYY zoned decimal)' , DC_MDYY_CHAR TEXT IS 'Date (MMDDYYYY character)' , DC_YYMD_DEC TEXT IS 'Date (YYYYMMDD packed decimal)' , DC_YYMD_ZONED TEXT IS 'Date (YYYYMMDD zoned decimal)' , DC_YYMD_CHAR TEXT IS 'Date (YYYYMMDD character)' , DC_CC_CHAR TEXT IS 'Century (2 characters)' , DC_YY_CHAR TEXT IS 'Year (2 characters)' , DC_MM_CHAR TEXT IS 'Month (2 characters)' , DC_DD_CHAR TEXT IS 'Day (2 characters)' , DC_YEAR TEXT IS 'Year (4 digits)' , DC_DOW TEXT IS 'Day of week (1-7)' , DC_DOY TEXT IS 'Day of year (1-366)' , DC_WOY TEXT IS 'Week of year (1-52)' , DC_QOY TEXT IS 'Quarter of year (1-4)' , DC_CC TEXT IS 'Century (2 digits)' , DC_YY TEXT IS 'Year (2 digits)' , DC_MM TEXT IS 'Month (2 digits)' , DC_DD TEXT IS 'Day (2 digits)' , DC_DAY_NAME TEXT IS 'Day Name (Monday,etc.)' , DC_QUARTER_NAME TEXT IS 'Quarter name (2008Q1)' , DC_WEEKEND TEXT IS 'Weekend Flag (Y or N)' , DC_SEASON TEXT IS 'Season (Spring, Summer, Autumn, Winter)' , DC_FISCAL_YEAR TEXT IS 'Fiscal year (4 digits)' , DC_FISCAL_QUARTER TEXT IS 'Fiscal quarter (1-4)' , DC_MONTH_NAME TEXT IS 'Month name (January, etc)' , DC_MONTH_ABRV TEXT IS 'Month abbreviation (Jan, Feb, etc)' , DC_JULIAN TEXT IS 'Date in Julian format' , DC_CYYMMDD TEXT IS 'CYYMMDD packed C = 0 for 1900 & C = 1 for 2000' , DC_EXCEL_DATE TEXT IS 'Date in Excel format' , DC_WEEK_STARTING_DATE TEXT IS 'Week starting date (the prior Saturday)', DC_WEEK_ENDING_DATE TEXT IS 'Week ending date (the next Friday)', DC_SAME_DAY_LAST_YEAR TEXT IS 'Same day last year', DC_CURRENT_DAY TEXT IS 'Current Day (Y/N)', DC_CURRENT_WEEK TEXT IS 'Current Week (Y/N)', DC_CURRENT_MONTH TEXT IS 'Current Month (Y/N)', DC_CURRENT_QUARTER TEXT IS 'Current Quarter (Y/N)', DC_CURRENT_YEAR TEXT IS 'Current Year (Y/N)', DC_CURRENT_DAY_LAST_YEAR TEXT IS 'Current Day Last Year (Y/N)', DC_CURRENT_WEEK_LAST_YEAR TEXT IS 'Current Week Last Year (Y/N)', DC_CURRENT_MONTH_LAST_YEAR TEXT IS 'Current Month Last Year (Y/N)', DC_CURRENT_QUARTER_LAST_YEAR TEXT IS 'Current Quarter Last Year (Y/N)', DC_CURRENT_YEAR_LAST_YEAR TEXT IS 'Current Year Last Year (Y/N)') ;
529
7214ax02.fm
CREATE PROCEDURE LOAD_DATE_CONVERSION_TABLE ( ) LANGUAGE SQL BEGIN DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE DECLARE VAR_DATE DATE DEFAULT NULL ; VAR_JDE_JULIAN_DATE DECIMAL ( 6 , 0 ) ; VAR_JDE_JULIAN_DATE_CHAR CHAR ( 6 ) ; VAR_DATE_MDYY_DEC DECIMAL ( 8 , 0 ) ; VAR_DATE_MDYY_ZONED NUMERIC( 8 , 0 ) ; VAR_DATE_MDYY_CHAR CHAR ( 8 ) ; VAR_DATE_YYMD_DEC DECIMAL ( 8 , 0 ) ; VAR_DATE_YYMD_ZONED NUMERIC( 8 , 0 ) ; VAR_DATE_YYMD_CHAR CHAR ( 8 ) ; VAR_CC_CHAR CHAR ( 2 ) ; VAR_YY_CHAR CHAR ( 2 ) ; VAR_MM_CHAR CHAR ( 2 ) ; VAR_DD_CHAR CHAR ( 2 ) ; VAR_YEAR INTEGER ; VAR_DOW INTEGER ; VAR_DOY INTEGER ; VAR_WOY INTEGER ; VAR_QOY INTEGER ; VAR_CC NUMERIC ( 2 , 0 ) ; VAR_YY NUMERIC ( 2 , 0 ) ; VAR_MM NUMERIC ( 2 , 0 ) ; VAR_DD NUMERIC ( 2 , 0 ) ; VAR_DAY_NAME CHAR ( 9 ) ; VAR_QUARTER_NAME CHAR ( 6 ) ; VAR_WEEKEND CHAR ( 1 ) ; VAR_SEASON CHAR ( 6 ) ; VAR_FISCAL_YEAR INTEGER ; VAR_FISCAL_QUARTER INTEGER ; VAR_MONTH_NAME CHAR ( 9 ) ; VAR_MONTH_ABRV CHAR ( 3 ) ; VAR_JULIAN NUMERIC ( 7 , 0 ) ; VAR_EXCEL_DATE INTEGER ; VAR_CYYMMDD_DEC DECIMAL ( 7 , 0 ) ; VAR_WEEK_ENDING_DATE DATE DEFAULT NULL ; VAR_WEEK_STARTING_DATE DATE DEFAULT NULL ; VAR_SAME_DAY_LAST_YEAR DATE DEFAULT NULL ; VAR_CURRENT_DAY CHAR(1) ; VAR_CURRENT_WEEK CHAR(1) ; VAR_CURRENT_MONTH CHAR(1) ; VAR_CURRENT_QUARTER CHAR(1) ; VAR_CURRENT_YEAR CHAR(1) ; VAR_CURRENT_DAY_LAST_YEAR CHAR(1) ; VAR_CURRENT_WEEK_LAST_YEAR CHAR(1) ; VAR_CURRENT_MONTH_LAST_YEAR CHAR(1) ; VAR_CURRENT_QUARTER_LAST_YEAR CHAR(1) ; VAR_CURRENT_YEAR_LAST_YEAR CHAR(1) ;
SET VAR_DATE = '01/01/1900' ; SET VAR_CURRENT_DAY = 'N' ; SET VAR_CURRENT_WEEK = 'N' ; 530
Getting Started with DB2 Web Query for i
7214ax02.fm
VAR_CURRENT_MONTH = 'N' ; VAR_CURRENT_QUARTER = 'N' ; VAR_CURRENT_YEAR = 'N' ; VAR_CURRENT_DAY_LAST_YEAR = 'N' ; VAR_CURRENT_WEEK_LAST_YEAR = 'N' ; VAR_CURRENT_MONTH_LAST_YEAR = 'N' ; VAR_CURRENT_QUARTER_LAST_YEAR = 'N' ; VAR_CURRENT_YEAR_LAST_YEAR = 'N' ;
REPEAT SET VAR_YEAR = YEAR ( VAR_DATE ) ; SET VAR_EXCEL_DATE = INT ( DAYS ( VAR_DATE ) - DAYS ( DATE ( '01/01/1900' ) ) ) + 1 ; -- Excel incorrectly calculates Feb 29, 1900 as a leap day (when in fact it is not). -- The following accounts for that. SET VAR_EXCEL_DATE = ( CASE WHEN VAR_EXCEL_DATE > 59 THEN VAR_EXCEL_DATE + 1 ELSE VAR_EXCEL_DATE END ) ; SET VAR_JDE_JULIAN_DATE = ( INT ( VAR_DATE - DATE ( '01/01/1900' ) ) / 10000 ) * 1000 + DAYOFYEAR ( VAR_DATE ) ; SET VAR_DOW = DAYOFWEEK_ISO ( VAR_DATE ) ; SET VAR_DOY = DAYOFYEAR ( VAR_DATE ) ; SET VAR_WOY = WEEK ( VAR_DATE ) ; SET VAR_QOY = QUARTER ( VAR_DATE ) ; SET VAR_CC_CHAR = SUBSTRING ( CHAR ( YEAR ( VAR_DATE ) ) , 1 , 2 ) ; SET VAR_YY_CHAR = SUBSTRING ( CHAR ( YEAR ( VAR_DATE ) ) , 3 , 2 ) ; SET VAR_MM_CHAR = SUBSTRING(DIGITS(MONTH(VAR_DATE)),9,2) ; SET VAR_DD_CHAR = SUBSTRING(DIGITS(DAY(VAR_DATE)),9,2) ; SET VAR_CC = DECIMAL ( SUBSTRING ( CHAR ( YEAR ( VAR_DATE ) ) , 1 , 2 ) ) ; SET VAR_YY = DECIMAL ( SUBSTRING ( CHAR ( YEAR ( VAR_DATE ) ) , 3 , 2 ) ) ; SET VAR_MM = MONTH ( VAR_DATE ) ; SET VAR_DD = DAY ( VAR_DATE ) ; SET VAR_DATE_MDYY_CHAR = VAR_MM_CHAR|| VAR_DD_CHAR || VAR_CC_CHAR || VAR_YY_CHAR ; SET VAR_DATE_MDYY_DEC = DECIMAL ( VAR_DATE_MDYY_CHAR ) ; SET VAR_DATE_MDYY_ZONED = VAR_DATE_MDYY_DEC ; SET VAR_DATE_YYMD_CHAR = ( VAR_CC * 1000000 ) + ( VAR_YY * 10000 ) + ( VAR_MM * 100 ) + VAR_DD ; SET VAR_DATE_YYMD_DEC = DECIMAL ( VAR_DATE_YYMD_CHAR ) ; SET VAR_DATE_YYMD_ZONED = VAR_DATE_YYMD_DEC ; SET VAR_CYYMMDD_DEC = ( CASE WHEN VAR_CC = 19 THEN ( VAR_YY * 10000 ) + ( VAR_MM * 100 ) + VAR_DD ELSE 1000000 + ( VAR_YY * 10000 ) + ( VAR_MM * 100 ) + VAR_DD END ) ; SET VAR_DAY_NAME = ( CASE VAR_DOW WHEN 1 THEN 'Monday' WHEN 2
531
7214ax02.fm
THEN WHEN 3 THEN WHEN 4 THEN WHEN 5 THEN WHEN 6 THEN WHEN 7 THEN ELSE '' END ) ;
SET VAR_QUARTER_NAME = TRIM ( CHAR ( YEAR ( VAR_DATE ) ) ) CONCAT 'Q' CONCAT TRIM ( CHAR ( QUARTER ( VAR_DATE ) ) ) ; SET VAR_WEEKEND = ( CASE VAR_DOW WHEN 1 THEN 'Y' WHEN 7 THEN 'Y' ELSE 'N' END ) ; SET VAR_SEASON = ( CASE WHEN VAR_MM < 3 OR ( VAR_MM = 3 AND VAR_DD < THEN 'Winter' WHEN VAR_MM < 6 OR ( VAR_MM = 6 AND VAR_DD < THEN 'Spring' WHEN VAR_MM < 9 OR ( VAR_MM = 9 AND VAR_DD < THEN 'Summer' WHEN VAR_MM < 12 OR ( VAR_MM = 12 AND VAR_DD THEN 'Autumn' ELSE 'Winter' END ) ; SET VAR_FISCAL_QUARTER = ( CASE WHEN VAR_MM < 4 THEN 2 WHEN VAR_MM < 7 THEN 3 WHEN VAR_MM < 10 THEN 4 ELSE 1 END ) ; SET VAR_FISCAL_YEAR = ( CASE WHEN VAR_MM < 10 THEN YEAR ( VAR_DATE ) ELSE YEAR ( VAR_DATE ) + 1
21 ) 21 ) 21 ) < 21 )
532
7214ax02.fm
END ) ; SET VAR_MONTH_NAME = MONTHNAME ( VAR_DATE ) ; SET VAR_MONTH_ABRV = ( CASE VAR_MM WHEN 1 THEN 'JAN' WHEN 2 THEN 'FEB' WHEN 3 THEN 'MAR' WHEN 4 THEN 'APR' WHEN 5 THEN 'MAY' WHEN 6 THEN 'JUN' WHEN 7 THEN 'JUL' WHEN 8 THEN 'AUG' WHEN 9 THEN 'SEP' WHEN 10 THEN 'OCT' WHEN 11 THEN 'NOV' WHEN 12 THEN 'DEC' ELSE '' END ) ; SET VAR_JULIAN = DECIMAL ( SUBSTRING ( CHAR ( ( YEAR ( VAR_DATE ) * 1000 + DAYOFYEAR ( VAR_DATE ) ) ) , 1 , 7 ) ) ; SET VAR_WEEK_ENDING_DATE = ( CASE VAR_DOW WHEN 1 THEN VAR_DATE + 4 DAYS WHEN 2 THEN VAR_DATE + 3 DAYS WHEN 3 THEN VAR_DATE + 2 DAYS WHEN 4 THEN VAR_DATE + 1 DAYS WHEN 5 THEN VAR_DATE WHEN 6 THEN VAR_DATE + 6 DAYS WHEN 7 THEN VAR_DATE + 5 DAYS ELSE NULL END ) ; SET VAR_WEEK_STARTING_DATE = VAR_WEEK_ENDING_DATE - 6 DAYS;
533
7214ax02.fm
SET VAR_SAME_DAY_LAST_YEAR = VAR_DATE - 364 DAYS; INSERT INTO DATE_CONV VALUES ( VAR_DATE , VAR_JDE_JULIAN_DATE , VAR_DATE_MDYY_DEC , VAR_DATE_MDYY_ZONED , VAR_DATE_MDYY_CHAR , VAR_DATE_YYMD_DEC , VAR_DATE_YYMD_ZONED , VAR_DATE_YYMD_CHAR , VAR_CC_CHAR , VAR_YY_CHAR , VAR_MM_CHAR , VAR_DD_CHAR , VAR_YEAR , VAR_DOW , VAR_DOY , VAR_WOY , VAR_QOY , VAR_CC , VAR_YY , VAR_MM , VAR_DD , VAR_DAY_NAME , VAR_QUARTER_NAME , VAR_WEEKEND , VAR_SEASON , VAR_FISCAL_YEAR , VAR_FISCAL_QUARTER , VAR_MONTH_NAME , VAR_MONTH_ABRV , VAR_JULIAN , VAR_CYYMMDD_DEC , VAR_EXCEL_DATE , VAR_WEEK_STARTING_DATE, VAR_WEEK_ENDING_DATE, VAR_SAME_DAY_LAST_YEAR, VAR_CURRENT_DAY, VAR_CURRENT_WEEK, VAR_CURRENT_MONTH, VAR_CURRENT_QUARTER, VAR_CURRENT_YEAR, VAR_CURRENT_DAY_LAST_YEAR, VAR_CURRENT_WEEK_LAST_YEAR, VAR_CURRENT_MONTH_LAST_YEAR, VAR_CURRENT_QUARTER_LAST_YEAR, VAR_CURRENT_YEAR_LAST_YEAR ) ; SET VAR_DATE = VAR_DATE + 1 DAY ; UNTIL VAR_DATE > '12/31/2030' END REPEAT ; END ;
534
7214ax02.fm
Notice that several of the columns in the date conversion table are current flags that contain the value of Y or N depending of if the condition for that flag is met. For example, the column DC_CURRENT_YEAR will contain a Y if that row represents a date whose year is equal to the current year. So if the current date is August 26, 2009, then the value for the DC_CURRENT_YEAR column would be Y for all of the rows that represent dates for the year 2009. Because these are dynamic values, you need to add a process to keep these columns in the date conversion table updated. The stored procedure example provided in Example B-3 does just that.
CREATE PROCEDURE UPDATE_DATE_CONVERSION_TABLE ( ) LANGUAGE SQL BEGIN UPDATE UPDATE UPDATE UPDATE UPDATE DATE_CONV DATE_CONV DATE_CONV DATE_CONV DATE_CONV SET SET SET SET SET DC_CURRENT_DAY = 'N' WHERE DC_CURRENT_DAY = 'Y'; DC_CURRENT_WEEK = 'N' WHERE DC_CURRENT_WEEK = 'Y'; DC_CURRENT_MONTH = 'N' WHERE DC_CURRENT_MONTH = 'Y'; DC_CURRENT_QUARTER = 'N' WHERE DC_CURRENT_QUARTER = 'Y'; DC_CURRENT_YEAR = 'N' WHERE DC_CURRENT_YEAR = 'Y';
UPDATE DATE_CONV SET DC_CURRENT_DAY_LAST_YEAR = 'N' WHERE DC_CURRENT_DAY_LAST_YEAR = 'Y'; UPDATE DATE_CONV SET DC_CURRENT_WEEK_LAST_YEAR = 'N' WHERE DC_CURRENT_WEEK_LAST_YEAR = 'Y'; UPDATE DATE_CONV SET DC_CURRENT_MONTH_LAST_YEAR = 'N' WHERE DC_CURRENT_MONTH_LAST_YEAR = 'Y'; UPDATE DATE_CONV SET DC_CURRENT_QUARTER_LAST_YEAR = 'N' WHERE DC_CURRENT_QUARTER_LAST_YEAR = 'Y'; UPDATE DATE_CONV SET DC_CURRENT_YEAR_LAST_YEAR = 'N' WHERE DC_CURRENT_YEAR_LAST_YEAR = 'Y'; UPDATE DATE_CONV SET DC_CURRENT_DAY = 'Y' WHERE DC_DATE = CURRENT DATE; UPDATE DATE_CONV SET DC_CURRENT_WEEK = 'Y' WHERE DC_DATE >= (SELECT DC_WEEK_STARTING_DATE FROM DATE_CONV WHERE DC_DATE = CURRENT DATE) AND DC_DATE <= (SELECT DC_WEEK_ENDING_DATE FROM DATE_CONV WHERE DC_DATE = CURRENT DATE); UPDATE DATE_CONV SET DC_CURRENT_MONTH = 'Y' WHERE DC_YEAR = YEAR(CURRENT DATE) AND DC_MM = MONTH(CURRENT DATE); UPDATE DATE_CONV SET DC_CURRENT_QUARTER = 'Y' WHERE DC_YEAR = YEAR(CURRENT DATE) AND DC_QOY = QUARTER(CURRENT DATE); UPDATE DATE_CONV SET DC_CURRENT_YEAR = 'Y' WHERE DC_YEAR = YEAR(CURRENT DATE); UPDATE DATE_CONV SET DC_CURRENT_DAY_LAST_YEAR = 'Y' WHERE DC_DATE = CURRENT DATE - 364 DAYS; UPDATE DATE_CONV SET DC_CURRENT_WEEK_LAST_YEAR = 'Y' WHERE DC_DATE >= (SELECT DC_WEEK_STARTING_DATE FROM DATE_CONV WHERE DC_DATE = (CURRENT DATE - 364 DAYS)) AND DC_DATE <= (SELECT DC_WEEK_ENDING_DATE FROM DATE_CONV WHERE DC_DATE = (CURRENT DATE - 364 DAYS)); UPDATE DATE_CONV SET DC_CURRENT_MONTH_LAST_YEAR = 'Y' WHERE DC_YEAR = (YEAR(CURRENT DATE) - 1) AND DC_MM = MONTH(CURRENT DATE); UPDATE DATE_CONV SET DC_CURRENT_QUARTER_LAST_YEAR = 'Y' WHERE DC_YEAR = (YEAR(CURRENT DATE) - 1) AND DC_QOY = QUARTER(CURRENT DATE); UPDATE DATE_CONV SET DC_CURRENT_YEAR_LAST_YEAR = 'Y' WHERE DC_YEAR = (YEAR(CURRENT DATE) - 1); END;
535
7214ax02.fm
All you need to do is make sure this stored procedure runs every day. To do this, create a job scheduler entry to call this stored procedure daily. This can be accomplished by taking the following steps: 1. Create a source file member to store an SQL statement script ADDPFM FILE(QGPL/QTXTSRC) MBR(UPDDATCONV) 2. Edit this source file member and add the following SQL statement to call the stored procedure: CALL QWQCENT/UPDATE_DATE_CONVERSION_TABLE 3. Now add a job sheduler job to run the SQL script in the source file member: ADDJOBJS JOB(UPDDATCONV) SCDCDE(*DAILY) TIME(0010) CMD(RUNSQLSTM SRCFILE(QGPL/QTXTSRC) SRCMBR(UPDDATCONV) COMMIT(*NONE) NAMING(*SYS)) This job scheduler job will run daily at 1 AM and will call the RUNSQLSTM command to run the script (in the specified source file member) through SQL.
536
7214ax02.fm
At this point you want to add a join segment to the date conversion table. 5. Right-mouse click on the CEN_LEGAGY_ORDER_HEADER segment name and select Add Segment From Existing Synonym as shown in Figure B-14
A list of synonyms in the BASEAPP folder is presented. 6. As demonstrated in Figure B-15 on page 538, find and select the cen_date_conv synonym and press the Select button
537
7214ax02.fm
The new segement is added to the synonym. Next you need to change the segment type from Multiple to Unique. 7. Select the new CEN_DATE_CONV join segment and locate the Type attribute under SEGTYPE 8. This is a drop down list. Click on it to and change the Type to Unique as shown in Figure B-16 on page 539. This will instruct DB2 Web Query to rely on SQL syntax to create the join and when accessing the joined columns (allowing you to sort and select fields across multiple join segments)
538
7214ax02.fm
9. Next define the fields that will be used to join the tables together. As shown in Figure B-17, right-click again on the CEN_DATE_CONV segment and select Join Properties.
539
7214ax02.fm
10.In the Join Properties window, do the following: From the list of columns in the CEN_LEGACY_ORDER_HEADER segment, select ORDDAT so that it is highlighted. From the list of columns in the CEN_DATE_CONV segment, select DC_MDYY_DEC so that it is highlighted. The values in the ORDDAT are in this format, thus this is the column in the date conversion table that you want to use as the join column. Click the = icon located between the two segment lists. This action should bring the selected join columns down into the expression pane. An example is shown in Figure B-18.
540
7214ax02.fm
11.Click OK To help the report developers identify what legacy date field this date conversion segment represents, rename the segment to the name of the field it is converting. If you do not do this, the segment names to the date conversion table many be ambiguous (yourre report developers may not be certain what legacy date field they represent). This is particularly true if you have multiple legacy date fields in your synonym because to convert them, you will need to define a join segment to date_conv for each one. Tip: If you are very meticulous (and ambitious), you could even completely remove the ambiguity by renaming each of the individual column names in the date conversion segments (for example rename DC_YEAR to ORDDAT_YEAR). This can be done by highlighting the column and selecting Rename from the right-click menu. That is really going the extra mile, but youre report developers would love you for this. 12.Highlight the segment and select Rename from the right mouse click menu. This is shown in Figure B-19.
541
7214ax02.fm
13.Specify ORDDAT as the segment name. When you are finished, your synonym will look like the example provided in Figure B-20.
542
7214ax02.fm
14.Repeat steps 5-13 for the SHPDAT legacy date field field. Be sure you rename the segment SHPDAT.
Author Comment: I was not able to figure out how to create a cross reference for steps 5-13 above.
543
7214ax02.fm
Tip: For performance reasons, now would be a good time to create indexes over your join columns. The DB2 optimizer will be able to use these indexes for statistics and implementation during query execution. Here are the two SQL statements for creating indexes over the LEGACY_ORDER_HEADER and DATE_CONV tables: CREATE INDEX LEGACY_ORDER_HEADER_INDEX_00001 ON LEGACY_ORDER_HEADER (ORDDAT ASC); CREATE INDEX DATE_CONV_INDEX_00001 ON DATE_CONV (DC_MDYY_DEC ASC);
544
7214ax02.fm
As shown in Figure B-22 on page 545, taking this action groups the synonym columns under their respective segments, and allows you to expand and collapse the list of columns under each segment.
4. Finish the report by performing the following: a. Drag the new DC_YEAR field into the Sort by pane. b. Drag DC_DOW field into the Sort across pane. Make it an invisible field. DC_DOW is the numeric value of the day of the week. You really want to sort by this field and not by the name of the day of the week field (DC_DAY_NAME). Otherwise the data for Friday would appear first (since it's the first day name alphabetically) and Wednesday would appear last. However you probably don't want the numeric day of the week value to actually appear on the report. So you want to hide this column in the report. c. Drag DC_DAY_OF_WEEK field into the Sort across pane. d. Drag the ORDAMT field into the Sum pane and select it. Click on the Show field options icon for this field. e. Add comma inclusion and floating currency formatting to the ORDAMT field by adding CM to the end of the Format in report as setting. When finished, the report definition should look like the exampe provided in Figure B-23 on page 546.
545
7214ax02.fm
5. Run the report. The results should look identical to those in Figure B-24.
Other than the fields and techniques used for date conversion, this is the same report that you created in Using DB2 Web Query functions to convert to dates on page 521. Compare the results of those two reports. They should be identical. 6. Save your report as Date conversion using date conversion table.
546
7214ax02.fm
Tip: Now would be an opportune time to create indexes over the join columns. One of the advantages of the date conversion table method is that all of the columns in the table will be brought into the synonyms segment and subsequently will appear on the list of available fields in the development tools. This gives report developers the ability to easily and effortlessly include a wide variety of date formats in your reports. One of the disadvantages is that all of the columns in the table will appear on the list of available fields in the development tools. Why is this a disadvantage? Because there may many columns in the table and some of them may never actually be used in the reports. These columns can clutter up the list, particularly if the synonym contains many other columns. Further, and as mentioned previously, if you have multiple legacy date fields in your file and you want to convert them to date fields, you will need to create join segments to the date conversion table for each one. This will add even more columns to the list of fields in the development tools. Here are some ideas to keep the list of available fields to a manageable size: Create date conversion table with fewer columns (only the ones your use regularly) Create DB2 Web Query business views over your synonyms. This will allow you to create and organize a subset of columns to display in the report development tools. See zzz for more information on business views. Set the the columns Access Property to INTERNAL to hide the infrequently used columns in the synonym . This gives you the ability to preserve the columns in the date conversion table, while not showing them in the development tools. If they are needed for some reports you can simply unhide them by unchecking the INTERNAL setting. Figure B-25 on page 548 provides an example of how to hide DC_MONTH_NAME so that it does not appear in the list of available columns in the report development tools.
547
7214ax02.fm
Figure B-25 Defining a column that does not appear in list of available columns
Attention: Existing reports that reference hidden columns (those whose INTERNAL setting for ACCESS PROPERTY is selected) will continue to run. However, if you attempt to open such a report in the report development tools, the request will fail with a Field not found in master file error. In those cases, you will need to edit the synonym and remove (uncheck) the INTERNAL setting for ACCESS PROPERTY.
7214ax02.fm
cust , orderdate , shipdate , shpvia , ordsts , ordamt , totlin , invnum ) AS (SELECT order, cust, DATE(SUBSTRING(DIGITS(orddat),5,4) || '-' || SUBSTRING(DIGITS(orddat),1,2) || '-' || SUBSTRING(DIGITS(orddat),3,2)), DATE(SUBSTRING(DIGITS(shpdat),5,4) || '-' || SUBSTRING(DIGITS(shpdat),1,2) || '-' || SUBSTRING(DIGITS(shpdat),3,2)), shpvia, ordsts, ordamt, totlin, invnum FROM legacy_order_header ) SELECT order, cust, orderdate, YEAR(orderdate) AS orderyear, DAYOFWEEK_ISO(orderdate) AS orderdow, CASE WHEN DAYOFWEEK_ISO(orderdate) = 1 THEN 'MON' WHEN DAYOFWEEK_ISO(orderdate) = 2 THEN 'TUE' WHEN DAYOFWEEK_ISO(orderdate) = 3 THEN 'WED' WHEN DAYOFWEEK_ISO(orderdate) = 4 THEN 'THU' WHEN DAYOFWEEK_ISO(orderdate) = 5 THEN 'FRI' WHEN DAYOFWEEK_ISO(orderdate) = 6 THEN 'SAT' WHEN DAYOFWEEK_ISO(orderdate) = 7 THEN 'SUN' ELSE '' END AS orderdayname, shipdate, shpvia, ordsts, ordamt, totlin, invnum FROM t1
The above example performs the following: Converts legacy date fields ORDDAT and SHPDAT to true dates and returns them in the derived columns named ORDERDATE AND SHIPDATE. Creates a second derived column named ORDERYEAR by referencing the derived column ORDERDATE in the SQL function YEAR. This column returns the year portion of the date. Creates a third derived column named ORDERDOW by referencing the derived column ORDERDATE in the SQL function DAYOFWEEK_ISO. This column returns the integer value of the day of the week. Creates a fourth derived column named ORDERDAYNAME by referencing the derived column ORDERDATE in the SQL function DAYOFWEEK_ISO and performing some logic in a CASE statement to return the name of the day of the week. Notice the use of the WITH keyword to create an SQL common table expressions. If you are not familiar with common table expressions, they can be thought of as temporary views that only exist during the execution of the query. By using them, you can define a result table with a table-identifier (T1 above) that can be specified as the table name in any FROM clause of the SELECT statement. Because the example uses derived columns that reference other derived columns (ORDERDATE), a common table expression is used. It allows you to define ORDERDATE in one place and reduce the query's complexity by minimizing the amount of text, especially when ORDERDATE is referenced multiple times in the query.
549
7214ax02.fm
To create the same type of report (as the previous examples) that uses this SQL view, take the following steps: 1. Create a DB2 Web Query synonym over the view. Specify cen_ for the metadata prefix. 2. Create a new report in Report Assistant, using the new view synonym. a. Drag the ORDERYEAR field into the Sort by pane. b. Drag ORDERDOW field into the Sort across pane. Similar to the report in the previous section, make it an invisible field so that the columns are sorted by the numeric value of the day of the week rather than alphabetically by the name of the day of the week. c. Drag ORDERDAYNAME field into the Sort across pane. d. Drag the ORDAMT field into the Sum pane and select it. Click on the Show field options icon for this field. e. Add comma inclusion and floating currency formatting to the ORDAMT field by adding CM to the end of the Format in report as setting. 3. When finished, the report definition should look like the exampe provided in Figure B-26
4. Run the report. It should look like the example provided in Figure B-27 on page 551.
550
7214ax02.fm
Figure B-27 Results of report using SQL view for date conversions
The reason that the date conversion table and SQL views perform so much better (than the DB2 Web Query BIFs) is because the conversion logic processing is pushed down to the DB2 engine. However, these are two vastly different approaches: one is performing database joins to locate the row with the data that is already converted, while the other is actually performing the conversions dynamically. If SQE processes the requests, both have the ability to cache the results so that subsequent requests perform better. As you can see in the above benchmarks results, the date dimension table performed slightly better, particularly as more conversion functions were added to the SQL view. In addition, performing the conversion in an SQL views and functions may require a fairly elaborate view defintion and does require some degree of SQL knowledge to implement. The date conversion table, on the other hand, can be implemented by someone with limited SQL skills.
551
7214ax02.fm
Performance notwithstanding, the best technique is purely subjective. For simplicity, most report developers would probably prefer to use the DB2 Web Query BIFs. Use of the BIFs may provide acceptable performance in your environment, particularly for smaller databases. Consequently, the suggested approach is to try using the DB2 Web Query BIFs first. If the performance is not satistfactory, then consider using one of the other two technques. Attention: The IBM and Information Builders development teams are working on ways to improve the performance of the DB2 Web Query built-in functions, particularly those used for date conversion. The goal is to pass as much of that logic to the database engine as possbile. DB2 Web Querys ability to internally translate the BIF to the appropriate SQL function would provide the best of both worlds: report developers could use the BIFs for date conversions and deliver a report that performs well. When deciding between the date conversion table or SQL function/view method, most people would likely find the date conversion table method to be a bit more flexible and easier to implement. Because the information resides in a table that can be viewed and maintained, its easier for many to conceptualize. Implementing customized columns like fiscal year/quarter and a Super Bowl Sunday flag is also easy because you can manually set these values in the table and view the data. And after all, there is no SUPERBOWLSUNDAY SQL function (not yet anyway - though one could add syntax to the view to join it with another table that has this information).
552
7214ax02.fm
Date conversion table To implement the date conversion table method for JDE World date fields, create a join from the World file to the date conversion table using the World date field (in this case PCCEFJ) and DC_JDE_JULIAN_DATE as the join columns. Figure B-29 shows an example of how to define this join in the DB2 Web Query synonym.
Figure B-29 Using date conversion table to convert JDE World date
553
7214ax02.fm
SQL functions/view If you prefer the SQL functions and view technique, use something like the following to convert the field to a date: SELECT DATE(DIGITS( DECIMAL(pccefj + 1900000 , 7 ,0))) AS conv_date FROM f43090
CH_MDYY
CHAR(8)
MDYY
CH_YYMD
CHAR(8)
YYMD
20090831
Join CH_YYMD to DC_YYMD_CHAR in DATE_CONV table Join ZN_MDYY to DC_MDYY_ZONED in DATE_CONV table
DATE(SUBSTRING(CH_YYMD,1,4) || '-' || SUBSTRING(CH_YYMD,5,2)|| '-' || SUBSTRING(CH_YYMD,7,2)) DATE(SUBSTRING(DIGITS(ZN_MDYY) ,5,4) || '-' || SUBSTRING(DIGITS(ZN_MDYY),1,2) || '-' || SUBSTRING(DIGITS(ZN_MDYY),3,2) ) DATE(SUBSTRING(DIGITS(ZN_YYMD) ,1,4) || '-' || SUBSTRING(DIGITS(ZN_YYMD),5,2) || '-' || SUBSTRING(DIGITS(ZN_YYMD),7,2) ) DATE(SUBSTRING(DIGITS(PK_MDYY) ,5,4) || '-' || SUBSTRING(DIGITS(PK_MDYY),1,2) || '-' || SUBSTRING(DIGITS(PK_MDYY),3,2) ) DATE(SUBSTRING(DIGITS(pk_yymd) ,1,4) || '-' || SUBSTRING(DIGITS(pk_yymd),5,2) || '-' || SUBSTRING(DIGITS(pk_yymd),7,2) ) DATE(SUBSTR(CHAR(ZN_JUL),1,7))
ZN_MDYY
ZONED (8,0)
MDYY
08312009
ZN_YYMD
ZONED (8,0)
YYMD
20090831
PK_MDYY
PACKED (8,0)
MDYY
08312009
PK_YYMD
PACKED (8,0)
YYMD
20090831
ZN_JUL
ZONED (7,0)
2009243
Join ZN_JUL to DC_JULIAN in DATE_CONV table Join legacy date fields to the following columns in DATE_CONV table: DC_CC DC_YY DC_MM DC_DD
ZN_CEN ZN_YEAR ZN_MONTH ZN_DAY (Each component of the date is stored in a separate zoned decimal field.)
20 09 08 31
DATECVT( ((ZN_CEN * 1000000) + (ZN_YEAR * 10000) + (ZN_MONTH * 100) + ZN_DAY), 'I8YYMD', 'YYMD' )
554
7214ax02.fm
SQL function
CH_CEN CH_YEAR CH_MONTH CH_DAY (Each component of the date is stored in a separate character field.)
CC YY MM DD
Join legacy date fields to the following columns in DATE_CONV table: DC_CC_CHAR DC_YY_CHAR DC_MM_CHAR DC_DD_CHAR
The DATEADD function is not required if you simply want to add months or days to a date. To add months, your result field must be in a format similar to YYM or MY. To add days, your result field must contain days, for example, YYMD. If we want to add 11 days to SHIPDATE in the previous example and do not need to worry about business or weekdays, we replace the DATEADD with the following values: ORDERDATE + 11 This creates a SHIPDATE of 11 days in the future.
555
7214ax02.fm
556
7214ax02.fm
Meaning Current business day or prior business day if current is a non-business day Current weekday or next weekday (if weekend) Current business day or next business day if current is a non-business day
This define field will automatically create the prompt for an input parameter named &inDate (when the report is run). This is an example of an implicit input parameter. It will then convert the input parameter to a true date field.
557
7214ax02.fm
Attention: You do NOT need to create an input parameter for &inDate in the Selection criteria tab. 3. Create a DEFINE field named beginRange. The format is YYMD and the expression is DATEADD( inDate2, 'D', (0-&daysRange)) as shown in Figure B-33.
Similar to above, this define field will create the prompt for an input parameter named &daysRange (when the report is run). Again, you do not create an explicit input parameter for &daysRange. The DEFINE field will return a date that is the specified number of days less than the specified input date. 4. Create a DEFINE field named endRange. The format is YYMD and the expression is DATEADD( inDate2, 'D', &daysRange) as shown in Figure B-34 on page 559
558
7214ax02.fm
This DEFINE field will return a date that is the specified number of days greater than the specified input date. Important: The order that you create these DEFINE fields is very important. This is because the second and third DEFINE fields contain expressions that reference the first DEFINE field. If you define them out of order, the expression will fail because it will be unable to find and resolve DEFINE field inDate2. 5. Next go to the Selection Criteria tab and create two screending conditions for the ORDERDATE column. The first condition is GREATER THAN OR EQUAL TO the beginRange DEFINE field The second condition is LESS THAN OR EQUAL TO the endRange DEFNE field. Select WHERE for both conditions. An example is shown in Figure B-35 on page 560.
559
7214ax02.fm
6. Finally, return to the Field Selection tab and complete the report by selecting the following Sort by and Sum report columns: Sort by: ORDERDATE, PRODUCTTYPE Sum: COSTOFGOODSSOLD, LINETOTAL An example is provided in Figure B-36.
560
7214ax02.fm
7. Save your report as Dynamic Date Range 8. Click Quit to return to the DB2 Web Query launch page. 9. Run the new Dynamic Date Range report 10.Specify 20071111 for the inDate parm and 5 for daysRange 11.Click Run. The report returns rows for orders between 11/06/2007 and 11/16/2007 as shown in Figure B-37.
561
7214ax02.fm
562
7214ax02b.fm
Appendix C.
563
7214ax02b.fm
We explain the sequence in greater detail as follows while noting the differences between the two fields: 1. When DB2 Web Query begins to process a report request, it locates the Master File Description (MFD) and the database. DB2 Web Query then processes the WHERE test on a database value to select a valid record for the report. 2. After selecting a record, DB2 Web Query determines the value of each define field, in sequence. After determining the values of the define fields, it executes any selection tests that use the value of a define field and potentially further limits the number of records per report. 3. DB2 Web Query then sorts the data (according to the BY and ACROSS phrases) and performs the action indicated in the verb phrase (PRINT, SUM, or COUNT). If the report uses SUM or COUNT, it aggregates the values in memory. 4. DB2 Web Query then takes the processed data and determines the values of any compute fields, in the sequence in which they appear in the request. 5. After evaluating the compute fields, DB2 Web Query performs the final selection test; it performs any WHERE TOTAL tests against any aggregated results and the values of the compute fields, and thereby further limits the records for the report. 6. Finally DB2 Web Query formats the report and routes it to your Web browser.
564
7214ax02c.fm
Appendix D.
565
7214ax02c.fm
Developer Workbench
The simplest way to move items between multiple systems is using Developer Workbench. This requires a connection to both systems at the same time to make this work. Once both systems are added and expanded in Developer Workbench, you can simply drag and drop between systems. This works for all types of items: metadata, applications, domains, folders, reports, HTML pages, and images.
566
7214ax02c.fm
authority since that is the only level that can create a new domain, which is essentially what you are doing during the load. Again, we have the two panel screen, showing the available packages on the left. Select the one you just created to move to the right side and click Load Change Package. I confirmation message will appear when the load is complete. For more details on this process, please see IBM i Knowledge Base Document 517159487.
567
7214ax02c.fm
568
7214addm.fm
Appendix E.
Additional material
This book refers to additional material that can be downloaded from the Internet as described below.
569
7214addm.fm
570
7214bibl.fm
Related publications
The publications listed in this section are considered particularly suitable for a more detailed discussion of the topics covered in this book.
IBM Redbooks
For information about ordering these publications, see How to get IBM Redbooks on page 571. Note that some of the documents referenced here might be available in softcopy only. OnDemand SQL Performance Analysis Simplified on DB2 for i5/OS in V5R4, SG24-7326 Preparing for and Tuning the SQL Query Engine on DB2 for i5/OS, SG24-6598 SQL Performance Diagnosis on IBM DB2 Universal Database for iSeries, SG24-6654
Online resources
These Web sites are also relevant as further information sources: Information Builders Corporate http://www.informationbuilders.com/ DB2 for i5/OS Portal http://www.ibm.com/systems/i/software/db2 DB2 Web Query http://www-03.ibm.com/systems/i/software/db2/webquery/ DB2 Web Query for i developerWorks Community http://www.ibm.com/developerworks/spaces/DB2WebQuery System i Database DB2 UDB SQL call level interface (ODBC) http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/cli/rzadp.pdf Indexing and Statistics Strategies for DB2 for i5/OS http://www.ibm.com/servers/enable/site/education/ibo/record.html?indxng
571
7214bibl.fm
572
7214IX.fm
Index
Symbols
*QRYDFN 4 automatic generation or refresh of metadata 486 autostart after IPL 484 Available fields icons 100
Numerics
3020 record 462 5722-QU1 (Query/400) 45, 18 5733-QU2 (DB2 Web Query) 57, 1718, 43, 227, 229, 450
B
bar chart 152, 302 dual axis 160 multiple bars to one chart 156 with drill-down capabilities 154 basic synonyms 344 basic user 85 Basic user tasks 25 benchmark, DB2 Web Query 474 Burst this Report 400 Burst Value 406 Business View 361 Business Views 46
A
access file 45, 254, 512 Active Reports 8, 229, 481 active visualizations 502 ActiveX controls 235 cross-tab or pivot functionality 243 e-mail user requirements 502 file size 502 filtered chart 240 general use of 235 highlights 230 license key 231 overview 230 problems saving 502 report creation 231 tutorial 229 Active Reports Styling 232 ActiveX controls 235 adapter 13 optimization 438 processing 438 Add Adapter Configuration 385 ADDLICKEY command 384 add-on products 501 ADDRDBDIRE command 73 ADDWQLUSR 29 ADMIN 39 Administration Console 13 Administration console 394 Administrator tasks 25 administrator tasks 31 assignment of authority to users 35 domains 31 subfolder creation 34 Advanced 399 aggregate field 125 aggregation optimization 445 AJAX 7, 481 analysis 466 application server 1112 architecture 11 auditing 485 authority, assignment to users 35 authorization of users 19
C
calendar controls 316 call-level interface (CLI) 22 capabilities of DB2 Web Query 480 cell formatting 382 CENTURY 43 Change report 35 chart, revenue trend over time 167 CHGUSRPRF 31 child table 57 Classic Query Engine (CQE) 5, 13, 93, 451, 490 CLI (call-level interface) 22 cluster 99 cluster join 354 Common Domain 32, 91 Common Domain folder 32 compound parameterized report 290 bar chart 302 gross profit report 303 HTML page options 303 HTML report 296 line chart 298 New form element 300 compute field 190, 563 computing fields 115 conditional styling 118, 190, 377 configuration of Developer Workbench 250 Configuring Report Broker 394 Connection Name 74 Contains operand 239 CPU resource usage 476 CQE (Classic Query Engine) 5, 13, 93, 451, 490 CREATE ALIAS 55 Create domain 35 Create report 35 Create subfolder 35
573
7214IX.fm
Create Synonym 49, 387 Creating Metadata 387 cross-system join 72, 448 cross-tab functionality 243 cross-tab report 113
D
dashboard 15, 495 graphics 496 periodic report 496 Dashboards in Excel 381 data adapters 7, 13 DB2 CLI 7, 13 DB2 Heritage File 7, 13 DB2 Heritage File adapter 13 Query/400 7 data download to PC server or Windows server 483 data field, format conversion 517 data profiling 8, 366 Data Range Properties 382 database analysis and tuning 472 design 451 monitor 473 database joins 46 Datasource 74 date component conversion 517 functions 555 manipulation 350 separator 516 date and time functionality 513 system variables 514 Date Decomposition 8, 348 date field 516 conversion 517 date component conversion 517 in arithmetic expressions 516 date format 514 display options 514 date formatting 109 date range filter 176 date range parameter 181 DATEADD function 555 DATEDIFF function 556 DATEMOV function 556 DB2 11 DB2 CLI adapter 7, 13 performance 436 DB2 file output 132 DB2 for i5/OS database, query without multiple licenses 489 optimization 451 referential integrity features 486 DB2 Heritage File adapter 7, 13, 55 DB2 Web Query 5 additional features 481 administrator tasks 31 adopted authority for reports 485
aggregation optimization 445 architecture 11 attributes 12 autostart after IPL 484 base features 6 capabilities 480 conditions that prevent optimization 443 data adapters 13 Developer Workbench 15 domain authority 485 domains 31, 484 exception join 489 features 6 functional differences with Query/400 429 functional similarities with Query/400 428 general announcement 378, 384, 418, 480 Graph Assistant 6 imported Query/400 object 490 imported Query/400 query 490 installation 18 installation and server operations 17 integration with Excel 2007 501 integration with Rational tools 483 introduction 5 license keys 19 login 29 multiple licenses 489 named user 486 object import from Query/400 489 OLAP feature dimensions 501 optional features from IBM 7 optional features from Information Builders 9 PC and System i requirements 20 performance benchmark 474 performance considerations 435 port 11331 for HTTP requests 484 Power Painter 7 product information 378, 384, 418, 480 product positioning 15 QRYDFN edit 433 Query/400 definitions 490 reasons to move from Query/400 480 referential integrity 57 Report Assistant 6 report auditing 485 report development 490 report run from CL program 496 Reporting Server 13 commands 22 reports from Query/400 489 running existing Query/400 reports 427 running in an IASP environment 565 RUNWEBQRY command 496 save and restore 504 server jobs 22 server-based processing 484 servlet 12 sign-on via LDAP or Kerberos 485 sorting optimization 445 stored procedures with input parameters 492
574
7214IX.fm
training and education 506 upgrade to 489 user security 485 web console 484 DB2 Web Query domain 26 DB2 Web Query users 25 DB2 Web Query V1R1M1 394 DDS Logical files 45 define field 190, 563 defining fields 115 detail reports 102 Developer tasks 25 developer tasks 43 creation of metadata 47 cross-system join 72 Developer Workbench 7, 15, 97, 249, 482 additional features 343 Business View 361 configuration 250 data profiling 366 Date Decomposition 348 date manipulation 350 default options 254 filter creation 352 HTML Layout Painter 289 Impact Analysis 363 Java 2 SDK 21 not part of base DB2 Web Query product 502 OLAP 257 profiling 249 requirements 21 hardware 21 software 21 SQL Wizard 369 Synonym Editor 249, 344 synonym management 487 dicing 7 dimensions 259 Distribute report by 400 Distribution 399 domain 3031, 484 authority 485 create 33 creation 33 eight-character rule 32 rename 34 renaming 34 domain-level report movement 487 double-spaced printing 494 drill down 15, 159 adding to chart 158 bar chart 154 drill downs 377 drill-down report 138 further drill downs 494
Email option 400 ENDWEBQRY 393 ENDWEBQRY command 22 Establishing a connection 384 Event driven distribution 416 Excel 6 output 130 with formulas option 501 Excel 2000 130 Excel 2007 integration with DB2 Web Query 501 Excel 97 130 Excel spreadsheet access to another spreadsheet 501 integration 499 report 499 exception joins 489 Extensible Markup Language (XML) 6
F
FAQs (Frequently Asked Questions) 383, 393, 479 federated DB2 7 filter creation 352 Foreign key option 100 foreign key relationships 446 foreign keys 388 format conversion 517 formatting 377 formula support 377 Frequency 399 Frequently Asked Questions (FAQs) 383, 393, 479 fullselect 446
G
general announcement 378, 384, 418, 480 generic term report 290 graph building with Power Painter 201 properties and settings, Graph Assistant 166 Graph Assistant 6 bar chart 152 conditional styling 190 date range parameter 181 drill down 158 dual axis bar and line chart 160 graph properties 166 line graph 169 pie charts 184 traffic lighting a graph 190 gross profit report 303 group profile MDUNTITLED 90 Group profiles 26 GRPPRG user profile, domain authority 485
H
hierarchy 259 Highlight button 239 highly parameterized report 305 calendar controls 316
E
EDAPGWY 22 EDAPLOG 22 EDAPTH 22
Index
575
7214IX.fm
Highly Parametrized reports 411 HLISNK 23 host table 443 Href 32 HTML launch page 380 HTML Layout Painter 249, 289 compound parameterized report 290 highly parameterized report creation 308 parameter controls 313 Run button 304 tool 8 HTML page options 303 HTML report 296 HTTP clients 11
L
LDAP sign-on 485 Left Outer Join 143 library list-like behavior 487 license key 19, 231 line chart 160, 298 line graph 169 date range filter 176 Log Purge Period 396 Log Purge Time 396 long-running report 466
M
Managed Reporting drivers 13 Master file 46 master file 254, 511 materialized query table (MQT) 50, 447, 473 Materialized Query tables 45 MDUNTITLED group profile 19, 90 memory usage 477 Metadata 45 metadata 6, 47 aliases 50 automatic generation or refresh 486 considerations for creation 50 deletion of 512 from Query/400 objects 430 MQT 50 prefix and suffix 433 stored procedures 50 tables 50 views 50 metadata creation i5/OS object deleted 56 miscellaneous considerations 50 multimember files 54 model 8nn system 483 MQT (materialized query table) 447, 473 MRADMIN 393 MRADMIN group 90 MRADMIN group profile 19 MRSCHEDULE 393 multi-dimensional 7 multimember files 54 multiple bars on one chart 156 multiple instance 143 multiple members 13 multiple result sets 54 multiplicative effect 443
I
i5/OS system objects 18 IBM DB2 Web Query for System i 5 IBM Query for System i 4 icons for Available fields 100 IDE (Integrated Development Environment) 15 Impact Analysis 8, 363 imported report 490 index 446, 461 Index Advisor 462, 473 Index Only Access 461, 473 Information Builders optional features 9 Inner Join 143 input parameters 492 Installation 378 installation 1718 Installing Report Broker 394 Integrated Development Environment (IDE) 15 integrated file system 12 directories 18 metadata 511 integration with Rational tools 483 iSeries Navigator, synonym management 486
J
Java 2 SDK 1.5.0_09 21 JDBC driver 384 join disablers 443 join optimization 442 join relationship 486 join segments 65 join types 143 join, table 354 joining tables 142 joins in DB2 Web Query synonyms 65 JSCOM3 22
N
named user 486 licenses 8 New form element 300 Notification 399 number of rows 491
K
Kerberos sign-on 485 key constraints 59 key performance indicators (KPI) 15
576
7214IX.fm
O
offline reporting 8 OLAP dicing 268 dimension 258 Dimension Builder 261 dimensions for database 501 drill down 258 drill-down options 267 enabled report 268 enablement 266 getting started 258 grouping data 286 hierarchy 258259 hyperlinks 258 measure 258 metadata 259 modeling view 260 pivot 258 slicing 268 Synonym menu 261 terminology 258 tutorial 257 OLAP (online analytical processing) 7, 257 OLAP Control Panel 279 OLAP dimensions 46 OLAP module 481 OLAP report on demand column sort 501 prior selections 501 on-demand paging 128 online analytical processing (OLAP) 7, 257 operational reports 15 OPNQRYF command 13 optimization 443 DB2 for i5/OS 451 disablers 466 hierarchy 441 other influencers 445 Other Files folder 32 output files for next query 429 output options 127
adapter processing and optimization 438 basics 436 benchmark for DB2 Web Query 474 case study 466 DB2 CLI adapter 436 DB2 Web Query 435 Query/400 adapter 450 remote database access 448 pie chart 184 product type for each year 184 pivot functionality 243 port 11331 for HTTP requests 484 Portable Document Format (PDF) 6 PostScript 6 Power Painter 7 building a graph 201 building a report 209 Clustered Bar chart 202 dashboard 495 Data Sources palette 200 launching 198 PDF report 217 Properties palette 200 tailoring the main window 198 Predefined Server configurations 378 prefix 49 and suffix 49 metadata 433 primary key 57 printing, double-spaced 494 product information 378, 384, 418, 480 projection 441
Q
QRYDFN edit by DB2 Web Query 433 objects 427 QSQSRVR 23 Query/400 4, 427428 5722-QU1 5 adapter 7, 450 adapter performance 450 definitions 490 functional differences with DB2 Web Query 429 functional similarities with DB2 Web Query 428 imported query 490 metadata from Query/400 objects 430 migration of reports to DB2 Web Query 489 object 490 object import 489 product history 4 reasons to move to DB2 Web Query 480 report development 490 running existing reports in DB2 Web Query 427 QWEBQRYADM 19 QWQCENT 43
P
palettes 198 parameter controls 313 parameter passing 429 parameterized report 133 design 498 multiple item selection 493 parameters, adding 290 parent report 138 parent tables 57 PC requirements 20 PC server 483 PDF (Portable Document Format) 6 distributing batch reports via e-mail 502 output 129 performance
R
ranking columns 126 Index
577
7214IX.fm
Rational tools 483 RDBMS (relational database management system) 11 Redbooks Web site 571 Contact us xvi referential constraint 57 referential integrity 442 benefits in DB2 Web Query 57 DB2 for i5/OS 486 Refresh Synonyms 487 Registered/named users 26 relational database management system (RDBMS) 11 remote database access 448 report adopted authority 485 building with Power Painter 209 creating with Active Reports 231 creation 98 development 490 development phase 491 distributing batch reports in PDF via e-mail 502 execution phase 437 layout 99 long-running 466 production phase 438 Query/400 reports in DB2 Web Query 427 request process flow 436 sample detail 114 security for specific user 485 selection defined on expression 497 tuning options 468 types 15, 133 Report Assistant 6 date formatting 109 DB2 file output 132 drill-down reports 138 Excel output 130 footings 120 generating subtotals 123 headings 120 on-demand paging 128 output options 127 parameterized reports 133 PDF output 129 ranking columns 126 report properties 141 selection criteria 110 sort by aggregate field 125 sorting 125 style sheet 491 subtotal generation 123 Report Assistant mode 379 Report Assistant route 379 Report Broker Administrator 412 Report Broker and Active Reports 415 Report Broker distribution list 405 Report Broker Schedule panel 398 report developer, SQL statements 502 Report Library 15 Report Options 399 Reporting Server 11, 13
commands 22 Reports folder 32 requirements 20 restore 504 revenue trend over time chart 167 Right Join 428 RMVWQLUSR 29 row quantity 491 RSTLICPGM command 17 Run button execution 304 Run Interval 400 Run report 35 Run Time User Enablement option 28 Run time users 26 RUNBRSCHED 416 RUNWEBQRY command 496 database file option 497 registered named user 497
S
sample detail report 114 save 504 SCHED 39 Scheduling Frequency 402 scorecards 15 second Y axis 163 securing Metadata 79 Security 74 security specific user 485 user 485 segmented metadata 80 Segmenting Metadata 79 selection 440 selection criteria 110 Sent as an attachment 400 server jobs 22 EDAPGWY 22 EDAPLOG 22 EDAPTH 22 HLISNK 23 JSCOM3 22 QSQSRVR 23 TSCOM3 22 WQLWI7 23 server operations 17 server-based processing 484 servlet container 12 servlet engines 12 SET CURRENT DEGREE 51 SET OPTION SRTSEQ 51 single instance 143 slicing 7 sort by aggregate field 125 sorting optimization 445 Spreadsheet Client 377 Spreadsheet Client Manual 382 spreadsheet reports in Excel 499 SQE (SQL Query Engine) 5, 490 SQE Plan Cache 462, 472
578
7214IX.fm
SQL catalog views 93 SQL CREATE TABLE 93 SQL fullselect 446 SQL Performance Monitor 462 SQL Plan Cache snapshot 462 SQL Query Engine (SQE) 5, 490 SQL statements, report developer 502 SQL trace 466 SQL translation 441 SQL view 468, 493 creation 445 new report 470 SQL views 45 SQL Wizard 8, 249, 369 statistics 461 stored procedure input parameters 492 Stored procedures 45 Structured Ad-Hoc Form mode 380 STRWEBQRY 393 STRWEBQRY command 22 style sheet 491 subfolders creation 34 suffix 49 and prefix 49 metadata 433 sum reports 102 summary report 99 SUPGRPPRF parameter 485 Supplemental Group (SUPGRPPRF) parameter 485 Symmetric Multi Processing 51 synonym 56, 468 individual movement 505 management 486 Synonym Candidates 48 Synonym Editor 249, 343344, 487 Synonyms, Refresh option 487 System i objects 93 requirements 21 system objects 18
U
unique join 443 upgrade to DB2 Web Query 489 Usage 379 USER 39 user authorization and verification 19 user security 485 user-specified date range parameter 181
V
variables in report headings and footings 120 verification of users 19 view 446 Viewing the Distribution log 410 virtual columns 46 Visual Explain 462, 473
W
WAB (Web Application Bundle) file 13 Web 2.0 481 Web Application Bundle (WAB) file 13 Web browser clients 12 web console 484 Web server 1112 Web-based query and report writing function 481 WebFOCUS 291 WebSphere Application Server 484 WHERE 111 WHERETOTAL 111 Windows Explorer, synonym management 486 Windows server 483 Work with Web Query 28 WQLWI7 23 WRKLICINF 29 WRKLNK command, synonym management 487 WRKRDBDIRE command 72 WRKWEBQRY 393 WSff0ad76f515651cb176dad510f7220ddaa-68e6 279
X T
table join 354 Tables/physical files 45 target table 443 time and date functionality 513 trace statements 466 traffic lighting a graph 190 conditional styling 118 TRCWEBQRY command 22 TSCOM3 22 tutorial Active Reports 229 getting started 89 OLAP 257 XML (Extensible Markup Language) 6
Y
Y axis 163
Index
579
7214IX.fm
580
To determine the spine width of a book, you divide the paper PPI into the number of pages in the book. An example is a 250 page book using Plainfield opaque 50# smooth which has a PPI of 526. Divided 250 by 526 which equals a spine width of .4752". In this case, you would use the .5 spine. Now select the Spine width for the book and hide the others: Special>Conditional Text>Show/Hide>SpineSize(-->Hide:)>Set . Move the changed Conditional text settings to all files in your book by opening the book file with the spine.fm still open and File>Import>Formats the
7214spine.fm
581
To determine the spine width of a book, you divide the paper PPI into the number of pages in the book. An example is a 250 page book using Plainfield opaque 50# smooth which has a PPI of 526. Divided 250 by 526 which equals a spine width of .4752". In this case, you would use the .5 spine. Now select the Spine width for the book and hide the others: Special>Conditional Text>Show/Hide>SpineSize(-->Hide:)>Set . Move the changed Conditional text settings to all files in your book by opening the book file with the spine.fm still open and File>Import>Formats the
7214spine.fm
582
Back cover
Follow the best practice guides to simplify report development Take your reporting to the next level of Business Intelligence Learn DB2 Web Query by using the easy to follow tutorials
The DB2 Web Query for System i product is a Web-based query and report writing product that offers enhanced capabilities over the IBM Query for iSeries (also commonly known as Query/400) product. IBM DB2 Web Query for System i includes Query for iSeries technology to assist customers in their transition to DB2 Web Query. It offers a more modernized, Java-based solution for a more robust, extensible, and productive reporting solution. DB2 Web Query provides Report Assistant, Graph Assistant, and Power Painter. Using these tools, customers can modernize existing Query for iSeries reports while providing a foundation for building more complex business intelligence applications, such as online analytical processing (OLAP), data mining, dash boarding, or data warehouse implementations. This IBM Redbook publication gives a broad understanding of the new DB2 Web Query product. It entails a group of self-explanatory tutorials to help you get up to speed quickly. Overall this book is designed for IT users. You can extract and use Part 2, Tutorials for DB2 Web Query, and Part 3, Tutorials for DB2 Web Query optional features, as stand-alone tutorials for anyone who is developing their own queries. Much of Chapter 8, Active Reports, is appropriate for those who work disconnected from the System i environment. In addition, you can use much of Chapter 10, OLAP (Online Analytical Processing), if you will simply be running OLAP-enabled reports. Include 5250. WAS Java, traditional batch, .? (Subset of Workload Estimator (WLE) workloads