Welcome!

Tuesday, June 29, 2010

How to Implement Subreports using JasperReport and SpagoBI?

This article records the steps to implement subreports and their master report using JasperReport (iReport) and deploy them to SpagoBI reporting server.

Both sub-reports and master report are reports. Sub-reports, like building blocks, can be insert into master report to generate complex reports.

Environment
============
SpagoBI: version 2.5
Data Source: OE example database on Oracle 11g R2
iReport : version 3.7.3

We are going to create Order (master) report to show order level data and Order Items (sub-report) report to show order detail data.

1) Create a sub-report to display the order items detail for one order.

Open iReport, create the order items detail report -- “subreport_orderitems”

Report Query:

Report Layout:


2)
Create the master report to show order level data and insert the sub-report (detail) to show the order item level data.
Using iReport to create the master (order level) report -- “Master_Order”

Report Query:


Report Layout:

Sub-report Parameter:


Setup sub-report parameter(s) in master report will let master report know how to pass values to sub-0report.

Create a variable (parameter) -- “SBI_RESOURCE_PATH”

On SpagoBI reporting server, this variable will point to folder: Tomcat_home/resources/img/
Later, we will copy resource files (needed by this example) to the above folder on SpagoBI server.
On developer workstation (in iReport), we can set this variable a default value to point to a local folder where the image files reside.


Resource - Image Expression

And

Subreport Expression:

The subreport file (“subreport_orderitems”) should be just referenced (or pointed) by its name in master report (“Master_Order”).

Finally, test the Master / subreport.

3) Prepare to deploy to SpagoBI reporting server

Copy the resource files (in this example, two image files “coffee.jpg” and “coffee_stain.png”) from your local developing environment to the folder on SpagoBI reporting server: Tomcat_home/resources/img/

4) Deploy to SpagoBI reporting server

First, add an analytical driver for the parameter (in this example, the parameter name is “p_OrderID”) used in the report, as below:


You may also need to specify the “Roles Associations” and “Predefined Value Constraints” for this parameter.


Click the “Save and return” button.
Then, click “insert” button to insert the “Document” for sub-report:


Click the “Save and return” button.

Next, click “insert” button to insert a “Document” for the Master report:


Click the “Links” button to specify the sub-report document that this master (report) document will use.


Click the “Save and return” button.

Click the “Save and return” button.


Test the Master report:

Click “User Menu” --> “Documents Execution”, and run the report “OrderEntry_Master”:


Final report output:

1 comment:

  1. i have followed your process but my subreport is not shoiwng up and in logs
    its show data conneciton null while executing subreport query thus shows no data Do you have any idea about it?

    ReplyDelete