birt master.detail tutorial

67
Building a Master Detail report using BIRT and Sybase IQ A cookbook by Courtney Claussen, Sybase IQ Technical Marketing, Sybase Inc

Upload: qbit0815

Post on 10-Apr-2015

1.065 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

A cookbook by Courtney Claussen, Sybase IQ Technical Marketing, Sybase Inc

Page 2: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

2

Table of Contents Purpose ........................................................................................................................................................... 3 Use case .......................................................................................................................................................... 3 Details about the example .............................................................................................................................. 3 Tasks ............................................................................................................................................................... 4

Open up Sybase WorkSpace and display “Help Contents” ........................................................................ 4 Create a new project ................................................................................................................................... 6 Build the Master report ............................................................................................................................... 9

Create a new report ................................................................................................................................. 9 Create a data source ...............................................................................................................................10 Create a data set .....................................................................................................................................13 Add a chart to the report ........................................................................................................................17 Format the chart and test the report .......................................................................................................20

Build the Detail report ...............................................................................................................................30 Create a new report ................................................................................................................................30 Create a data source ...............................................................................................................................32 Create a data set to display the different countries ................................................................................34 Create a report parameter ......................................................................................................................37 Create a data set to display the order detail for a particular country......................................................39 Add a dynamic cross tab to the report ...................................................................................................43 Format the chart and test the report .......................................................................................................51

Link the Master report to the Detail report and test ...................................................................................61 Link the Master report to the Detail report ............................................................................................61 Test the Master and Detail reports together ...........................................................................................64

Summary .......................................................................................................................................................66

Page 3: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

3

Purpose

This cookbook explains how to design a Master Detail report using Sybase Workspace and BIRT (Business

Intelligence Reporting Tool). BIRT is an open source, Eclipse-based reporting system, with features such

as report layout, data access and scripting. The data source for the report is a Sybase IQ database.

The purpose of this cookbook is to introduce the user to BIRT, and to provide a practical hands-on lesson

in how to use the tool to create a common type of business intelligence report.

Use case

Sub reports are a very common type of report. They are also referred to as Master Detail reports, or Parent

Child reports. BIRT is a flexible tool that allows the report developer to design many reports and integrate

them in sub report fashion via a few clicks of the mouse. The example in this cookbook demonstrates the

use of BIRT to create reports that are linked together: a main report with a bar chart displaying order totals

links to a sub report displaying details about the order breakdown for the particular country – product

categories, quantities and grand totals. Order details are presented in a report element called a “dynamic

cross tab”, which displays data in a row-and-column matrix. It is similar to a pivot table in Excel, where

you can dynamically arrange the underlying data into a spreadsheet-like format. Cross tabs are built on top

of “data cubes”, and data can be “sliced and diced” in various ways, as long as the data exists in the

underlying cube.

This example utilizes the following SYBASE products:

Sybase WorkSpace Data Analytics 2.5 which includes BIRT 2.2.2

Sybase IQ 15.1

Details about the example

The data that is the source for the report is from TPC-H. TPC-H defines a workload for decision support

system benchmarks. It includes a database schema based on an order processing scenario, and utilities for

generating data and queries. Here is a picture of the TPC-H schema:

Page 4: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

4

This schema was installed in a Sybase IQ 15.1 database, along with 1GB of data.

The objective for the reporting example is to display a Master report with the number of part orders (sum

across table column LINEITEM.QUANTITY) for each country (table NATION). The Master report

information is depicted as a bar chart, with one bar for each country.

Then, when the user clicks on a particular bar, a Detail report will be displayed. The Detail report will

show a cross tab with order totals categorized by part type, and the year and the year’s quarter in which the

orders were placed. Grand totals across yearly quarters and part type are shown.

Tasks

The tasks you will perform using this cookbook are the following:

1. Open up Sybase WorkSpace and display help contents (to learn where to go to get help)

2. Create a new project

3. Build the Master report

4. Build the Detail report

5. Link the Master report to the Detail report and test

Open up Sybase WorkSpace and display “Help Contents”

After you start Sybase WorkSpace, select Help…Help Contents. If you navigate to “Getting Started” under

“Sybase WorkSpace 2.5 New Features”, you will see some basic information about the BIRT version that

