#### 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 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:

1. Open the report that contains the customer report tab 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 that contains the order report tab 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 Tab box.
7. 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

8. Click OK to apply the settings.
9. Preview the customer report tab. You will find that a crosstab is generated for each customer based on the customer ID.

Note: 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).