Create a Data Model with a Data Link

11-4 Oracle Reports Users Guide to Building Reports

7. On the Groups page, click Next.

8. Click Finish to display the data model for your report in the Data Model view.

9. Repeat the steps above for a second query, but this time name your query Q_Product and use the following SELECT statement: SELECT REPID, PRODNAME, AMOUNT, CUSTNAME FROM SALES ORDER BY REPID, CUSTNAME Figure 11–2 Two-query data model without a link To add the data link 1. In the Data Model view, click the Data Link tool in the tool palette.

2. Click and drag from the EMPNO column in the G_ENAME group to the REPID

column in the G_REPID group. Notice that a line is drawn from the bottom of the G_ENAME group to the Q_Product query. Labels for EMPNO and REPID are created at each end of the line to indicate they are the columns linking G_ENAME to Q_Product. Figure 11–3 Two-query data model with a data link 3. Double-click the new data link line to display the Property Inspector and examine the property settings: Note: If you are not already connected to a database, you will be prompted to connect to the database when you click Query Builder or Next. Ensure that you connect to a database that has the appropriate schema for this example. Section 11.1, Prerequisites for This Example describes the sample schema requirements for this example. Building a Two-Query Group Report 11-5 ■ G_ENAME is identified as the parent, while Q_Product is listed as the child. In terms of the data, the sales reps name and employee number make up the master record and should print once for the associated product information retrieved by the Q_Product query. ■ Notice that WHERE already appears in the SQL Clause property. WHERE is the default clause used in masterdetail relationships. You can replace WHERE with other SQL clauses such as HAVING and START WITH, but for this report the default is correct. ■ The other point to notice is that an equal sign = appears in the Condition property. An equality that is, table1.columnname = table2.columnname is the default condition for masterdetail relationships defined through a data link. You can replace the equal sign with any other supported conditional operator to see what is supported, click the field, but for this report the default is the proper condition. Linking the group G_ENAME and the query Q_Product through the EMPNO and REPID columns is analogous to writing both queries as the single-query shown below: SELECT ENAME, EMPNO, REPID, PRODNAME, AMOUNT, CUSTNAME FROM EMP, SALES WHERE JOB = SALESMAN AND EMPNO = REPID + ORDER BY REPID, CUSTNAME

11.4 Use the Report Wizard to Layout the Data

Once your data model is complete, you need to create a layout for the data objects to display in the report output. The Report Wizard enables you to create layouts for your data model. To create the layout:

1. In the Data Model view, right-click on the canvas, then choose Report Wizard.

2. In the Report Wizard, on the Report Type page, select Create Paper Layout only.

3. On the Style page, select Group Above.

4. On the Groups page, ensure that both groups from your data model appear in the

Displayed Groups list.

5. On the Fields page:

■ Click the double right arrows to move all of the fields to the Displayed Fields list. ■ Click REPID in the Displayed Fields list and click the left arrow to move it back to the Available Fields list. Since REPID and EMPNO represent the same value, you only need to display one of them. EMPNO is part of the master group, which is the level where we want to see its values in the report. REPID is part of the detail group. Hence, you remove REPID from the Displayed Fields list to prevent it from appearing in the output. Tip: When you have multiple queries in your data model, make sure that you check the names of the groups associated with each query prior to entering the Report Wizard. The Report Wizard requires you to choose data for the layout by group name. 11-6 Oracle Reports Users Guide to Building Reports Figure 11–4 Fields page of the Report Wizard

6. On the Labels page, change the labels and field widths as follows:

7. On the Template page, make sure Beige is selected under Predefined Template,

then click Finish to display your report output in the Paper Design view. It should look like this: Table 11–1 Field description of Labels page Fields Labels Width PRODNAME Product 22 AMOUNT no change 10 CUSTNAME Customer 15 ENAME Name no change EMPNO Emp. No. no change