has been incorporated into WorkSpace:

Page 5: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

5

If you expand “BIRT Report Developer Guide” and select “Field Guide to BIRT”, you will see the

following:

Page 6: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

6

The field guide is where you want to start with documentation as you learn how to build reports.

In addition, there is information on-line, and communities to engage with for more help. Go to “Eclipse

BIRT Home” at:

http://www.eclipse.org/birt/phoenix/

Create a new project

Before you can create reports, you need to create a project to contain those reports. First, open the “Report

Design” perspective with “Window…Open Perspective…Report Design”. Then do

“File…New…Project…”:

Page 7: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

7

Choose a new Report Project:

Page 8: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

8

Give the project a name:

Page 9: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

9

Click on Finish. You will see the project show up in the Navigator view.

Build the Master report

The next several tasks take you through the creation of the Master report that displays a bar chart of order

totals by country.

Create a new report

Right click on the “MasterDetailReportProject” project, and choose “New…Report”:

Page 10: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

10

Give the report a name – “Master.rptdesign” - and click on Next. Then choose a “Blank Report” and click

on Finish.

Create a data source

Now you need to create a data source, which specifies the configuration parameters to connect to your

Sybase IQ database – the source of data for your report. First, start up your Sybase IQ database. Then in

the Data Explorer view in Sybase WorkSpace, right click on “Data Sources”, and select “New Data

Source”:

Page 11: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

11

Highlight “JDBC Data Source”, and give the data source the name “TPCH”:

Page 12: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

12

Click on Next. Fill in the fields as shown:

Driver Class: com.sybase.jdbc3.jdbc.SybDriver (v6.0)

Database URL (<hostname> is the name of the machine where IQ is running, and <port> is the

port that IQ is listening on):

jdbc:sybase:Tds:<hostname>:<port>?LITERAL_PARAMS=true&PACKETSIZE=512&HOSTN

AME=<hostname>

User Name = <IQ_user>

Password = <IQ_password>

Page 13: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

13

Click on “Test Connection” to make sure you can connect to your Sybase IQ database. You should see a

dialog box with the text “Connection successful”. Click on OK.

Create a data set

Now you need to create a data set, which defines the query to run to generate data for your report. In the

“Data Explorer” view, right click on “Data Sets”, and choose “New Data Set”:

Page 14: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

14

You will see the following dialog:

Page 15: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

15

Give the data set the name “GetAllCountryOrderTotals”, choose the “TPCH” data source, and leave the

“Data Set Type as “SQL Select Query”. Click on Next:

Cut and paste to enter the following query:

select sum(l.L_QUANTITY), n.N_NAME

from TPCD.LINEITEM l,

TPCD.CUSTOMER c,

TPCD.NATION n,

TPCD.ORDERS o

where l.L_ORDERKEY = o.O_ORDERKEY

and o.O_CUSTKEY = c.C_CUSTKEY

and c.C_NATIONKEY = n.N_NATIONKEY

group by n.N_NAME

order by n.N_NAME

Page 16: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

16

Click on Finish.

In the next dialog, click on “Preview Results”, to make sure the query executes correctly:

Page 17: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

17

Click on OK.

Add a chart to the report

Open the palette with “Window…Show View…Palette”. Do a drag and drop to insert a chart element onto

the canvas of the report:

Page 18: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

18

Press on the “Select Data” tab above the chart, select the “Use Data Set” radio button, and choose the

“GetAllCountryOrderTotals” data set:

Page 19: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

19

From the “Data Preview” pane, either use the right-click menu, or drag the columns into the fields shown

below:

Page 20: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

20

Format the chart and test the report

Choose the “Format Chart” tab above the chart:

Page 21: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

21

Highlight “Title” to the left of the chart and enter a chart title:

Page 22: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

22

Press “Select Chart Type”, and check the “Flip Axis” check box next to the label “Orientation:”:

Page 23: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

23

You need to do this, because there are many countries to view along the X axis. Click on Finish:

Page 24: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

24

Press the “Preview” tab beneath the chart to see how the chart behaves when accessing data from the

database:

Page 25: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

25

The chart is too small. Go back to the “Layout” tab and resize the chart until you can see all the countries

