Anda di halaman 1dari 138

Workshop: DB2 Web Query for i

Page

DB2 Web Query (5733-QU2) Getting Started Lab Exercises

Instructor: Gene Cobb IBM Corporation cobbg@us.ibm.com

Workshop: DB2 Web Query for i

Page

Table of Contents
Lab 1: Creating synonyms..................................................................................................................................3 Lab 2: Defining joins in your synonyms............................................................................................................7 Lab 3: Report Assistant....................................................................................................................................14 Lab 3.1: Creating Simple Summary and Gross Profit Display....................................................................14 Lab 3.2: Creating a Sample Detail Display .................................................................................................23 Lab 4: Graph Assistant......................................................................................................................................40 Lab 4.1 Creating a Bar Chart ........................................................................................................................40 Lab 4.2 Creating a revenue trend over time chart.........................................................................................46 Lab 5: Converting existing QRY/400 objects...................................................................................................52 Lab 5.1: Creating Metadata from Query/400 objects ..................................................................................52 Lab 6: Active Reports .......................................................................................................................................56 Lab 6.1: Creating an Active Report ..............................................................................................................56 Lab 6.2: Using an Active Report ..................................................................................................................60 Lab 7: OLAP (Online Analytical Processing) ..................................................................................................73 Lab 7.1: Enabling an OLAP report ..............................................................................................................73 Lab 7.2: Defining OLAP metadata using the Developers Workbench .......................................................74 Lab 7.3: Working with an OLAP-enabled report .........................................................................................83 Lab 8: HTML Composer .........................................................................................................................................................................100 Lab 8.1: Adding parameters to existing reports .........................................................................................101 Lab 8.2: Designing the layout for the HTML report ..................................................................................106 Appendix: Optional Exercises.........................................................................................................................120 Lab A: Report Assistant .............................................................................................................................120 Lab B: Report Assistant .............................................................................................................................126 Lab C: Using Web Query to enhance a QRYDFN ....................................................................................129 Lab D: Developers Workbench .................................................................................................................133 Lab D.1: Configuring Developers Workbench .....................................................................................134

Workshop: DB2 Web Query for i

Page

Lab 1: Creating synonyms


Before you can develop a single report or graph in DB2 Web Query, you must create metadata (also referred to as a synonym) over the DB2 for i database files that you will be querying. DB2 Web query metadata is an abstraction layer that contains information about the files and their fields that you will be querying (think of it as repository of information that is similar to what is generated when you issue the DSPFD and DSPFFD commands or when you query the system catalogs). These synonyms reside in the Integrated File System (IFS) and are read by DB2 Web Query to gather relevant information about the underlying files before the files themselves are actually queried. Because it is an abstraction layer, business logic can be built into the metadata. Defined fields, join logic, and filters are all examples of logic that can be stored in the metadata. For example, gross profit margin is a calculated field (based on other fields) and typically is not stored in the database. As such various programmers in your company may have different formulas for calculating this value. The metadata layer removes this potential ambiguity by allowing you to centralize and standardize key formula-based business information. A DB2 Web Query domain is a container which holds all of your reports and graphs and is secured using IBM i group profiles. Only members of the group profile associated with that domain have access to the folders, sub-folders, reports, graphs, and other files within that domain. This implementation locks down the reports and graphs, but what about the metadata? For a secure metadata environment, application folders are used. An application folder is a container for the metadata (synonyms) and can be set up to be an extension of the domain. Only members of the group profile associated with that domain have access to the metadata in the associated application folder. Domains can be set up to have multiple application folders. For this lab, a domain and an application folder have already been created for you. To keep it simple, they are named as follows: Domain: webqryXX (where XX = your team number) Application Folder: webqryXX (where XX = your team number) In this exercise, you will create a new DB2 Web Query synonym based on a table (physical file) in the DB2 for i database. This synonym will be created in the application folder set up just for you. Consequently, no other lab student has access to your synonym (and you will not have access to theirs). So lets get started! 1. Find the DB2 Developer Workbench icon on your desktop and click on it to open Expand WebFOCUS environments and select the name of your system (name provided in student worksheet handed out by lab instructor) Log in with your team id: i. User ID: QRYUSRxx (where xx is your team number) ii. Password: passw0rd iii. Click Logon button

a. b.

Workshop: DB2 Web Query for i

Page

2. Expand Managed ReportingDomainswebqryXXApplications 3. Under Applications, right-click on application folder webqryXX and select NewSynonym

4. Under Configured Adapters: a. Expand DB2 cli b. Select *LOCAL (the local IBM i system where the tables reside) and click OK. Note: There are three types of System i objects that you can query with the DB2 Web Query product: i. DB2 for i5/OS refers to the majority of your tables created with either an SQL CREATE TABLE statement or by using DDS and a CRTPF command. ii. DB heritage files refers to files that have multiple record formats or multiple members. Files described by this adapter will utilize the OPNQRYF command on the IBM i. This

Workshop: DB2 Web Query for i

Page

directs the query to the older, and typically slower, database optimizer (CQE) iii. Query/400 imports existing Query/400 definitions and converts them to both table and report definitions.

5. Under Further restrict search to: a. Make sure Tables is selected. b. Click the Views checkbox to de-select it. Note: This results in a nice, concise list of only your physical files or tables. If you have SQL views or logical files you wish to query, the Views checkbox must be selected. If the library is an SQL collection or schema, selecting Views also displays the SQL catalog views. c. For the Library specify QWQCENT d. Click Next

6. You see a window with a list of tables in library QWQCENT. Specify the following: a. For Prefix, specify CEN_ Note: This causes the table names to be displayed with a CEN_ prefix (for example, CEN_ALERTS, CEN_ORDERS, etc.) If you have a long list of table names, this is a way to keep all related tables grouped together. b. Select Overwrite existing synonyms (Note: you may have to use the vertical scroll bar to see this setting) c. From the list of files, select the ORDERS table

Workshop: DB2 Web Query for i d. Click Create synonym.

Page

7. Your synonym for the ORDERS table has been created. Click Close to continue.

8. Back in the Developer Workbench Explorer window, you see two files in the webqryXX folder: cen_orders.acx The access file for the synonym. Contains file level information such as the library that the file resides in. cen_orders.mas The master file for the synonym. Contains information about all of the fields in the file.

Workshop: DB2 Web Query for i

Page

Lab 2: Defining joins in your synonyms


Notice that we (so far) have created a DB2 Web Query synonym over a single file (ORDERS) in our database. In most production environments, the database and the reporting requirements are much more sophisticated than that. Most databases have information dispersed across multiple files and these files need to be joined together to make your reports accurate and meaningful. In this exercise, you will learn how to describe your file relationships to DB2 Web Query by defining joins in the synonyms. Because the joins are defined at the synonym level, you only have to do this in one place. Every report that uses this synonym will have access to the join logic already defined, thus it is not necessary to define the joins in each report. This is an example of the power of the metadata abstraction layer. 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 oneto-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 we use Unique join types. 1. Create new segments a. Right-click on the cen_order.mas file and select Edit in Synonym Editor.

Once in the tool, we want to add new join segments to the ORDERS file. For this we will create new segments using the metadata import function. b. Right-click cen_orders and select AddSegment Via Metadata Import

Workshop: DB2 Web Query for i

Page

You see the Create Synonym dialog window. c. Under Configured Adapters, expand DB2 cli, select *LOCAL and click on OK.

d. Under Further restrict search to: Select Tables, de-select Views, and specify library QWQCENT. Click Next

Workshop: DB2 Web Query for i

Page

e. For Prefix, specify CEN_ and select the files INVENTORY, PLANT, and STORES. These are the files you will join to the ORDERS file. Click the Create Synonym button.

You see a confirmation window indicating that the synonyms were successfully created.

Workshop: DB2 Web Query for i f. Click the Close button.

Page

10

2. Define Join Properties Now that the synonyms for the join segments have been created, you must define the fields that join the files to the ORDERS tables. a. Select and right-click on CEN_stores. Select Join Properties

b. STORECODE is the field that is used to join ORDERS to STORE. Select this field under both tables and click the map button. (located between the tables lists) This will bring the join formula into the Expression pane. Make sure Inner Join is selected for the Join Type. Click OK to continue.

Workshop: DB2 Web Query for i

Page

11

c. While segment CEN_stores is still selected and under Attribute, change the join segment type (SEGTYPEType) settings from Multiple (the default) to Unique.

Workshop: DB2 Web Query for i

Page

12

