Create a table in the database to hold the TOC data Create a group above report

35-6 Oracle Reports Users Guide to Building Reports Figure 35–4 Data model for the group above report 15. In the toolbar, click the Paper Layout view button. The Paper Layout view should look like this: Figure 35–5 Paper Layout view of the group above report 16. Save your report as toc_your_initials.rdf. You have now created the data model and the basic layout for your report.

35.2.3 Create an After Parameter Form trigger and a format trigger

The steps in this section will show you how to create two triggers. The first trigger will use the SRW.SET_FORMAT_ORDER built-in procedure to format the Main section of the report first, then the Header and Trailer sections. The second trigger will fetch the number of the page on which each country name displays, and place that information into the table you created in Section 35.2.1, Create a table in the database to hold the TOC data .

35.2.3.1 Create an After Parameter Form trigger

An After Parameter Form trigger is a function that executes after the parameter form is executed. In this section, you will set the trigger to change the order of the report execution, so that the Main section runs first. To create an After Parameter Form trigger:

1. In the Object Navigator, under your report name TOC_your_initials, expand

the Report Triggers node. 2. Right-click AFTER PARAMETER FORM, then choose PLSQL Editor from the pop-up menu. 3. In the PLSQL Editor, use the template to enter the following PLSQL code: function AfterPForm return boolean is begin srw.set_format_ordersrw.main_section, srw.header_section, srw.trailer_ section; return TRUE; end; Building a Paper Report with a Simple Table of Contents and Index 35-7

4. Click Compile.

5. Once the code has compiled, click Close.

35.2.3.2 Create a format trigger

In this section, you will create a format trigger based on the field F_COUNTRY_NAME. This field displays the country name. This format trigger will fetch the page number for each country name, so that the table of contents will enable the user to navigate to various parts of the report based on the name of the country. 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_1_GRPFR R_G_1 , then click F_COUNTRY_ NAME .

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, type the following code: function F_COUNTRY_NAMEFormatTrigger return boolean is pageNum number; begin -- get current page number srw.get_page_numpageNum; -- insert row into table insert into toc_example values :country_name, pageNum; return TRUE; end;

5. Click Compile.

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

7. Save your report.

35.2.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 with a formula column that calculates the page range for the data under each country name. This query will fetch the information from the database table you created in Note: You can also copy and paste the code from the provided file, toc_index_code.txt. 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, toc_index_code.txt. 35-8 Oracle Reports Users Guide to Building Reports Section 35.2.1, Create a table in the database to hold the TOC data . You will later create a tabular layout to display this information in your table of contents. To create a second query with a formula column: 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 TOPIC, MINPAGE FROMPAGE, MAXPAGE TOPAGE FROM TOC_EXAMPLE GROUP BY TOPIC

3. Click OK. Your data model should now look like this:

Figure 35–6 Data model with second query 4. In the Data Model view, click the Formula Column tool in the tool palette, then click in the group G_TOPIC for the second query.

5. While the formula column is selected, choose Tools Property Inspector to

display its Property Inspector.

6. Under General Information, set the Name property to TOC_pages, and the

Datatype property to Character.

7. Under PlaceholderFormula, click the PLSQL Formula property field to display

the PLSQL Editor. 8. In the PLSQL Editor, use the template to enter the following code: Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called toc_index_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.