displayed next to their respective bars when you run preview:

Page 26: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

26

Do a little more formatting to give the bars in the bar chart different colors. Right click on the report:

Page 27: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

27

Press “Format Chart”:

Page 28: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

28

Highlight “Series” to the left of the chart, and click on down arrow for the list box next to the “Color By:”

label. Choose “Categories”:

Page 29: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

29

Click Finish. Then preview the report again:

Page 30: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

30

Build the Detail report

The next several tasks take you through the creation of the Detail report that displays a dynamic cross tab

with the details of orders for a particular country.

Create a new report

Go back to the Navigator view, and right click on the MasterDetailReportProject to create another report:

Page 31: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

31

Name this report: “Detail.rptdesign”:

Page 32: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

32

Click on Next. Choose a “Blank Report” and click on Finish.

Create a data source

This report has no data source, and it needs the same one that you created for the Master report. You can

simply copy and paste the “TPCH” data source from the Master report design to the Detail report design:

Page 33: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

33

Page 34: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

34

Create a data set to display the different countries

For this report, you are going to need two data sets: one to display all the country choices, and one to

display the order details for a particular country. The first one is a convenience for setting the report

parameter for which country you are interested in.

Create a new data set by right clicking on the “Data Sets” category in the “Data Explorer” view, and choose

“New Data Set”:

Page 35: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

35

Name the data set “CountryChoices”, and click Next:

Page 36: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

36

Enter this SQL statement:

select N_NAME

from TPCD.NATION

and click Finish. Preview the results:

Page 37: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

37

Click on OK.

Create a report parameter

This report is going to be passed a parameter with the country name for which to retrieve details. In the

“Data Explorer” view, right click on “Report Parameters” to create a new report parameter:

Page 38: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

38

Fill out the details about the parameter as follows:

Page 39: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

39

Create a data set to display the order detail for a particular country

Now create a data set to display the order details for a particular country. Create a new data set, and give it

the name “OrdersByCountry”. Specify the following SQL:

select sum(l.L_QUANTITY),

year(l.L_COMMITDATE) as YEAR,

quarter(l.L_COMMITDATE) as QUARTER,

c.C_MKTSEGMENT

from TPCD.LINEITEM l,

TPCD.CUSTOMER c,

TPCD.NATION n,

TPCD.ORDERS o

where l.L_ORDERKEY = o.O_ORDERKEY

and o.O_CUSTKEY = c.C_CUSTKEY

and c.C_NATIONKEY = n.N_NATIONKEY

and n.N_NAME = ?

group by YEAR, QUARTER, c.C_MKTSEGMENT

order by YEAR, QUARTER, c.C_MKTSEGMENT

Page 40: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

40

Note the “?” in the SQL statement. “?” indicates that a parameter will be passed to the SQL statement with

the country name to return order information for. Click on OK. When you highlight “Parameters”, you

will see that a parameter has been automatically created for the data set. You need to edit it to complete it.

Highlight “param_1”:

Page 41: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

41

Click on Edit:

Page 42: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

42

Specify that the SQL statement parameter is linked to the report parameter “country”, it is a “String”, and

an input parameter. Click on OK. Then preview the results (the default value of the report parameter is

“UNITED STATES”, and it is for that country that the results should be displayed):

Page 43: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

43

Add a dynamic cross tab to the report

The next thing you are going to do is add a dynamic cross tab to the Detail report. A dynamic cross tab

shows data organized in rows and columns, like a spreadsheet, but with a more dynamic flavor – like a

pivot table in Excel.

Open up the palette and drag a cross tab onto the report canvas:

Page 44: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

44

You want to see time along the vertical axis: by year and quarter. Along the horizontal axis, you want to

see product categories. All of this data is for a particular country. To set this up, drag the “YEAR” column

from the “OrdersByCountry” data set to the portion of the cross tab that is labeled “Drop data field(s) to

define rows here”. When you do that, a dialog box opens up that guides you through building a data cube,

which is the foundation of a cross tab:

Page 45: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

45

The Summary field that you are interested in looking at using various dimensions is the order total. That is

the only field – or “fact” - that goes in the “Summary Fields” section. All the other data are dimensions for

looking at the facts in different ways. Fill out the “Groups and Summaries” as shown:

