Examine the Conditional Format Trigger Code Summary

Building a Report with Conditional Highlighting 22-9

22.5 Summary

Congratulations You have successfully built a report that highlights specified data in the report output. You now know how to: ■ use the Report Wizard to create a simple tabular report. ■ format the appearance of your report using tools in the Paper Design view. ■ use the Conditional Formatting dialog box and the Format Exception dialog box to create format triggers that highlight certain data in your report output. ■ examine the code automatically generated by Reports Builder. For more information on any of the wizards, views, or properties used in this example, refer to the Oracle Reports online Help, which is available in Oracle Reports Builder or hosted on the Oracle Technology Network OTN, as described in Section 4.1.1, Using the Oracle Reports online Help . Note: In this code, you can see that the two format exceptions you created comprise two parts of a format trigger. You needed to create two separate format exceptions in the Conditional Formatting dialog box to achieve this effect. If you had tried to create both exceptions simultaneously in the same Format Exception dialog box, your data would not have satisfied both exceptions, and thus would not have been highlighted. 22-10 Oracle Reports Users Guide to Building Reports Building a Conditional Form Letter Report 23-1 23 Building a Conditional Form Letter Report In this chapter, you will learn about reports that generate different versions of a form letter based on changing conditions. By following the steps in this chapter, you can generate the report output shown in Figure 23–1 and Figure 23–2 . Figure 23–1 Conditional form letter report output, base version 23-2 Oracle Reports Users Guide to Building Reports Figure 23–2 Conditional form letter report output, alternate version Concepts ■ The two form letters above were generated from the same report. As you can see, the two letters share a number of features. Hence, it is more convenient to create a base form letter and then apply conditions to certain parts to determine whether they should be displayed for the current record, in this case, employees. ■ Conditional printing is useful when you want to display a section of a report only if certain conditions are met at run time. Conversely, you may wish to use conditional printing to suppress certain information for those who dont need it. Data Relationships This report uses one query to select all data. Layout This report uses the Form Letter layout style. Youll also create the various pieces of boilerplate that will comprise the letter. To govern the printing of these boilerplate objects, youll use vertically collapsing anchors and PLSQL format triggers to conditionally produce different form letters for employees who meet the specified criteria. Example Scenario In this example, you will create a form letter to invite all of your employees to the company picnic. For your top sales representatives, though, you also want to include a Building a Conditional Form Letter Report 23-3 special invitation to a dinner party in the form letter. For all other employees, you want to include a thank you without the dinner invitation. As you build this example report, you will: ■ Create the Data Model and Layout . ■ Add Additional Text . ■ Add Logic for Text , which involves anchoring objects together and creating format triggers to control whether the text displays. To see a sample conditional form letter report, open the examples folder named condform, then open the Oracle Reports example named condform.rdf. For details on how to access it, see Accessing the Example Reports in the Preface.

23.1 Prerequisites for This Example

To build the example in this chapter, you must have access to the SCOTT sample schema provided with the Oracle Database. If you do not know if you have access to this sample schema, contact your database administrator.

23.2 Create the Data Model and Layout

When you are creating a single-query report, such as this one, you can use the Report Wizard to create the data model and layout simultaneously. To create a data model and layout:

1. Launch Reports Builder or, if already open, choose File New Report

2. In the Welcome or New Report dialog box, select Use the Report Wizard, then

click OK. 3. If the Welcome page displays, click Next. 4. On the Report Type page, select Create Paper Layout Only, then click Next. 5. On the Style page, type a Title for your report, select Form Letter, then click Next. 6. On the Data Source page, click SQL Query, then click Next. 7. On the Data page, enter the following SELECT statement in the Data Source definition field: SELECT ENAME, COMM FROM EMP ORDER BY ENAME

8. Click Next.

Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called condform_code.txt into the Data Source definition field. ■ Click Query Builder to build the query without entering any code manually. ■ Type the code in the Data Source definition field. 23-4 Oracle Reports Users Guide to Building Reports 9. Type the first paragraph of your letter in the Form Letter Text window: Dear Employee ENAME, Mark your calendar You are invited to attend the Summit Sporting Goods annual picnic on June 15, from 11:00 AM to 6:00 PM. Be prepared for lots of food, lots of entertainment, and lots of fun.

10. Click Next.

11. On the Template page, select No template, then click Finish to preview your

report output in the Paper Design view. 12. Save the report as condform_your_initials.rdf.

23.3 Add Additional Text

After you add the basic text in the Report Wizard, you need to create some additional text. The text must reside inside of the repeating frame, so before you add text, you will resize the repeating frame. To resize the repeating frame: 1. Click the Paper Layout button in the toolbar to display the Paper Layout view.

2. In the Object Navigator, type R_G_ENAME in the Find field to locate it.

3. Click R_G_ENAME to select it. It is simultaneously selected in the Paper Layout

view. 4. Click the title bar of the Report Editor to make it the active window. 5. Click the bottom handle of R_G_ENAME and drag it down about 4 inches 10 centimeters. To add more text: 1. Click the Text tool in the tool palette. 2. Click about 0.25 inches 0.5 centimeters below the first text object. 3. Type the following text: Because youre one of our top sales representatives, we would like to invite you to a celebration dinner after the picnic. Employees such as yourself brought in over 10 million in increased revenues this year, a 15 increase over last year. The 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 23.1, Prerequisites for This Example describes the sample schema requirements for this example. Tip: Be sure to include hard returns at the end of each line.