Once you have done this, the icon next to the CEN_stores segment becomes a red color 3. Click the Save icon to save your synonym

4. Repeat steps 2a 2c for the CEN_Inventory segment. The join field for this join is PRODUCTNUMBER 5. Repeat steps 2a 2c for the CEN_Plant segment. The join field for this join is PLANTCODE When you are finished, you have created a cluster for the ORDERS table. The segments of this cluster should look like this:

Workshop: DB2 Web Query for i

Page

13

6. Click the Save icon to save your synonym

7. Close the DB2 Web Query Developer Workbench window.

Workshop: DB2 Web Query for i

Page

14

Lab 3: 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 the data; include record selection criteria; add headings, footings, subtotals, and page-breaks; apply a style template; and more.

Lab 3.1: Creating Simple Summary and Gross Profit Display


In this lab you create the two reports shown below. The first report is a simple summary showing revenue by product type. The second report is a more detailed report calculating gross profit for each product category within a specific user-requested product type. Finally you enable a user who is viewing the initial summary report to click on product type and automatically drill down to see the more detailed gross profit report.

Signing on and creating a folder


c. d. 1. Open a Web browser and sign on Go to http://i5os02.sealinc.org:11331/webquery Log in with your team id: i. User ID: QRYUSRxx (where xx is your team number) ii. Password: passw0rd

Workshop: DB2 Web Query for i

Page

15

a. b.

2. Create a folder for the reports Expand Domains your domain (webqryXX) Reports1: Getting Started Labs. Right-click the Reports folder and select New Folder. Key Folder Name: Manufacturing Reports and click Save.

Creating the summary report


Your first reporting task is to show the product revenue for each product type. All of your reports and graphs in this lab will be stored in your webqryXX domain under the Manufacturing Reports folder you just created. 1. Right-click the Manufacturing Reports folder where you will store your report and select Report Assistant. This displays a list of available tables for you to query. 2. Select the CEN_ORDERS table and click OK. Tip: Typing the first character of the table name jumps to the tables starting with that character.

Workshop: DB2 Web Query for i

Page

16

Defining a report layout


After selecting the CEN_ORDERS table, you see a list of all the column or field names. Note that the displayed fields come from various tables that you earlier created join segments for in the ORDERS synonym. This results in the composite list of fields shown below. 3. To see the actual table or segment names drag the sides of the window to widen it. Note: 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 being a calculator icon hierarchy icon (New define field). To its right is the dimension or (Tree) which will show the fields within each individual table. The rightmost icon

(List), will show all the fields from all the tables in one long alphabetical list. 4. Drag PRODUCTTYPE from the list of available fields on the left and drop it in the Sort by box in the center of your screen. Tip: If you are using the Firefox browser, you may not be able to drag and drop. In this case you will need to first click on the box to receive the field (Sort by) and then double-click the desired field name in the field list. 5. Drag LINETOTAL from the list of available fields and drop it in the Sum, Print box on the right. LINETOTAL is the gross revenue for each line item on an invoice. 6. Click the Add grand totals to the end of the report checkbox to select it.

Workshop: DB2 Web Query for i

Page

17

7. Click the Run arrow to produce your first report. A new browser window is launched and your first report is displayed:

8. Close the browser window with the report. This will return you back to the Report Assistant dialog window. 9. Save your report, naming it Revenue by Product Type.

Workshop: DB2 Web Query for i

Page

18

Next you will format LINETOTAL, and add a count of the number of orders for each product type. 10. Highlight the LINETOTAL field in the Sum, Print box and open the Field options - LINETOTAL dialog near the bottom of the screen.

Workshop: DB2 Web Query for i

Page

19

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 you are working with a sort field, you have additional capabilities to control the sort, add ranking columns, and control the subheadings and subfooting. 13. Click the ellipsis (three dots) to the right of the Format in report as window. 14. Change the LINETOTAL field to be displayed with Comma inclusion and Floating currency (you may need to scroll down to see both options) and click OK.

Workshop: DB2 Web Query for i

Page

20

15. On the Field selection tab ensure that LINETOTAL is highlighted. Then make sure the Field options LINETOTAL dialog is open and select the Title tab.

Notice that the Title is Revenue. This panel is where you can 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 DB2s heading attribute into the metadata attribute Title. The last thing we are going to do with this summary report for now is add a count of the number of orders for each product type. 16. Drag ORDERNUMBER from the field list on the left to the Sum, Print box. 17. Open the Field options ORDERNUMBER dialog if it is closed. Under the Display tab, select Count from the Calculated as drop-down list.

Workshop: DB2 Web Query for i

Page

21

Note: If you dont see a long list of field options, including Count, verify that your report is a summary report and not a detail report -- in other words, that Sum and not Print is highlighted.

18. Change the field format to integer, 7, and Comma inclusion - C using the ellipsis button and click on OK.

Workshop: DB2 Web Query for i 19. Select the Title tab. 20. Change the title to Order Count on two lines.

Page

22

Workshop: DB2 Web Query for i 21. Using the up and down arrows LINETOTAL.

Page in the Sum, Print box, move CNT.ORDERNUMBER above

23

22. Click the blue arrow

to the right of Run at the top of the screen to run the report.

23. Save your report and close Report Assistant.

Lab 3.2: Creating a Sample Detail Display


In this section you will create a parameterized report where the user selects, at run time, the product type they wish to query. You will also be able to drill directly to this report from the Revenue by Product Type report we initially created. 1. Right-click the Manufacturing Reports folder and select Report Assistant. 2. Select table CEN_ORDERS and click on OK.

Workshop: DB2 Web Query for i

Page

24

After you have chosen your table you are presented with a list of all the column or field names belonging to that table or cluster of tables. 3. Drag and drop PRODUCTTYPE and PRODUCTCATEGORY into the Sort by box. NOTE: Make sure PRODUCTTYPE is listed before PRODUCTCATEGORY. 4. Drag and drop LINETOTAL and COSTOFGOODSSOLD into the Sum, Print box. 5. Click the Add grand totals to the end of the report checkbox.

6. In the Field options panel use the ellipsis button to add commas to the formatting of LINETOTAL, and COSTOFGOODSSOLD.

Workshop: DB2 Web Query for i

Page

25

Workshop: DB2 Web Query for i

Page

26

Define and compute fields


You now create a gross profit field by subtracting the COSTOFGOODSSOLD from the LINETOTAL. 7. Select the calculator icon above the field list to create a define field.

Note: There are two ways to create calculated fields in DB2 Web Query. When you use the define field you are adding the definition to the list of fields within the table. This field is calculated every time a record is read and selected. Beside the Sum, Print heading is a picture of a wizards wand . This allows you to create a computed field. In this case the field isnt calculated until after the data is sorted and all aggregation is complete. Computed fields are often required for percentages and variances. The right panel can be used to display the precoded functions that are available or to display the list of fields either alphabetically or in a hierarchical structure: file then field name. Try the different buttons. 8. Enter a field name of Gross_Profit. 9. Select the list icon in the upper right. This displays the list of available field names alphabetically. 10. Create the formula LINETOTAL minus COSTOFGOODSSOLD by double-clicking the field names and using the - button on the calculator pad or on your keyboard. Note: If you use your keyboard, be sure to include a space after the -. Tip: Field names in the defined field definition panel must all be in upper case. 11. Click the Format button for Gross-Profit and define your field as being an integer, 10, long, with commas and a floating currency. Then click on OK.

Workshop: DB2 Web Query for i

Page

27

Tip: When creating your own reports ensure that the field length is large enough to handle the commas, dollar sign and the maximum digits possible. 12. Click OK and then drag and drop Gross Profit into the Sum, Print box.

13. Verify that the Gross_Profit field is highlighted and open the Field options Gross_Profit dialog near the bottom of your screen. Select the Title tab. 14. Label the column Gross Profit on two lines.

Workshop: DB2 Web Query for i

Page

28

Generating subtotals
Next you add subtotals for each product type. 26. Under the Sort by pane, highlight PRODUCTTYPE and make sure that the Field options PRODUCTTYPE dialog is open. 27. Select the Sorting tab and check Subtotal numeric sum/print fields.

Workshop: DB2 Web Query for i

Page

29

28.

Run the report again.

29.

Close the browser window displaying the report.

30. To change the default subtotal heading (*TOTAL) make sure that PRODUCTTYPE is highlighted. Go to the Field options - PRODUCTTYPE display and select the Subtotal tab.

Workshop: DB2 Web Query for i

Page

30

31.