Page 46: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

46

Click on Finish. You will notice that a data cube has been created in the “Data Cubes” category in the

“Data Explorer” view:

Page 47: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

47

Now that you have a cube, you will drag and drop elements from that cube into the cross tab in your report

canvas. Drag “L_QUANTITY” to the summary area, “C_MKTSEGMENT” to the column area, and

“YEAR” to the row area. There will be a down arrow next to year. Choose to “Show/Hide Group Levels”:

Page 48: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

48

Select “QUARTER”, so that you will see both a year and quarter breakdown for orders:

Page 49: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

49

Click on OK. Now preview the report, so you can see some initial results. You will be prompted to enter

the country you are interested in:

Page 50: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

50

Here are the results:

Page 51: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

51

The content looks reasonable, but there are some basic improvements you will probably want to make:

Add a title to the report

Change the “L_QUANTITY” labels to something more friendly

Add the grand total to the bottom of each column, and to the end of each row

Format the chart and test the report

Add a title to the report

Go back to the layout of the report. A title can be created by adding a “Dynamic Text” element to the top

of the chart. Drag a Text element above the cross tab, and the following dialog will be displayed:

Page 52: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

52

Build an expression, using the expression builder components at the bottom:

Page 53: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

53

Click on OK. Highlight the text element, and set a couple of its properties: text alignment and background

color:

Page 54: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

54

Here is a preview of the report with the title:

Page 55: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

55

Change the “L_QUANTITY” labels to something more friendly

In the case of this report, the report title indicates that order totals are being displayed, so we are just going

to remove the “L_QUANTITY” label. Right click on the label and choose “Delete”:

Page 56: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

56

When you preview the report again, it looks like this:

Page 57: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

57

Add the grand total to the bottom of each column, and to the end of each row

Finally, add grand totals to each column and row. Click inside the cross tab on the canvas, and in the

“Property Editor – Cross Tab”, choose “Row Area”, then “Grand Totals”:

Page 58: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

58

Click on Add. The default of “Data Fields” equals “L_QUANTITY”, and “Function” equals “SUM” is

fine:

Page 59: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

59

Click on OK. Then do the same for the “Column Area” properties. Preview the report again. If you scroll

to the bottom, you see the grand totals:

Page 60: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

60

And if you scroll to the right, you see grand totals for each row:

Page 61: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

61

You have completed the Master and Detail reports as separate entities. Now you need to link them

together.

Link the Master report to the Detail report and test

You want to be able to click on a country bar in the bar chart and display the report with the order details

for the particular country. You need to link the Master report to the Detail report.

Link the Master report to the Detail report

Open the Master report, right click on the chart, and choose “Format Chart”:

Page 62: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

62

Highlight “Value (Y) Series”, and click on the “Interactivity” button:

Page 63: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

63

Choose the “Hyperlink” action, and click on the “Edit base URL” button:

Page 64: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

64

Fill in the fields as shown above. You are choosing a drill through to a sub-report. The sub-report is the

Detail report, and you are passing it the “country” report parameter, which is associated with the bar you

click on in the Master report. Click on OK.

Test the Master and Detail reports together

Preview the Master report:

Page 65: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

65

Click on the bar labeled “United Kingdom”, and the Detail report will fire up. You will see the following

results:

Page 66: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

66

Summary

You have been introduced to BIRT, and learned how to use it to build a Master Detail report - a common

type of business intelligence report. There are many other features and capabilities within BIRT, and this

cookbook just scrapes the surface of what is available. Nevertheless, it should give you a good starting

point, and some directional bearings for how to work with the tool.

Page 67: Birt Master.detail Tutorial

Building a Master Detail report using BIRT and Sybase IQ

©Sybase Inc 2010

67

Sybase Incorporated

Worldwide Headquarters

1 Sybase Drive

Dublin, CA 94568 Tel: 1-800-8-SYBASE www.sybase.com

Copyright © 2010 Sybase, Inc. All rights reserved. Unpublished rights reserved under U.S. copyright laws. Sybase and the Sybase logo are trademarks of Sybase, Inc. All other trademarks are property of their respective owners. ® indicates registration in the United States. Specifications are subject to change without notice. Printed in the U.S.A.