|
Return to Newsletter Contents...
Introduction to Sub-Reports in Crystal Reports
by: Kristen St. Jean, Crystal Instructor, BI Specialist
Subreports can be a powerful tool in Crystal Reports.
Subreports are reports that are displayed inside of a main report.
While there are many advantages to using subreports in a Crystal Report,
there are also a few things to consider before using them.
You might ask yourself, why do we use subreports? One reason
to use subreports is that they allow unrelated information to be displayed as one
report. For example, if your company
has multiple databases and no common link between tables in one database
to tables in a different database, a subreport can be used in bring the data from
one database into a report that is based on the unrelated database.
When viewing the report, instead of having to look at two reports for this
information, the reports display as one.
This type of subreport is called an
unlinked subreport because there is no relationship between the report and the subreport.
Another reason to use a subreport is to create what's called a linked subreport. Linking a subreport to a report relates
the data in some way. Links can be
based on database fields, formulas, or parameters.
One use for linking subreports is to link “unlinkable” data.
For example, a customer table in a database has a customer id field that
is a number, while the orders table is in a different database, and it has a customer
id field also, but it is a string data type.
In the Links tab of the Database Expert we cannot link these fields because they
are different data types. To relate
the information in these two tables we can create an orders report as a subreport
and create a formula in the orders report that changes the customer id from a string
to a number. After we create the formula,
we can link the subreport to the main report using customer id from the main report
to the customer id formula in the subreport.
The subreport should be placed at the level we are linking.
If we have a group on customer in the main report, and we’re linking by customer
id, we should place the subreport in the customer group header or footer.
This will display the orders for each customer.
The placement of subreports is very important.
It not only affects the linking, but also determines how many times that
subreport is run. In our example above,
the subreport was placed in the customer group in order to display the orders for
each customer. If there are 200 customers
in the main report, the subreport will be processed 200 times, once for each customer. It is important to take this into consideration
because the placement of the subreport can greatly affect the processing time of
the report.
Another thing to keep in mind when creating a report with subreports is that a subreport
cannot contain another subreport. There
can be multiple subreports in a report, but it’s not possible to have any subreports
inside of other subreports.
Remember, subreports can be very helpful in creating reports that couldn’t be created
any other way, but they also affect performance, so use them carefully.
Next month we will discuss sharing values from a subreport to the main report.
Go to Top |
Return to Newsletter Contents
|