Creating and Designing Report using iReport - Part 2
page 2 of 4
by Anuva Das
Feedback
Average Rating: 
Views (Total / Last 10 Days): 17023/ 437

Subreport

A Subreport (a report within a report) is an important feature of report generating tool. In some situations you might need more than one query to retrieve data from database, and then you can use the subreport feature of iReport. A report can contain more than one subreport. Each report, including a parent report and a child report, has its own SQL query to retrieve data from database.

Suppose you want to display the sales order details of each salesman. For that, first you have to create the parent report that displays all the salesmen. Now create the subreport that displays the order details of each salesman. To create subreport select “Edit-> Insert Element    ->  subreport” or click the “subreport” icons. It will open the following dialog.

Figure 1

Click the next button and write the query in the “SQL query” text box.

Figure 2

Now click the next button. Select the required fields to display in your subreport.

Figure 3

Continue the subreport generating process by clicking the next button. It will open the following dialog, having different layouts to display the subreport. Choose a suitable template from the above dialog for your report and click the next button.

Figure 4

In the following “Subreport expression” dialog, if you choose the first option then you have to specify the path of your subreport’s jasper file in the “SUBREPORT_DIR” parameter.

Figure 5

Now click the finish button to get a subreport table that displays your subreport.

Create a parameter (for example: salesmanId) in the subreport. Now open the properties by right clicking on the subreport icons. Click the subreport(Other) tab as shown in the following dialog.

Figure 6

To add a parameter click the Add button and fill up the parameter name and default value expression field in the “Add/modify parameter” dialog as shown in the following dialog.

Figure 7

Now change the subreport query to display the order details of each salesman by passing their “salesId” as a parameter to the subreport. The following query is used for this.

Listing 1

Select * from order_details where salesId = $P{salesmanId}

When it is run it generates a report like this:

Figure 8


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 1 and 4 and type the answer here:

User Comments

Title: doubt in crossta with group   
Name: kalpana
Date: 7/1/2008 7:15:06 AM
Comment:
i am tring to create the Crosstab with group , i am not able to create the summation for the grouped columns . pl guide me to design the report using i-reports.
thanks in advance
Title: Cross tab report   
Name: Navin
Date: 6/16/2008 6:45:45 AM
Comment:
I generated the cross tab report as per the steps, but have got blank output and the number of pages is 6, but each page is displaying nothing
Title: Page Display   
Name: Brendan
Date: 6/9/2008 9:16:34 AM
Comment:
Mr. Dilip,

I've fixed the display of the article. Thank you for mentioning this.
Title: Mr   
Name: Dilip
Date: 6/9/2008 7:51:04 AM
Comment:
The figure 10 in this url is missing.
Please provide the same asap
Title: Student SE   
Name: Shirhan
Date: 5/28/2008 9:41:37 AM
Comment:
Thanx once again! this article was the one I was looking for
I needed to print a Character certificate and had a problem of how to run a couple of queries so this will give the answer.

Once again you saved the day..... :-)
Title: Reply to Sandeep   
Name: Anuva
Date: 8/11/2007 11:47:28 AM
Comment:
Thanks.Still i'm not deciding.
Title: Nice work   
Name: Abhishek Kumar Singh
Date: 8/11/2007 6:54:01 AM
Comment:
Nice one.
Title: Hello   
Name: Sandeep Acharya
Date: 8/10/2007 9:49:28 AM
Comment:
Hello,
Nice to see the part 2. How many parts are yet to come??? Carry on.... I am counting the $s. Dont worry !!!

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 10/11/2008 3:52:23 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search