Prerequisites for This Example Create a table in the database to hold the TOC data

Building a Paper Report with a Multilevel Table of Contents 36-5 7. Save your report as multilevel_your_initials.rdf.

36.3.2 Create a format trigger

In this section, you will create a format trigger based on the field F_PROD_ SUBCATEGORY. This field displays the sub-category, which is the product name. This sub-category falls under the main category, which is the product department. This format trigger will fetch the page number for each product name, so that the table of contents will enable the user to navigate to various parts of the report based on the department name, then the product name. To create a format trigger:

1. In the Object Navigator, under the Paper Layout node for your report, navigate to

Main Section Body M_G_PROD_CATEGORY_GRPFR R_G_PROD_ CATEGORY M_G_PROD_SUBCATEGORY_GRPFR R_G_PROD_ SUBCATEGORY_GPRFR , then click F_PROD_SUBCATEGORY.

2. Choose Tools Property Inspector to display the Property Inspector for this field.

3. Under Advanced Layout, double-click the Format Trigger property field to

display the PLSQL Editor.

4. In the PLSQL Editor, use the template to enter following code:

function F_PROD_SUBCATEGORYFormatTrigge return boolean is pageNum number; myCount number; begin -- get page number srw.get_page_numpageNum; -- check table for duplicates select count into myCount from toc_multilevel where main_topic = :PROD_CATEGORY and sub_topic = :PROD_SUBCATEGORY; -- if no duplicates, insert row if myCount = 0 then insert into toc_multilevel values :PROD_CATEGORY, :PROD_SUBCATEGORY, pageNum; end if; return TRUE; end;

5. Click Compile.

6. Once the code is compiled, click Close, then close the Property Inspector.

7. Save your report. Tip: If you cannot find this field, use the Find field at the top of the Object Navigator. Note: You can also copy and paste this code from the provided file, multilevel_code.txt. 36-6 Oracle Reports Users Guide to Building Reports

36.4 Create a Second Query in the Data Model

The steps in this section will show you how to create a second query in the data model that retrieves the information stored in the table you created in Section 36.2, Create a table in the database to hold the TOC data . This query will fetch the data necessary for generating the table of contents in the Header section of your report. To create a query: 1. In the Data Model view, click the SQL Query tool in the tool palette then click in an open area of the Data Model view, somewhere to the right of query Q_1, to display the SQL Query Statement dialog box.

2. In the SQL Query Statement field, enter the following SELECT statement:

SELECT FROM TOC_MULTILEVEL

3. Click OK.

4. In the new query, click and drag the MAIN_TOPIC column to a separate group

above the rest of the query. 5. Click the Summary Column tool in the tool palette, then click in the new group object to create a summary column. 6. Double-click the new summary column object to display the Property Inspector, and set the following properties: ■ Under General Information, set the Name property to Subcategory_Page ■ Under Summary, set the Function property to Minimum and set the Source property to PAGE Your data model should now look like this: Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called multilevel_code.txt into the SQL Query Statement field. ■ Click Query Builder to build the query without entering any code manually. ■ Type the code in the SQL Query Statement field.