Contents

 

Jasper Sub-Reports

Sub-reports can be used in two ways:

1. to provide a "re-useable" report that can be inserted any where in the main report such as a Legend that may be straight text or from a database, but is not strictly related to the main report.
2. to provide chunks of independent reports that are related to the main report.

For each of these cases a parameter is able to be passed form the main report to the sub-report and as well you may design a return value as well to be passed back.

Here is an example of a fairly simple re-usable report containing a legend.
In this case no parameter is passed from the main to the sub-report and no value is passed back.

 

 


Requirement:
My client has a service level agreement (SLA) with a response time. He likes to use acronyms. But of course the average customer may not understand all of these so we provide a legend on the last page footer.
Some acronyms are:

Standard 4Hr Service 5 days STD13x5, Standard 4Hr Service 6 days STD13x6, Basic Same Day Service 5 days BSD9x5

Basic Same Day Service 6 days BSD9x6, Weekly response WKL, Premium Service 7 days PREM24x7

Of course in this case the long description comes from a database table that is under the control of the end customer. The acronym gets prints on the report. However the report is actually not related to the main data what so ever so a sub-report is ideal.

The resultant sub-report looks like this when run:

SLA_sample

The actual report font size is very small (Arial 5) because we wanted to fit a lot of info that is usually not read often into a small space. WE usually produce reports in pdf so the end user can use the magnifier to zoom in and see details.

The other feature used to condense space is the three columns. The number of columns to use is defined in the report properties. Be careful with the column widths and the space between. Here is the screen shot of my setting:

SLA_sample_props

Best Practice:
Set the page margins to ZERO for this sub-report so that when embedded in the main there are no gaps to worry about.
However, do not set the margins to zero until you are ready - otherwise it makes it more difficult to "debug" if you like to print the results on paper and see the whole effect. (Zero margins are not nice for some laser printers). See this screen capture for the settings I used:

page_settings