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
Data Source: OE example database on Oracle 11g R2
iReport : version 3.7.3
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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvGyaSKiL2NRlIpdS3hc71S1Tm6sMWlj4A86ajDjUygdju2uP1n1HLLi_YEAh7suJp8K2WEtT47Op4b8Eb15annEB1UNlLjnDhoSScpUWE7z4N6OHRHlhlLNzBEN67XtudnlIjNx_50uA/s400/SR-query.jpg)
Report Layout:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxBqULqGQTVGeeJUKF-N2gQHfvYXsRXBJey89UL6CfrVupZHGQJgLUk1nJK6-IUWvgTqOVTntaAzZFUMO7c2CakAxycOQv8j0YPlekUg8dfeCNsGu87u-HESNVFQbdg-voryYznVKaGc0/s400/SR-layout.jpg)
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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuBMYokg7AhToOJlCydF3BYmFTDRXq1-qzkKFiYuFArpd7vsPEDZrIEbOvZJ7swVfyFaiUHKKtVNU_WjauHqz9KErV0Wn082v_ghggKt1ChawWkQuEgjhmjRvwUQCA5OvXjLlvp9qpL9A/s400/MR-query.jpg)
Report Layout:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinYfgwiCIUamOb9UFX4TBTa7WVl-1kRfVYwfjJ7cWQGwwOuKe6xv817b2SJIPoBrDfoSQEgDjNei5AMlSCn3qQv4WCNNEPhhNbhDfWTPBgnlVV7dHEwgCbrHg2ApTQBZbtA6AOfkw5ivo/s400/MR-layout.jpg)
Sub-report Parameter:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH82L7KjyNta1_6xnmwa6GPY9W0Eu-QuHw8uBIUEEFR5XXbpkDdVrNOVsAtHQGPcpxrH3s7vxdIl4AZ9ms6wYnQHxjQQYci8sa_Vw5RXeSB7ukq4jYTq6oReJIPG4Ec1ko0-gk8Gv_vWQ/s400/MR-par4sr.jpg)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFy0nCuQDbOssuAhtBkZGEhKIIJFyF8kzYcgSBl6IJ1c92j1wdPrlFnrgCnlkyUrwe7QSHiu5MC9_yriII_cg5Uk9nypTWIKiE7VJOz6c2hIC8GQaU4GRVj9fPVN_BX7axXEX7i9-4_i4/s400/MR-image1.jpg)
And
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2Hgxr1tX3ALmvu7hhdrB_bFwXjVDiIqo1Cp22DGc1xbmMFEV91f7pVVaue6TOTbaIQ1lH3ifpAKkuf4Zb6MP4QB-Nu3EHUEk8CR6smG6ecJLplq1Z-osjxNc440cUwaK9NLwsTHH5L6c/s400/MR-image2.jpg)
Subreport Expression:
The subreport file (“subreport_orderitems”) should be just referenced (or pointed) by its name in master report (“Master_Order”).
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9lWjue1G7M5vH4MgGeJWCcA1UyBdTy-0SUFBP9Zfiz3OZIE6XejN9Ly75CIFIEbhzQ54cvyXyHgbs_eCOXvv48PCZvuQf-RO_si-xFvwuHNRjdD6dBCGJvHJUZXgx8MZjgg_rL5FdpBM/s400/MR-image3.jpg)
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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrfwQ0llzmtrcoh8xJu5yiMP9DvzXdmdXKpPDDkG11DBETJ7ILsiMs3eDCI3FO1NLh3eOd2FwoZTPn_6Rymc4HWE4jIPQAipAuPm9BkBfZkrQVUCbzBu6-DqT9-Uo_2zW1mw2X3kXAJFI/s400/MR-image4.jpg)
You may also need to specify the “Roles Associations” and “Predefined Value Constraints” for this parameter.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrIbqGqlcwupr7HsOxJH2Ea5E9K9xH9iyEcyDAeMM54NsiOeQlr4_DaatG46ByRn-XA3uHb7bFl-3VqfNAwcP2vJjQZxy6oLeG0T3fxdF501XYFJ77tOWY9JDgyif7kjXZGK-yBmPOm5I/s400/MR-image5.jpg)
Click the “Save and return” button.
Then, click “insert” button to insert the “Document” for sub-report:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYO3wl-6XnnzPvbE28TalD1_8ZV5Yl62PcUW4AhXuWA1K8qeWtPImskk6bQHQrKab4zT3LDvMStYJKstFHjx5OENrSwqBs6ta8G0a5HcbK19vw-oBI0iBdADaf2esGmEfMI-Tog5LScZU/s400/MR-image7-1.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBffAkUJYcl4W-sO_rBh_0NJAHb_vF9k11g_xY_7mskzyb4ten-S2MEau0dLZw_pwgeR-YfIRtPXZqT_WypH0PUOjU1OJWnSJkNJ9-oCAzBHmP2_fdAiWjv-DgPNmYTpF5aN_Ms4ydQS0/s400/MR-image6-2.jpg)
Click the “Save and return” button.
Next, click “insert” button to insert a “Document” for the Master report:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeEcc9zbhsj7n4cYzp1aplvhjWc9e8fgqNw9bidGbRdl9G9mcpSoEqhpP-e5p6cjWTB0INKZnpg3I5D_eiPKWAHc6CxJWKRQFNram_5ruZIhq4-XpA8AI9brD36eZFnho0Of4RORvDMb0/s400/MR-image6-1.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBffAkUJYcl4W-sO_rBh_0NJAHb_vF9k11g_xY_7mskzyb4ten-S2MEau0dLZw_pwgeR-YfIRtPXZqT_WypH0PUOjU1OJWnSJkNJ9-oCAzBHmP2_fdAiWjv-DgPNmYTpF5aN_Ms4ydQS0/s400/MR-image6-2.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-WM3ftNGC6FOGkX68bUWPAse7NMDkwVxR5HiOk80Tqj1ATRUposVXcPexpAwjpf4ULwsKa7Rr_UNl39LqXZSxuoBdPrIsGJGYdZMs6FfZ7vKgHrKBfjw3Yja_l91XnndX5DdfVPA9HSc/s400/MR-image8.jpg)
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”:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-HvVbsc2Wi-t9RvgRpOuXLCMNRnznCXOYwGdikMF0N5aU-LPx1z85RbppACV7cM2oDDkYfO7tRnqxNg34kjgcv18aDgAzRAK_yEdTNXASuTcEv0Cbb3eCOpbkW6K_K0ywfclUrM_dz5A/s400/MR-image9.jpg)
Final report output: