#### Creating sublinks

A sublink is a way to connect the primary report and the subreport. When you define a sublink, JReport 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 report sets in the same catalog: one contains a customer report which has a banded object inside and displays information of customer ID, country, city and phone, and the other contains an order report which contains a crosstab showing information of customer ID, product name and quantity. Now, you want to insert the order report as subreport into the customer report, and set up a link between them, so that when the end users views the customer report, a subreport will be built for each customer based on the order report, showing order records for only the specified customer.

To achieve this, take the following steps:

1. Open the report set that contains the customer report in JReport Designer.
2. Select the detail panel of the banded object and click the Insert Subreport button on the Insert toolbar.

   A box is then attached to the mouse pointer to indicate it is ready to place the subreport.

3. Click in the panel and the Subreport dialog is displayed.
4. Click the Browse button to select the report set that contains the order report as the subreport.
5. In the Field tab, click the Add button.
6. Check CTCrossTab in the Choose Component dialog, then click OK. The component is listed in the Component in Report box.
7. Add the Customers_CustomerID field in the customer report to the Field box. See illustration.

8. A link is automatically set up as below:

   Fields(Primary) | OP | Fields(Subreport)
   --- | --- | ---
   Customers_Customer ID | = | CUSTOMERS_CUSTOMERS ID

9. Click OK to apply the settings.

When you preview the customer report, crosstab is generated for each customer based on the customer ID. See the result.

Notes:

- When you specify the component in the subreport that will be added to the primary report in the Choose Component dialog, you can select more than one component as long as the components are based on the same dataset.
- When creating sublinks, you need to avoid link loop. 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).