Key your new subtotal heading Subtotal for.

Tip: By default all columns are added to create a total line. You can override individual columns and request that instead of summing the column, the total line should display the result of calculations such as a count of values or the average of the values. Look at the options for Sum under Prefix. 32. Save the report as Gross Profit Report and run the report.

Workshop: DB2 Web Query for i

Page

31

MS Excel Output
There are many possible output formats for your report. Note: In the appendix there are optional labs for testing additional output options such as PDF and On-demand paging. 33. From the Report options tab view the options in the drop down box Generate report as. Changing the selection in the second drop-down list to the right changes the output choices in the first list. Select EXL2KFORMULA - Excel w/formula.

34. Rerun your report. Note: Should you receive the Opening WFServlet dialog box, select Open with Microsoft Office Excel (default) and click on OK.

Workshop: DB2 Web Query for i

Page

32

Notice the Subtotal for Camcorders. If you look at the Excel input line you see that this is represented as a formula as opposed to an actual value of $103,516,731. This is a very nice 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. 35. Close the Excel spreadsheet without saving it and change the output back to HTML Web browser and save as Gross Profit by Product Type.

Parameterized reports
End-users have requested to be able to print the gross profit ranking report for a single product type requested at runtime. To do this you must add an input parameter. 36. Go to the Selection criteria tab. 37. Drag the PRODUCTTYPE field onto the empty Screening conditions panel on the right. 38. Click <Select values> to define the parameter. 39. Select Parameter and then click the Auto Prompt icon .

Workshop: DB2 Web Query for i

Page

33

40. Ensure that your selection is Dynamic. For Description, enter Select product type:. Accept the default name for this parameter -- PRODUCTTYPE. Be sure the Data Source: is CEN_ORDERS and Field: is PRODUCTTYPE. Click OK twice.

Workshop: DB2 Web Query for i

Page

34

Note: Choosing Dynamic selection presents the users with a distinct list of current values for the column when the query is run. Static 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 accept the default of allowing a single input value. To make the drill down report more understandable we need to include a report heading containing the product type. NOTE: You must be using Internet Explorer as your browser to complete this next section. 41. Under the Report headings tab enter the Page heading Gross Profit by Product Category for Type . 42. Click the Show - Field list arrow on the left and drag PRODUCTTYPE to the end of the heading. 43. Add date and time of day information to the bottom of the page. Enter the Page footing Prepared on &DATE at &TOD NOTE: &DATE and &TOD are system variables that represent the current date and current time respectively.

Workshop: DB2 Web Query for i

Page

35

44. Save this report as Gross Profit by Product Category and run the report.

45. Close Report Assistant. You now have a report that accepts either a parameter passed by another report or a value entered by the user.

Workshop: DB2 Web Query for i

Page

36

Drill-down reports - parent report


We are going to take our initial Revenue by Product Type report and enable it to pass an individual product type to the report we just created. 46. On the DB2 Web Query home page, right-click the original Revenue by Product Type report and select Open. 47. In the Sort by box, highlight PRODUCTTYPE; then open the Field options PRODUCTTYPE dialog and click the Drill down button.

48. Select the Execute procedure radio button. DB2 Web Query then populates the list with your reports. Navigate through the list and select your Gross Profit by Product Category report. 49. In the Alternate comment box enter Click to drill down to Gross Profit Report for users to see when they hover over the Product Type field. 50. Click Add.

Workshop: DB2 Web Query for i

Page

37

51. Key the name of the Parameter the drilldown report is expecting. In this case, PRODUCTTYPE. 52. Select the Field that you want passed into the parameter -- PRODUCTTYPE.

53. Click OK twice 54. Save your report as Revenue by Product Type with Drilldown. Remove the check mark in the Prompt for parameters and Show on users list options and click on OK.

Workshop: DB2 Web Query for i

Page

38

55.

Run your report.

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 detailed report. 56. Drill down (single-click) Audio.

Workshop: DB2 Web Query for i

Page

39

57.

Close the report and close Report Assistant.

CONGRATULATIONS you have finished the first and the longest set of labs. Wasnt it easy and wasnt it fun?

Report Assistant Summary


You have now completed the first major lab and created multiple reports. Many of the remaining labs modify these reports. The steps will still be listed but in far less detail. If you forget how to accomplish a function, simply return to this lab for a refresher. Happy reporting! List of reports created in this lab so far are: Revenue by Product Type Gross Profit Report Gross Profit by Product Type Gross Profit by Product Category Revenue by Product Type with Drilldown

Workshop: DB2 Web Query for i

Page

40

Lab 4: 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 through histograms and area charts, stock charts, gauges for key performance indicators and much more. In this lab you continue using the same webqryxx database from the previous labs and do the following: Create a simple bar chart showing revenue by product type within country. You will drill down from this graph to the detail report that we created previously with Report Assistant.

Lab 4.1 Creating a Bar Chart


In this exercise, you will create a bar chart that allows the user to drill down to a previous report.

Lab 4.1: Creating a simple bar chart with drill down capabilities
1. Right-click the Manufacturing Reports folder and select Graph Assistant. 2. Select the same CEN_ORDERS table you used in the previous labs.

Workshop: DB2 Web Query for i

Page

41

When you do this, you are presented with a list of the different types of graphs you can select from. 3. Click the Graph types pull-down and look at the various chart types available. For each chart type there are many variations shown under Graph Styles. 4. For this exercise choose a Bar type and select Clustered as the style. Look at the various different templates. Select Cylinder on grey for the template.

Next you define the fields representing the x and y axes for the chart. 5. 6. 7. 8. Click the Field selection tab. Drag LINETOTAL onto the Sum panel. This is your Y axis. Drag COUNTRY onto the X axis panel. Drag PRODUCTTYPE into the separate graph area box. By default this produces one chart for each

Workshop: DB2 Web Query for i separate product type.

Page

42

Adding multiple bars to one chart


9. Ensure that PRODUCTTYPE is still highlighted in the separate graph fields panel. 10. Open the Field options PRODUCTTYPE dialog and select Merge graphs into a single graph. Instead of having a graph for each product type, this causes a merge of the graphs so that each type is a separate bar within each country. Graphs can have headings both at the page level and at the individual chart level.

11. Select the Headings tab; then select the Graph tab. Give your chart the title Revenue by Product Type and the subtitle Country Comparison.

Workshop: DB2 Web Query for i

Page

43

12. Save your graph as Revenue by Product Type Graph and then run it.

Adding a drill down to your chart


Now that the chart is created, you should enable the users to double-click any of the bars and drill down to the detailed product type report you created earlier. 13. Return to the Field selection tab, highlight LINETOTAL and click the Drill down button under the Field Options tab.

Workshop: DB2 Web Query for i

Page

44

14. Click Execute procedure; a list of your reports is shown in the top white panel. 15. Navigate to and select the Gross Profit by Product Category report that you created earlier. Once you have selected your procedure, the Add button becomes available. Click Add to add the parameter that you want to pass from this report to the Gross Profit by Product Category report.

16. Select Field PRODUCTTYPE (the field that you want to pass as the parameter value) and then enter the Parameter name. This name must match the name that the Gross Profit by Product Category report is expecting to be passed. You accepted the default PRODUCTTYPE for this parameter name (the input column name).

Workshop: DB2 Web Query for i

Page

45

17.

Click OK twice, save the graph and then run it.

Drill down explained: When you drill down from one report to another, the child report is expecting a parameter to be passed. In your case this was PRODUCTTYPE that was linked in the Gross Profit by Product Category report to the PRODUCTTYPE field. In the parent report or graph, you indicate where the users can drill down. In this graph you said that the users could drill down on any LINECODE or bar. When they clicked a bar, you told the system that you wanted the Gross Profit by Product Category report to be run. You also indicated that you were going to pass the PRODUCTTYPE field referenced by the selected bar. You did this by passing the value as a parameter called PRODUCTTYPE. Since this is the name of the parameter the report was expecting, it accepts the value and runs the report. 18. Roll over the bars with your mouse. You should see the cursor change from an arrow to a hand. The hand indicates that you can drill down in this area. When you hover over a bar, you see information in a small pop-up window that shows you details about the bar. You see the product type, country, and revenue or line total.

26. Drill down on Camcorders in Canada.

Workshop: DB2 Web Query for i

Page

46

27. Save the report

Lab 4.2 Creating a revenue trend over time chart


In this lab, you start by creating a simple line chart spanning all the available data.

Creating a line graph


