Sei sulla pagina 1di 67

Building a Master Detail report using BIRT and Sybase IQ

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


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

Building a Master Detail report using BIRT and Sybase IQ 2


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 3


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 4


©Sybase Inc 2010
If you expand “BIRT Report Developer Guide” and select “Field Guide to BIRT”, you will see the
following:

Building a Master Detail report using BIRT and Sybase IQ 5


©Sybase Inc 2010
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…”:

Building a Master Detail report using BIRT and Sybase IQ 6


©Sybase Inc 2010
Choose a new Report Project:

Building a Master Detail report using BIRT and Sybase IQ 7


©Sybase Inc 2010
Give the project a name:

Building a Master Detail report using BIRT and Sybase IQ 8


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 9


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 10


©Sybase Inc 2010
Highlight “JDBC Data Source”, and give the data source the name “TPCH”:

Building a Master Detail report using BIRT and Sybase IQ 11


©Sybase Inc 2010
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>

Building a Master Detail report using BIRT and Sybase IQ 12


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 13


©Sybase Inc 2010
You will see the following dialog:

Building a Master Detail report using BIRT and Sybase IQ 14


©Sybase Inc 2010
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

Building a Master Detail report using BIRT and Sybase IQ 15


©Sybase Inc 2010
Click on Finish.

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

Building a Master Detail report using BIRT and Sybase IQ 16


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 17


©Sybase Inc 2010
Press on the “Select Data” tab above the chart, select the “Use Data Set” radio button, and choose the
“GetAllCountryOrderTotals” data set:

Building a Master Detail report using BIRT and Sybase IQ 18


©Sybase Inc 2010
From the “Data Preview” pane, either use the right-click menu, or drag the columns into the fields shown
below:

Building a Master Detail report using BIRT and Sybase IQ 19


©Sybase Inc 2010
Format the chart and test the report
Choose the “Format Chart” tab above the chart:

Building a Master Detail report using BIRT and Sybase IQ 20


©Sybase Inc 2010
Highlight “Title” to the left of the chart and enter a chart title:

Building a Master Detail report using BIRT and Sybase IQ 21


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

Building a Master Detail report using BIRT and Sybase IQ 22


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

Building a Master Detail report using BIRT and Sybase IQ 23


©Sybase Inc 2010
Press the “Preview” tab beneath the chart to see how the chart behaves when accessing data from the
database:

Building a Master Detail report using BIRT and Sybase IQ 24


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 25


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

Building a Master Detail report using BIRT and Sybase IQ 26


©Sybase Inc 2010
Press “Format Chart”:

Building a Master Detail report using BIRT and Sybase IQ 27


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 28


©Sybase Inc 2010
Click Finish. Then preview the report again:

Building a Master Detail report using BIRT and Sybase IQ 29


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 30


©Sybase Inc 2010
Name this report: “Detail.rptdesign”:

Building a Master Detail report using BIRT and Sybase IQ 31


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 32


©Sybase Inc 2010
Building a Master Detail report using BIRT and Sybase IQ 33
©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 34


©Sybase Inc 2010
Name the data set “CountryChoices”, and click Next:

Building a Master Detail report using BIRT and Sybase IQ 35


©Sybase Inc 2010
Enter this SQL statement:

select N_NAME
from TPCD.NATION

and click Finish. Preview the results:

Building a Master Detail report using BIRT and Sybase IQ 36


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 37


©Sybase Inc 2010
Fill out the details about the parameter as follows:

Building a Master Detail report using BIRT and Sybase IQ 38


©Sybase Inc 2010
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

Building a Master Detail report using BIRT and Sybase IQ 39


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 40


©Sybase Inc 2010
Click on Edit:

Building a Master Detail report using BIRT and Sybase IQ 41


©Sybase Inc 2010
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):

Building a Master Detail report using BIRT and Sybase IQ 42


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 43


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 44


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 45


©Sybase Inc 2010
Click on Finish. You will notice that a data cube has been created in the “Data Cubes” category in the
“Data Explorer” view:

Building a Master Detail report using BIRT and Sybase IQ 46


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 47


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

Building a Master Detail report using BIRT and Sybase IQ 48


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 49


©Sybase Inc 2010
Here are the results:

Building a Master Detail report using BIRT and Sybase IQ 50


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 51


©Sybase Inc 2010
Build an expression, using the expression builder components at the bottom:

Building a Master Detail report using BIRT and Sybase IQ 52


©Sybase Inc 2010
Click on OK. Highlight the text element, and set a couple of its properties: text alignment and background
color:

Building a Master Detail report using BIRT and Sybase IQ 53


©Sybase Inc 2010
Here is a preview of the report with the title:

Building a Master Detail report using BIRT and Sybase IQ 54


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 55


©Sybase Inc 2010
When you preview the report again, it looks like this:

Building a Master Detail report using BIRT and Sybase IQ 56


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 57


©Sybase Inc 2010
Click on Add. The default of “Data Fields” equals “L_QUANTITY”, and “Function” equals “SUM” is
fine:

Building a Master Detail report using BIRT and Sybase IQ 58


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 59


©Sybase Inc 2010
And if you scroll to the right, you see grand totals for each row:

Building a Master Detail report using BIRT and Sybase IQ 60


©Sybase Inc 2010
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”:

Building a Master Detail report using BIRT and Sybase IQ 61


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

Building a Master Detail report using BIRT and Sybase IQ 62


©Sybase Inc 2010
Choose the “Hyperlink” action, and click on the “Edit base URL” button:

Building a Master Detail report using BIRT and Sybase IQ 63


©Sybase Inc 2010
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:

Building a Master Detail report using BIRT and Sybase IQ 64


©Sybase Inc 2010
Click on the bar labeled “United Kingdom”, and the Detail report will fire up. You will see the following
results:

Building a Master Detail report using BIRT and Sybase IQ 65


©Sybase Inc 2010
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.

Building a Master Detail report using BIRT and Sybase IQ 66


©Sybase Inc 2010
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.

Building a Master Detail report using BIRT and Sybase IQ 67


©Sybase Inc 2010

Potrebbero piacerti anche