A report that is inserted into another report is referred to as the subreport. Subreports are inserted and managed just like a component in a primary report, but a subreport itself is created and managed as a primary report. You can specify relationships between the primary report and the subreport as well as have Logi Report pass values to the primary report or the subreport. A primary report can have more than one subreport.
The main reasons to consider a subreport are as follows: to insert the subreport into different primary reports, namely, you need not to create it again and again for every primary report; to show different data information in different subreports and then insert them into the primary reports for comparison.
Subreports are only supported in page reports.
This topic includes the following sections:
- Inserting Subreports in a Page Report
- Creating Sublinks Between Primary Report and Subreport
- Setting Up Parameter Links Between Primary Report and Subreport
- Returning Values from Subreport to Primary Report
See an example: The SampleComponents catalog, included with Logi Report Designer, contains reports that have examples of how each component type could be used in a report. For the subreport examples, open
- Open the primary page report.
- Position the mouse pointer at the destination where you want to insert the subreport. A subreport can be inserted in the page report areas listed in Component Placement.
- Select Insert > Subreport, Home > Insert > Subreport, or drag the Insert Subreport button from the Components panel. Then,
- If the destination is the report body or a tabular cell, the Subreport dialog appears.
- If the destination is a banded panel, select the mouse button in the panel to open the Subreport dialog.
- In the Subreport dialog, select the Browse button to select the report which contains the report tab you want to use as the subreport. This report must belong to the same catalog as the primary report.
- Select the required report tab as the subreport from the Report Tab drop-down list, where the names of all the report tabs in the specified report are displayed.
- In the Field tab, select the Add button beside the Component in Report Tab box. In the Choose Component dialog, add the components in the subreport you want to be interlinked with the primary report with conditions. If the required components use different datasets, you need to add them respectively, however, as long as the components are based on the same dataset, you can add them all at the same time.
After adding the components, you can change them by selecting the button on the right and then selecting new components.
- Select a component from the Component in Report Tab box and set up links between the primary report and the component as required. Repeat this to define the link condition between other components in the subreport and the primary report.
- If the subreport has parameters and you do not want to specify values for them at runtime, select the Parameter tab to assign values to the parameters.
- If you want the subreport to return values to the primary report, select the Return Value tab and specify the settings according to your requirements.
- Select OK to insert the subreport.
When a subreport is inserted into a report, you can further format the subreport settings. To do this, right-click the subreport and select Format Subreport on the shortcut menu. In the Subreport dialog, edit the settings according to your requirements. Moreover, when a report has been inserted into another report as a subreport, if you later modify this report, it is suggested that you go to the primary report and use the Format Subreport command to save the subreport settings again.
- When inserting subreports, you need to avoid link loops. For example, if you have inserted report B into report A as its subreport, then you cannot insert report A into report B as its subreport again. It is the same case when creating sublinks, for example, if you set the links between the primary report A and subreport B (report A -> report B), you cannot set the link back to report A (report A -> report B -> report A).
- When passing values between the subreport and the primary report, you should pay attention to avoiding parameter loop, which may occur as this case: parameter A of the primary report is assigned to parameter B of the subreport in the Parameters tab, while in the Return Value tab, B is assigned to A. In this case, the values of A and B will depend on the default values and the position relationship between the two parameters.
- Only the page level formula placed in a container below the subreport such as a banded panel or the report page footer panel can get the parameter values returned from the subreport. To use the return value parameter in a formula, you need to add PageNumber in the first line in the formula. For more information, see Formula Levels.
For example, all the formulas which referenced the return value parameter should be like:
... ... ...
... ... ...
- If the subreport will cross pages, the result of the formula may not be the expected value because the return value will only be calculated when finishing laying out the subreport.
- You can use the option "Show real view of subreport" in the General category of the Options dialog (File > Options > General) to specify whether or not to show the detailed subreport structure in the primary report in design mode. However,
- For subreport with multiple pages, only the report body in the first page will be shown in the primary report.
- For cascading subreports, only the first layer of the subreport will be shown in the primary report.
A sublink is a way to connect the primary report and the subreport. When you define a sublink, Logi Report will match the records with equal relationships within the subreport and the primary report. You can apply one or more links to make the subreport and the primary report interlinked.
The following example explains the use of sublinks in detail.
Assume that you have two reports in the same catalog: one contains a customer report tab which has a banded object inside and displays information of customer ID, country, city and phone, and the other contains an order report tab which contains a crosstab showing information of customer ID, product name and quantity. Now you want to insert the order report tab as subreport into the customer report tab, and set up a link between them, so that when the end users views the customer report tab, a subreport will be built for each customer based on the order report tab, showing order records for only the specified customer.
To achieve this, take the following steps:
- Open the report that contains the customer report tab.
- Select the detail panel of the banded object and select Insert > Subreport. A box is then attached to the mouse pointer to indicate it is ready to place the subreport.
- Select in the panel and the Subreport dialog is displayed.
- Select the Browse button to select the report that contains the order report tab as the subreport.
- In the Field tab, select the Add button.
- Select CTCrossTab in the Choose Component dialog, then select OK. The component is listed in the Component in Report Tab box.
- From the resource tree in the left box, add the Customers_CustomerID field in the customer report tab to the Field box, a link is then automatically set up as follows:
Fields(Primary) OP Fields(Subreport) Customers_Customer ID = CUSTOMERS_CUSTOMERS ID
- Select OK to apply the settings.
- Preview the customer report tab. You will find that a crosstab is generated for each customer based on the customer ID.
If a subreport contains parameters, the values must be supplied at runtime. You can map the subreport parameters to fields which are contained in the dataset of the component where the subreport is inserted in the primary report, and are of the same data type as the subreport parameters, so that the subreport parameters can obtain values from the mapped fields automatically. While if a subreport parameter is mapped to another parameter in the primary report, you will still be prompted to specify the value at runtime, but in the Enter Parameter Values dialog, the parameter name you see is that of the mapping parameter.
The following example shows how to set up parameter links between a primary report and a subreport.
Assume that you have two reports in the same catalog: Report A (with Report Tab A in it) and Report B (with Report Tab B in it). Report Tab B has a parameter PToday (Date type). Then, you insert Report Tab B as subreport into Report Tab A. When you view Report Tab A, you will be prompted to specify a value for its subreport parameter PToday. However, you do not want to specify the value each time you run Report Tab A and instead want to give it a fixed value. To achieve this, follow the steps below:
- Right-click the inserted subreport in Report Tab A and select Format Subreport.
- In the Subreport dialog, select the Parameters tab (this tab is disabled if the subreport does not contain any parameters).
- In the Parameters column, you can see PToday is listed there and a same parameter is assigned to it by default in the Value column.
- Select the value drop-down list where the available fields of Date type in the dataset of Report Tab A are listed. Here, we select MYTODAY which is a predefined formula and returns a value CurrentDate().
- Select OK to apply the settings.
- View Report Tab A, and no parameter dialog will be displayed prompting you to specify the value since the formula value is passed to PToday.
Similarly you can also make values of the subreport fields return to parameters of the primary report so that you do not need to specify values for the primary report parameters at runtime. To do this:
- In the Subreport dialog, select the Return Value tab.
- In the Component in Report Tab box, select the component in the subreport, the fields of which you want to use to return value to parameters of the primary report, then the Field in Subreport box will list the available fields in the selected component.
- Select the field that you want to assign to a parameter in the primary report, select , and a parameter in the primary report of the same data type will be displayed in the Parameters column of the Return Value box. If the automatically assigned parameter is not what you need, select the required one from the parameter drop-down list.
- You can select another component in the Component in Report Tab box and set more mapping fields for parameters in the primary report.
- When done, select OK to apply the settings.