1. Reports folder and select Graph Assistant. 2. table you used in the previous labs. Right-click your Manufacturing Select the same CEN_ORDERS

Workshop: DB2 Web Query for i

Page

47

Look at the various choices for line charts. 3. Absolute. Select Graph type as Line ->

To show product revenue trending over time, it is necessary to plot one point for every month for each product. To do this, the date field must be converted from year, month and day to a field with just the year and month. 4. 5. a new field. Go to the Field selection tab. Click the calculator button to define

Workshop: DB2 Web Query for i

Page

48

6. Name your new field MthYr. 7. In the panel where you define the formula for the new field, simply enter the name of the date it is based on, ORDERDATE. 8. Specify a Format of TMYY. T means that the month or day immediately following is represented as upper case text. YY means that you want the year formatted as a four-digit value. An example for MthYr is Jan, 2003. Note: A single Y would have meant to display a two-digit year. If we had wanted to put the year first we would have specified a format of YYTM. DB2 Web Query is very powerful when it comes to working with date and time fields. 9. Click OK.

The chart being created will have one line for each product type with a data point for LINETOTAL for each month in the data.

Workshop: DB2 Web Query for i

Page

49

10. Drag and drop MthYr to the X axis box, LINETOTAL to the Y axis box, and PRODUCTTYPE to the Create a separate graph for each value of this field box. 11. Open the Field optionsPRODUCTTYPE dialog and select the option to Merge graphs into a single graph.

Since an entry on an axis of Jan, 2007 is obviously a date, the heading or label for MthYr can be removed from the graph. 12. window. 13. dialog and delete the label MthYr. Highlight MthYr in the X axis Open the Field options - MthYr

Workshop: DB2 Web Query for i

Page

50

14. Revenue Trends. 15.

Save your report as Product Run your report.

Lets make the X axis look a little better. 16. Select the Properties tab and then select the X axis tab that opens up. 17. Select Style labels. 18. Set Style for: Data. Note: If some of the options are not available, it is because a default style sheet is in effect. In that case check the box at the top that allows overriding the defaults. 19. Change the Text rotation to 45-degree bottom to top and click OK.

Workshop: DB2 Web Query for i

Page

51

20. Save and run your report.

Workshop: DB2 Web Query for i

Page

52

Lab 5: Converting existing QRY/400 objects


Lab 5.1: Creating Metadata from Query/400 objects
Just as Web Query requires metadata to read from DB2 files, it also requires metadata to read from Query/400. When creating metadata on QRYDFN objects, there are a few extra screens you must remember to finish; otherwise the metadata creation will not be complete. As noted earlier, if you change the format of your underlying files, you must re-create the metadata on those files. If you change the QRYDFN on the server side, you must recreate the metadata on that QRYDFN. The process of creating metadata on a Query/400 object actually runs the query because it is gathering information on the files and columns used in query output. For this reason, creating metadata for a Query/400 object may require more time than it takes for a DB2 table. DB2 Web Query asks for the library name where your Query/400 objects are stored. You can choose to create metadata for all queries in a library in a single execution. The following screen shots walk you through the process of creating metadata for Query/400 objects. There are two additional screens related to creating metadata for a Query/400 object versus a DB2 object. Just make sure to click Next until you no longer see a Next button to click. 1. First open the Manufacturing Reports folder in your domain and select Metadata.

2. First you must select which adapter to use in the left panel. Right-click Query/400 and select Create Synonym.

Workshop: DB2 Web Query for i

Page

53

3. In the Create Synonym dialog box, enter the QWQCENT, the library where the QRYDFN objects reside. Then click Submit.

4. 5.

Key a Prefix of CEN_ and click on the Default Synonym Name REVGPFTQRY to select it. Click Create Synonym.

6.

Click Next on the Status screen.

Workshop: DB2 Web Query for i

Page

54

7.

Click Next on the Save Reports screen.

8.

Click Finish on the Save Reports Status screen.

You are returned to the DB2 Web Query home page where you can see the metadata for your QRYDFN object is already created as a report. You can simply click this report to run it or right-click it to see editing options. 9. Click the report to run it.

Workshop: DB2 Web Query for i

Page

55

10.

Compare it to the original report below.

As you can see, its easy to import and enhance existing AS/400 Queries. Note: The optional lab Lab C: Using Web Query to enhance a QRYDFN adds traffic lighting to the imported Query/400 report.

Workshop: DB2 Web Query for i

Page

56

Lab 6: Active Reports


Active Reports allows users to interact with their reports and work disconnected from the System i. Active Reports is well-suited for the mobile worker who is frequently disconnected from the Web. With Active Reports you can create a variety of simple or advanced charts (pie, line, bar, or scatter), roll-up analysis, or pivot reports. You might want to allow your sales reps to analyze the buying patterns for the clients they plan to visit that day. Your service reps might want to view the service history of a customer before making a call. You might even choose to e-mail reports to your customers or partners, detailing their activities with you. The end-user of an Active Report requires no special software, and there are no licensing fees for end-users.

Lab 6.1: Creating an Active Report


You will modify the Gross Profit Report that you created in Lab 3.2: Creating a Sample Detail Display to enable it to be used when the end-user is either not connected to the server or wishes to have some basic capabilities to modify reports. The only requirement for Active Reports is that the server be properly licensed. There are no end-user requirements. 1. Open a browser to the DB2 Web Query home page: Note: you must use Internet Explorer to complete this lab. http://i5os02.sealinc.org:11331/webquery 2. Expand webqryxxReports1. Getting Started Labs Manufacturing Reports folder. 3. Right-click Gross Profit Report and select Open.

4. From the Report options tab, change the report type to AHTML - Active Report.

Workshop: DB2 Web Query for i

Page

57

5. Run the Report.

Now you will make a few formatting and highlighting changes. 6. On the Report Options screen click the Active Report Styling button which became active when you selected AHTML - Active Report.

Workshop: DB2 Web Query for i

Page

58

7. For this example, make sure that Report view is Tabular and change the Row selection colors to Yellow for Hover, change the Visualization colors to Red for Negative numbers and Orange for Positive results, and click OK.

All you are doing here is affecting the initial look of the report for the end-user. 8. Save your report as Gross Profit Active Report and run it.

Workshop: DB2 Web Query for i

Page

59

9. Click a drop-down arrow next to the heading for any column and choose Save Changes. Click Yes to the ActiveX caution, if presented. Note: The Save changes menu option is NOT available in the Firefox browser.

10. Save your report as c:\Gross Profit.html.

Workshop: DB2 Web Query for i

Page

60

You can optionally use your browsers Save As option to save the HTML page, as follows:

Note: If you use Export instead of Save Changes you are exporting the records without formatting and controls. The records can be exported to an HTML page, MS Excel, and CSV files. Tip: Once you have saved your report as an HTML file, it can be e-mailed to end-users. In this case the recipient would be able to view and analyze the report with no connectivity to the System i. In the next lab you continue to work with this Active Report, but you do so as if you were the disconnected user rather than the developer.

Lab 6.2: Using an Active Report


When a user receives an Active Report, they simply open it in their browser. Once received, the user can If you to running i. perform various types of analysis on it without connectingare a System short of time, you can locate your Note:

Running out of time???

1. Close Web Query browser windows. 2. As an end-user, locate your Gross Profit.html page in C:\ and launch it with Internet Explorer.

Gross Profit.html page in C:\ and save it to a memory stick (or ask the instructor Active Reports use ActiveX controls. Based on your browser security settings, youto email this may see warning html file to you). You can then complete the messages, and you may be asked if you wantremainder of this content. of the lab at home.Allow to allow blocked section In this lab, always All you blocked content need is a web browser - DB2 Web Query is not required for this.

Workshop: DB2 Web Query for i

Page

61

Note: If you are connected to the System i you could also go to the DB2 Web Query home page, navigate to the report and run it. The first thing to do is to analyze the product categories, evaluating gross profit compared with revenue (LINETOTAL). 3. Click the drop-down arrow next to Gross Profit and select Sort Descending.

To make the report better fit the page, hide the Cost of Goods Sold column.

Workshop: DB2 Web Query for i

Page

62

4. Click the drop-down arrow next to Cost of Goods Sold and choose Hide Column.

Next, you Visualize a column. This is a very powerful tool that allows you to see, at a glance, relationships between various columns. 5. Select the drop-down list for the Gross Profit column and click Visualize. This displays colored bars in the chart below. Visualize provides a quick, visual representation of the data in a column.

Workshop: DB2 Web Query for i

Page

63

6. Now Visualize the Revenue column also.

With the visualize bars, it is much easier to spot relationships. Notice that although speakers wouldnt have ranked very high in revenue they are extremely profitable and generate the third highest profit of any Product Category. 7. From the Gross Profit drop-down list, choose Calculate -> % of Total.

Workshop: DB2 Web Query for i

Page

64

8. Notice the new column which shows each Product Type row as a percent of the total Gross Profit in this report.

9. Finally go back to your Calculation selection for Gross Profit and this time select Sum. Your summary will print at the top of the page.

Workshop: DB2 Web Query for i

Page

65

Next you temporarily filter the report to concentrate on audio sales. 10. Select the drop-down menu for Product Type and choose Filter -> Equals.

Workshop: DB2 Web Query for i

Page

66

11. Clicking the drop-down arrow on the right gives you a list of the distinct values in the field. Choose Audio and then click Filter.

Note: Besides 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. 12. In the filtered chart you see both your filtered sum and the total sum for a column. In the upper left corner is a new icon SUB/TOT. Try clicking this icon. It cycles you through three views: the sum of all your data; the sum of your filtered data; and having both sums displayed concurrently.

Workshop: DB2 Web Query for i

Page

67

Note: If instead of clicking the Filter button in the Filter Selection window, you had clicked the Highlight button, your report would contain all the records but the ones meeting the filter criteria would be highlighted. At any point in time, you can choose the Restore Original option from a drop-down list to return to the original display. To see all the records, simply close the Filter Selection dialog box. A helpful way of analyzing the data often involves changing the grouping and looking at your numbers slightly differently. 11. Close the Filter Selection window. 12. Select the Gross Profit drop-down and choose Rollup -> Group By (X)(SUM) Product Category.

Workshop: DB2 Web Query for i

Page

68

13. Now click the Pie chart graph icon (third from left) to change the report you are looking at into a pie chart. You could have chosen line or bar charts also.

Workshop: DB2 Web Query for i

Page

69

Note: You could have produced the same graph directly from your full report by clicking the Gross Profit drop-down arrow and selecting Chart -> Pie -> Group By (X) Product Category. Tip: If you had created filters, then plotted your graph, and then closed the filter, by default your graph would change to reflect the displayed report or all the data. To keep the chart displaying the filtered data, select the Lock icon (second from the right). 14. Click the List icon (leftmost) and select Export to -> Excel.

Workshop: DB2 Web Query for i

Page

70

15. Close MS Excel and close the charting window. If you have time at the end of the lab experiment with the Pivot or Cross Tab functionality of Active Reports. Again this is accessed via the drop down menu selected at a field level. Before leaving Active Reports, lets take a quick look at the difference between a Tabular and Accordion Active Report. 16. If your report definition is closed, go to the DB2 Web Query home page, right-click and Open Gross Profit Active Report. Subtotals should be removed for tabular reports. 17. Select the Field selection tab, highlight PRODUCTTYPE in the Sort by panel, Select the Field options display and then the Sorting tab. Remove the check from Subtotal numeric sum/print fields.

Workshop: DB2 Web Query for i

Page

71

18. Select the Report options tab and click the Active Report Styling button. 19. Select Accordion instead of Tabular, click OK and Run.

Workshop: DB2 Web Query for i

Page

72

20. Expand Audio (click the plus (+) sign).

You now see all the Product Categories within Audio. If there were more Sort By columns in the report, you could keep going, expanding down each of the levels. Take a look at some of the other options available under the drop-down arrows. You see that you can export data to CSV files, to HTML files, and directly into MS Excel. If you have filtered the data, you have the choice of exporting the entire dataset or just the filtered records.

Summary: Active Reports is a tool that works extremely well when your end-users are remote and not connected to the IBM i. It gives you the ability to perform sophisticated data analysis, manipulation, and charting all while in a completely disconnected mode.

Workshop: DB2 Web Query for i

Page

73

Lab 7: OLAP (Online Analytical Processing)


Online analytical processing (OLAP) is best known as the technology that allows a user to slice and dice their data or drill down into their data. DB2 Web Query makes it easy to provide users with a sophisticated drill-down, slice and dice interface without the report developers having to do anything at all. You should have a better understanding of this concept by the time you finish this lab. After taking a standard report created with Report Assistant, the report developer selects an output option to OLAP-enable the report. This automatically provides an interface with drop-down lists and drill capable columns that allow the user to slice and dice or pivot their data and perform a variety of local analysis on the original report. Before OLAP can be used in a report, the referenced tables must have any embedded hierarchies predefined using Developer Workbench. After this is done, the users have an easy and intuitive way to navigate and drill down on the hierarchy within their data. You will define OLAP dimensions and embedded hierarchies as part of the exercise in Lab 7.2: Defining OLAP metadata using the Developers Workbench. OLAP analysis typically starts with a question such as What were my regional sales numbers across the United States? At this point, you might look at the numbers and ask to see the details for the Eastern region which looks out of line with the other regions. If you then find that a single state is pulling down the region you might ask to see the revenue for that state split out by the different product groups you sell. After you find a product group that appears to be in trouble, you might ask to see the sales for that product group in that state summarized by month for the last two years. This type of analysis is sometimes called Having a conversation with your data. It is OLAP technology that enables this quick and easy interaction with the data. A user could have created a separate ad hoc query for each of the above questions but that would probably not occur in real life. If a user simply had to click a specific field of interest to go down to the next level of detail, they would be far more likely to continue with their analysis.

Lab 7.1: Enabling an OLAP report


1. Open (not Run) your original Revenue by Product Type report in your Manufacturing Reports folder. 2. Select the Report options tab. 3. From the Enable OLAP drop-down list, select Show Tabbed.

Workshop: DB2 Web Query for i

Page

74

4. From the Automatic drill down drop-down list, select Dimensions and Measures. This gives you the maximum drill down capabilities. Note: The most common choice for Automatic drill down is probably just Dimensions, not the Dimensions and Measures that we are using in the lab. 5. Save your report as OLAP Revenue. Make sure Run with OLAP is selected in the Save Standard Report dialog window (it should already be selected).

Your report is now OLAP-enabled. To summarize, you 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.

Lab 7.2: Defining OLAP metadata using the Developers Workbench


The first thing that must be done before a user can enable a report for OLAP is to define any hierarchies that are present in the data. This is done once by a developer and is then automatically used by DB2 Web Query whenever a user requests OLAP-enablement for a report that references tables containing these hierarchies. 1. Start Developers Workbench and expand down the following tree: WebFOCUS Environments -> <system name> 2. Logon to DB2 Web Query and continue down the tree.

Workshop: DB2 Web Query for i

Page

75

3.

Expand Managed Reporting Domains WebQryXX Applications webqryXX.

Remember that the term synonym is synonymous with metadata. To define a hierarchy, you must edit the metadata for a table. This is done through the Synonym Editor. 4. Right-click the table cen_orders.mas and select Edit in Synonym Editor.

Workshop: DB2 Web Query for i

Page

76

Note: Notice that the window you just opened shows four tables: ORDERS, INVENTORY, PLANT, and STORES even though you opened only the master file or metadata for the ORDERS table. This is because you earlier defined segments to join each of the files to the ORDERS tables. This pulls the metadata for all four tables into one clustered table.

Date Decomposition
One of the dimensions that we want to create will be a date dimension. To do this we need to break the date down into its individual components of Year, Quarter, Month and Day. We can manually create each of these four fields or we can use the Date Decomposition feature of Developers Workbench to generate them for us. 1. Select the ORDERDATE field.

Workshop: DB2 Web Query for i

Page

77

In many of the reports you have created so far, you have had to break down the date field into years, quarters and even months. This is a very common requirement. To save having to do this manually for every report, DB2 Web Query provides you with a feature to automatically decompose the date in the synonym editor. 2. Right click the ORDERDATE field and select Decompose Date

Workshop: DB2 Web Query for i

Page

78

3. Accept the default (all four sub components selected for ORDERDATE) by clicking OK. Four new fields are created for users to access. Now we return to creating our dimensions. 4. Select the Modeling View. This is the easiest way to define hierarchies in DB2 Web Query.

Workshop: DB2 Web Query for i

Page

79

5. If the Dimension Builder is not visible, select Dimension Builder from the Synonym menu at the top of the Developer Studio window.

In this view you see all the tables and their relationship to the base table ORDERS. You can either view the tables as icons or you can view a column list for each table. 6. Double-lick the INVENTORY table icon to switch to the Columns view. (A second double-click reverts back to icon mode.)

Workshop: DB2 Web Query for i

Page

80

The columns in the INVENTORY table are structured such that within product categories, you have product types; within product types you have models; and within models you have product names. Now you need to describe this hierarchy to DB2 Web Query. 7. In the Dimension Builder section, expand webqryXX/CEN_ORDERS, right-click Dimensions and select Add Hierarchy -> Levels.

Workshop: DB2 Web Query for i

Page

81

Dimension Builder
There are two types of hierarchies: one based on levels and the other based on parent child relationships. You use level hierarchies the example you have been using so far. (For example, Country -> Region -> State -> City is a level hierarchy.) For more information on different types of hierarchies see the Developers Workbench help text. 8. Right-click your new Dimension1 icon and select Rename. Change the name to Product Hierarchy.

Workshop: DB2 Web Query for i

Page

82

9. Starting at the top of the hierarchy, drag PRODUCTTYPE and drop it on Product Hierarchy. Repeat for each of the other levels, PRODUCTCATEGORY and PRODUCTNAME.

Workshop: DB2 Web Query for i

Page

83

10. Repeat steps through to define the Date Dimension, the Plant Hierarchy, and the Stores Hierarchy as shown in the following figure:

11. Save your definition and close all Developers Workbench windows. You have now completed all the steps required to OLAP-enable 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.

Lab 7.3: Working with an OLAP-enabled report


1. Run your OLAP Revenue report. Note: The Maximize Contents icon (on the far right of the DB2 Web Query home page) can be used to send your report to a new browser window.

Workshop: DB2 Web Query for i

Page

84

Notice the addition of a completely new panel at the top of the report. This is called the Selection pane. It includes tabs for every dimension described for any of the tables that are part of the ORDERS cluster. You also have the capability to work with the Measures and to create a Graph directly from the report. There are three ways to work with your OLAP data: from the report itself, from the Selection pane, and from the Control Panel. In the above report you cannot see the control panel because it is hidden or closed. It can be opened via the OLAP button or by clicking on the blue

square next to the Product Type heading.

Slicing / Dicing and Drilling Down for more details


Notice that the heading for every column has either a blue square icon or an arrows icon. The blue square icon allows you to drag and drop the column and to rearrange or pivot it. It also allows you to open up the OLAP control panel. The arrows icon allows you to sort the measures or numeric fields. 2. Click the arrows icon for Revenue. Because Revenue was previously unsorted, neither half of the icon was dark and the prompt read sort Revenue. 3. Now that you have sorted by Revenue, hover over the column again. Notice the prompt change. Notice also that the bottom half of the arrow is dark indicating that a click does the sort in descending sequence. 4. Click the arrows icon for Revenue again.

Workshop: DB2 Web Query for i

Page

85

Tip: The first thing you learn when working with an OLAP-enabled report is that there are multiple ways to accomplish the same result. 5. Right-click the title Revenue to bring up a context menu.

6. From the context menu select Visualize.

Workshop: DB2 Web Query for i

Page

86

As you saw in Active Reports, selecting visualization causes graph bars to be displayed to help you quickly note trends or to easily compare two columns. Positive numbers are visualized with blue bars while negative numbers are visualized with red bars. 7. Next, select the Store Hierarchy tab. Selecting the Store Hierarchy tab displays tabs for each element in the hierarchy, proceeding from the top of the hierarchy (on the left) to the bottom. By default each tabs drop-down list contains all the unique values for that column. For example, initially, every region in the world would be available under the region tab. 8. To begin to filter and drill down on your data, select Germany from the Country drop-down list.

Workshop: DB2 Web Query for i

Page

87

Tip: You can select multiple values using the Ctrl or Shift key. 9. Look at the Region drop-down list. Notice that the only regions displayed are for Germany. Select the Nord (North) region.

10. Your filters do not take effect until you run your report. First, look at your current totals and then click Run.

Workshop: DB2 Web Query for i

Page

88

Your report shows the revenue and number of orders for the Nord region in Germany. Notice the equal sign icon immediately to the left on each field of the Store Hierarchy tab. Basically each time you fill in a value you are filtering your data by creating a WHERE clause. Instead of selecting Country equal to Germany, you could have selected all countries except Germany by clicking the equal sign icon until it shows the not equal symbol. 11. Click this icon multiple times to cycle through your choices. 12. Click the Reset button to reset the report back to its initial state. You could also have used the back arrow on your browser to go back one screen at a time.

13. Select the Product Hierarchy tab but dont select any drop-down lists. Instead of using the hierarchy tabs, you drill down within the report itself. 14. Click the Audio link.

Workshop: DB2 Web Query for i

Page

89

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. You would have achieved the same result by selecting Product Type = Audio in the Product Hierarchy tab and then clicking the Run button. 14. Now drill down on Amplifiers/PreAmps/Tuners to see the actual products that compose that category.

Workshop: DB2 Web Query for i

Page

90

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. 15. Continuing your analysis, drill down to see only sales that occurred in January 2007. Select the Date Dimension tab. 16. Select 2007 for the YEAR. 17. Select 01 for the MONTH. 18. Click Run.

Workshop: DB2 Web Query for i

Page

91

19. Click Reset to return to an unfiltered report. 20. Now lets see what happens when you drill down on a measure or total field. Drill down on the Revenue for Office products.

Workshop: DB2 Web Query for i

Page

92

After drilling on the Revenue for Office products, the Office product type is expanded to its sub categories and products. Revenue and Order Count are now grouped at a much more detailed level. 21. Reset your report to remove all drill downs.

The next request from your users is to generate a report that shows revenue by product type by year. 22. Drag ORDERDATE_YEAR from the Selection pane into the area of the report where you want it, that is, across the top. The plus symbol indicates that you are in a valid area to drop the field.

Workshop: DB2 Web Query for i

Page

93

23.

Remove Order Count from the display by right-clicking Order Count and selecting Hide.

Workshop: DB2 Web Query for i

Page

94

24. You now have a very nice pivot table. To see the years down the left hand column, simply drag the column name ORDERDATE_YEAR to the left of Product Type. Again, the plus sign indicates where you can validly drop the field.

Workshop: DB2 Web Query for i

Page

95

25. Save your new pivot report. Click the Save button and select Save Report. Navigate to the Standard Reports folder, choose Manufacuring Reports and save your new report as OLAP Pivot Report.

Workshop: DB2 Web Query for i

Page

96

Workshop: DB2 Web Query for i

Page

97

Notice that you have the option to save this report without any OLAP capabilities. In essence, you have used the OLAP functionality to actually design a new report for an end-user. 26. See what happens when you save to Excel or PDF.

In addition to dragging and dropping from the Selection pane, there are other methods to display additional columns in the report. 27. Right-click ORDERDATE_YEAR and then hover over Unhide. 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 available to you for display.

Workshop: DB2 Web Query for i

Page

98

28. Try the same process on the Revenue field. Notice that here you see only the numeric fields that are available to you.

Workshop: DB2 Web Query for i Next you look at Graph tab.

Page

99

Working with the Graph tab


29. Select the Graph tab drop-down menu. Check Revenue and then cycle through the graph types on the right until you come to Pie Chart.

30. Click the Run button. If the report is running on the DB2 Web Query home page, click the Maximize Contents icon (on the far right). 31. Make the pie chart window larger by dragging down the horizontal break line between the graph and the report.

Workshop: DB2 Web Query for i

Page

100

Notice that there is one pie chart for each year which was your major sort by axis. Tip: To control the scope of the graph use the drop down boxes in the Selection pane. For example, if you only wanted a graph for 2006 revenue you could select the year 2006 from the ORDERDATE_YEAR drop down list. Tip: If your report had multiple measures that could be graphed, you can actually choose to graph them on the same chart. You can select each measure for graphing and choose a different graph type. For example if your report contained profit, you could superimpose a line graph on a bar graph with the line representing the profit and the bar representing revenue.

Lab 8: HTML Composer


HTML Composer is a component of IBM Developer Workbench. Prior to starting this set of tutorials, you must have completed Lab 6.1: Configuring the Developer Workbench. 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.

Workshop: DB2 Web Query for i

Page

101

In this lab youll design 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.

Compound parameterized report (HTML1_KPI)


In this exercise, using two graphs and one report created in previous exercises, you add a common parameter and bring them together on one HTML page for the user. Figure 11-1 shows the final output page.

Figure 11-1

Lab 8.1: Adding parameters to existing reports


In this lab, you do all your work from Developer Workbench. You can run Report Assistant and Graph Assistant from either Developer Workbench or the DB2 Web Query home page. In Lab 6, the two main functional areas of Developer Workbench were introduced. The first leg of the explorer tree expands through Data Servers to allow you to work with your metadata. The second branch expands down through Managed Reporting to allow you to work with the folder in your domains. In this section, you must add Product Type as a parameter to the three reports that you want on your KPI page. You modify the existing reports to accept this parameter and then save them under new names.

Workshop: DB2 Web Query for i

Page

102

1. Open Developer Workbench. You see WebFOCUS Environments under Developer Studio Desktop. 2. Expand WebFOCUS Environments -> <your environment -> Managed Reporting -> Domains -> QRYUSRxx -> Reports -> 1: Getting Started Labs Manufacturing Reports. 3. In your Manufacturing Reports folder, navigate to the graph Product Revenue Trends.

4. Right-click Product Revenue Trends and select Copy. Keeping your cursor in the same pane (the list of your reports), right-click and select Paste. You now have a report titled Product Revenue Trends1 in the Manufacturing Reports folder.

5. Right-click your new report, Product Revenue Trends1 and select Rename. Give the report the name HTML1_KPI_LINE.

Workshop: DB2 Web Query for i

Page

103

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 product_revenue_trends1.fex. You have changed only the display title of the report, not the physical name on disk. 6. Right-click HTML1_KPI_LINE and select Edit in Developer Studio Tool.

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. In this example, Graph Assistant opens. 8. In Graph Assistant, choose the Selection criteria tab. 9. Drag PRODUCTTYPE to the Screening conditions pane. 10. Click Select values [or undefined]. 11. In the EQ Values window, select Parameter and then click the Auto Prompt button.

1 12. In the Values pane, make sure the PRODUCTTYPE field is selected. Accept all other defaults for PRODUCTTYPE parameter properties and click OK.

Workshop: DB2 Web Query for i

Page

104

13.

2 Back on the EQ Values window, click OK.

Notice in the Screening conditions pane that the Select values [or undefined] link has changed.

Remove the months from the X axis labels to free more room in the small output frame for the graph itself. 14. 15. Click the Properties tab and the X axis subtab. On the X axis subtab, make sure the Show axis labels check box is not checked.

Workshop: DB2 Web Query for i

Page

105

16.

Click the Options subtab.

From experience, you know that the frame for your 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. 17. Set the output size to 350 pixels wide (Horizontal) by 250 pixels high (Vertical).

18. Save your graph and Run it. Notice how the size of the graph has changed from the original 19. Repeat the previous steps for the existing bar chart, Revenue by Product Type Graph. If you need more detailed assistance, refer to the previous steps 4-19 and figures. a. Copy and paste the Revenue by Product Type Graph 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.

Workshop: DB2 Web Query for i

Page

106

d. Click the Field selection tab. e. Open the Field options COUNTRY dialog. To save space for your graph, delete Country in the X axis field label field.

f.Save your graph and Run it. Again, notice the smaller size.

Lab 8.2: Designing the layout for the HTML report


In this section, you design the layout for the HTML report: 1. Open Developer Workbench. 2. Expand WebFOCUS Environments -> <your environment> -> Managed Reporting -> Domains -> QRYUSRxx Reports 1: Getting Started LabsManufacturing Reports. 3. Right-click the Manufacturing Reports folder and select New HTML File.

Workshop: DB2 Web Query for i

Page

107

0 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. 1 4. Call your new report HTML1_KPI and click Create.

In the rest of this lab, you include a line chart, a bar graph, and the gross profit report. Figure 11-10 below shows the final layout design of your compound report. The sections that follow refer to this figure unless noted otherwise.

Workshop: DB2 Web Query for i

Page

108

Figure 11-10

Including a line chart


5. Click the Graph icon on the toolbar.

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 of your graph. 7. Right-click Box 1 and select Reference existing procedure. This not only shows how the graph will look in this frame, but it also references any parameters that are used by the graph.

Workshop: DB2 Web Query for i

Page

109

8. Open your HTML1_KPI_Line file in the Manufacturing Reports folder. Notice that the actual file name is displayed.

9. In the New Parameters window, the system presents a list of the parameters used in HTML1_KPI_Line. For Control Type, accept the default of Drop down list. 10. For Parameter grouping options, select Do not create a form. 0 1

Workshop: DB2 Web Query for i

Page

110

Note: 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. You said no to this because you want to be able to move each of these elements separately on your page.

11.

Click OK.

You now modify the HTML Page by moving the positions of the parameters to match Figure 11-10. 12. Delete the label Producttype. You reference Product Type in your overall report heading. 13. Move the drop-down list and the Run button as shown below. Your Run button looks slightly different at this stage.

Workshop: DB2 Web Query for i

Page

111

Your page should now look like this:

14.

Select the line graph. In the Properties pane on the right, change Name to LineGraph.

Workshop: DB2 Web Query for i

Page

112

15. Click the drop-down control box in the report; click the Parameters tab in the lower right corner; select Add ALL option, and specify to display All Products.

Including a bar chart


Including a bar chart in the HTML report is very similar to including the line chart. Refer back to the previous section for detailed steps. 16. 17. 18. 19. 20. Click the Graph icon. Draw a box similar to the box in the upper right corner in Figure 11-10, labeled 2. Select the Properties tab at the bottom of the right pane. Right-click the new graph frame and select Reference existing procedure. Select HTML1_KPI_Bar.

21. To make the two graph frames the same size, you can use the Properties pane to manually size the frames to be 250 x 350.

Workshop: DB2 Web Query for i

Page

113

Note: Another way to do this is to select both frame 2 and frame 1 using the Ctrl key and then click the Make same size icon ( ). Notice that it is the last element selected that controls the final size of all the selected elements. 22. Select frame 2 and then frame 1 and click the Align top icon ( ).

23.

In the Properties pane on the right, change the Name to BarGraph.

Workshop: DB2 Web Query for i

Page

114

Including the gross profit report -- Gross Profit by Revenue Type


24. Select the Report icon.

25. 26.

Draw a box similar to the box at the bottom in Figure 11-10, labeled 3. Right-click the new report frame and select the Gross Profit by Product Type report.

27.

In the Properties pane on the right, change the Name to GrossPftReport.

To make this page look a little cleaner, you remove the frames around each of the reports: 28. Highlight each of the three reports. 29. In the Properties pane on the right, set Frame border to no.

Workshop: DB2 Web Query for i

Page

115

30. To have all three reports in your compound HTML page automatically run when the page is opened, highlight each of the three reports and from the Properties pane on the right, set Auto Execute to True.

Give the report a title. 31. Select the Text icon

Workshop: DB2 Web Query for i

Page

116

32. Draw a box in the pane where you want the report title to be. 33. Enter the text Product Type Indicators. 34. Click outside your text box so that it is surrounded by a straight line frame and not slashes. 35. In the Properties pane on the right, click the ellipsis button (...) next to Styling: Font. 36. Define the styling for your title by selecting the following options: arial, 18pt, bold, underlined, and blue.

Modifying the Run button


Finally, you tell the system which reports should be run when the Run button is clicked. 37. Right-click the Run Graph1 button and choose Hyperlink properties. 38. In the Hyperlink Properties window, change the display text to Run and appropriately size the Run button. 39. Click the add icon ( ) on the right.

Workshop: DB2 Web Query for i

Page

117

The Run button is initially set to run the original report that was used to import the parameter. You must tell it to also run your other two reports when the user clicks Run. 40. To add the second graph, click the add icon ( ) again. 41. For Action, select External procedure. 42. For Source, click the ... button, and navigate to and select HTML1_KPI_Bar. 43. For Target Name, select BarGraph to indicate which frame the report should run in. 44. Repeat the process and select the external procedure Gross Profit by Product Type and point it to the frame GrossPftReport. Your Hyperlink Properties window should look like this:

45. Click OK. 46. Save your report and then run it by clicking the Run button (circled in Figure 11-20). You must also click the Run button on your report to fill in the two graphs.

Workshop: DB2 Web Query for i

Page

118

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.

Figure 11-21 N 0738486760

Workshop: DB2 Web Query for i

Page

119

Workshop: DB2 Web Query for i

Page

120

Appendix: Optional Exercises


Lab A: Report Assistant Date formatting
In this next example you select only products sold in the year 2006, and you include the quarter the products were sold across the top of your report. To do this easily we first want to create two new fields based on ORDERDATE. One field will contain the quarter and the other field will contain the year. 1. If you have closed your report, open the Manufacturing Reports folder on the DB2 Web Query home page, right-click the Revenue by Product Type Report and select Open. 2. To the right of the Available fields heading, click the calculator icon (New define field) to define a new field.

3. Give the new field the name Quarter and select a format of Q. Either select or key the date field name ORDERDATE. The name must be in upper case letters. This extracts the quarter from ORDERDATE. Click OK.

Workshop: DB2 Web Query for i

Page

121

Workshop: DB2 Web Query for i

Page

122

4. Repeat the process to create a field named Year from ORDERDATE with a format of YY (UPPER CASE required).

Selection criteria
The next steps filter this report by selecting only year 2007. 5. 6. 7. 8. 9. Select the Selection criteria tab. Drag and drop Year from the Available fields list onto the Screening conditions panel on the right. From the first drop-down box, select WHERE. Select EQUAL to. Click the <Select values> link.

Note: Although you are selecting 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.

Workshop: DB2 Web Query for i

Page

123

WHERETOTAL does the comparison after the records have been retrieved, sorted and aggregated. The selection is done on the aggregate value of the column. If you wanted to select only the product types whose total revenue was greater than $100 million, you would use WHERETOTAL. If you used WHERE, you would be applying the selection on every individual order read and none would meet this criteria. 34. Select the Values radio button. DB2 Web Query looks for all distinct values in this field and presents them in a list. 35. Select 2007 and click OK.

Note: You can compare a field to a: Constant - a specific number Parameter -a variable whose value(s) is either entered by a user or passed from another report Field - another field in your table(s) Values - select from a list of actual values in the selected field.

Workshop: DB2 Web Query for i

Page

124

Cross Tab report


Now you specify the columns you want across the top of your report. 36. Select the Field selection tab. 37. Drag and drop Quarter into the Sort across box.

37. Run your report. When you do a save as for the report, default values selected are Prompt for parameters and Show on users list. I left the default values. You might want to make a note of what is the best choice for these here.

Workshop: DB2 Web Query for i

Page

125

38. Save the report as Cross Tab 2007 and close it.

Workshop: DB2 Web Query for i

Page

126

Lab B: Report Assistant Output options


Lets experiment with a few of the other Report options within DB2 Web Query first, on-demand paging. 1. Open your Gross Profit by Product Type report.

On-demand paging
2. Click the Report options tab and select On-demand paging in the Output format specific section.

3. Rerun the report

Workshop: DB2 Web Query for i

Page

127

This report, only one page long, isnt the best to demonstrate the on-demand paging feature. Assume that your report was 201 pages long instead. When on-demand paging is enabled, DB2 Web Query saves your report on the System i and delivers one page of report output at a time to your browser, decreasing the amount of time you wait for your report to be transmitted. The bulk of your report remains on the System i 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.

PDF output
So far all our output has been sent to the display. DB2 Web Query provides many additional options for output. 4. Select the Report options tab and for Generate report as, select PDF - Portable Document Format from the drop-down list. Note: Users do not require any additional software to create a PDF report. Adobe Acrobat Professional edition is not required.

5.

Run the report again.

Workshop: DB2 Web Query for i

Page

128

6.

Close the PDF report and Report Assistant for this report.

Workshop: DB2 Web Query for i

Page

129

Lab C: Using Web Query to enhance a QRYDFN


Once you have created metadata, DB2 Web Query understands the metadata as a result set. You can use DB2 Web Query to edit, sort, and filter that report. Lets modify the converted query to traffic light product categories with greater than 22,000,000 Gross Profit. You follow the same steps you performed in the Report Assistant labs. 1. Right-click the query you just created and Open it.

As you can see it looks very much like the reports you created in Report Assistant.

Workshop: DB2 Web Query for i

Page

130

Traffic Lighting fields in converted Queries


2. Highlight GROSSPROFT

3. Open the Field options GROSSPROFT dialog at the bottom of the screen and click Conditional styling.

Workshop: DB2 Web Query for i

Page

131

Note: You cannot add new columns to the report, even if the column is from a table used in the report. DB2 Web Query, in effect, sees the Query/400 result set as any other table. If you edit the report from DB2 Web Query, those changes are not reflected in the QRYDFN object 2. Click the Add icon to use the Wizard to create a conditional field to display Gross Profit in a green font if the gross profit is greater than 22,000,000.

3. Click OK to create the condition. 4. Click the Add condition icon to attach the condition; then change the Font to traffic light Gross Profit in green.

Workshop: DB2 Web Query for i

Page

132

5. 6.

Run your report. Save your report as qry400grossprofithighlight

Workshop: DB2 Web Query for i

Page

133

Lab D: Developers Workbench


Developers Workbench provides an integrated development environment for building and maintaining a DB2 Web Query reporting environment. Developers Workbench includes additional tools to work with your metadata. The synonym editor allows you to change the way a field is displayed to the end-users. You can add commas and decimal signs, convert date formats, convert alpha to numeric fields, and even change the length of a field. The synonym editor also allows you to create new calculated fields or standard predefined filters for the end-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 to use the optional OLAP feature, you must define your hierarchies or dimensions through the synonym editor. Utilizing the metadata layer, Developers Workbench provides the ability to do impact analysis at both a file and field level. If you need to make changes to a field, you can see which reports and graphs use that field and what business views it is part of. Developers Workbench provides you with the capability of profiling your data. This allows you to see both the patterns in the actual text characters. For example, profiling the telephone number in the Stores table shows us that most of the records have a format of 9999999999 whereas five records have a format of 9 9s instead of 10. Are these five records a quality problem? Data profiling also shows you the minimum and maximum values in a column and identifies ten possible outliers. This is done by showing you the ten highest and ten lowest values in a column. The SQL Wizard component of Developers Workbench allows you to import SQL or run a System i stored procedure and use the result set as input to Report or Graph Assistant. One of the major tools within Developers Workbench is the HTML Composer which is specifically designed to create HTML pages that can contain compound reports or dashboards. Using cascading style sheets and other techniques, you can design your HTML page to match your company intranet standards. In this lab you configure your System i DB2 Web Query environment and set up some Developers Workbench default settings. This lab is a prerequisite for Lab 7: OLAP (Online Analytical Processing) and Lab 9: HTML Composer.

Workshop: DB2 Web Query for i

Page

134

Lab D.1: Configuring Developers Workbench


1. Developers Workbench is a PC application. Click Start -> All Programs -> Information Builders -> WebFOCUS 76 Managed Reporting Developer -> WebFOCUS Developer Studio. 2. Right click on WebFOCUS Environments and select add.

When you start Developers Workbench, the first thing you must do is to add the definition of your System i environment. 3. 4. 5. Fill in the name and description of your System i. Verify that port 11331 is selected and that the HTML Alias is /webquery_html Click OK.

The first time you open the System i environment or connection that you just added, you must sign on. 6. Sign on with your admin or developer authorized profile.

Workshop: DB2 Web Query for i

Page

135

7. Open your application folder (WebQryXX) by selecting <system name>Managed ReportingWebQryXXApplicationsWebQryXX.

Application folders contain your metadata -- 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. Thats where you go to create a new report or modify an existing one.

Setting Developer Workbench default options


Developers Workbench has a set of options that can be tailored to each user. These options can be accessed from the Window menu on the tool bar.

Workshop: DB2 Web Query for i 8. Click Window on the tool bar and select Options

Page

136

Following is the screen display of the General tab:

Developers Workbench allows you to show your Windows desktop explorer tree in the same window as your DB2 Web Query Explorer tree. 9. Select the Explorer tab and click the checkbox for Show Desktop on Explorer tree.

Workshop: DB2 Web Query for i

Page

137

Notice, there now is a Windows Desktop icon in the DB2 Web Query explorer tree.

10.

Expand Windows Desktop.

Workshop: DB2 Web Query for i

Page

138

Showing your Windows desktop tree within Developers Workbench has a few definite benefits. The first and obvious benefit is being able to stay within one working environment as a programmer. A very nice additional benefit is the ease with which you can copy items from your PC hard drive to the DB2 Web Query folder structure. You may want to move style sheets, company logos, pictures and other PC files between the different file structures. In the example below, a text file containing SQL statements is being copied and pasted into the Other Files folder in the Common Domain. From here the SQL can be accessed and run via the SQL Wizard in Developers Workbench or the SQL metadata creation option from the DB2 Web Query home page.

Youre now finished with the basic setup.

Anda mungkin juga menyukai