Oracle Reports Building Reports Release 6i A73172-01 |
|
The report described in this chapter will help you learn more about Report Builder features for conditional formatting. You will build a single-query report that records company stock prices, and then displays values using conditional formatting when the price of a stock hits minimum and maximum values.
To build this report, you will use the Report Wizard to create the initial data model and report layout. You will make refinements to the report layout in the Live Previewer. You will also write PL/SQL, which is provided for you.
It is often useful to highlight certain parts of your report when particular conditions are met. For example, you can change the color of a value to red when it is greater than 5000. Report Builder provides two ways of adding conditional formatting to your report:
For many conditions, you often can do what you need using the Conditional Formatting and Format Exception dialog boxes. For other conditions, you may want to use the dialog boxes to get started, and then modify the generated code by editing the Format Triggers.
The following figure illustrates the condition formatting features that you will apply to your report. Table 2-1, "Features demonstrated in this Conditional Formatting sample report", describes the steps you will take to create this report.
The cond.rdf
file contains the report you will create after finishing the tasks in this chapter. You may want to refer to this file while you are working. This file is located in your ORACLE_HOME\TOOLS\DOC60\US\RBBR60
directory.
Feature | Location |
---|---|
Use the Report Wizard to define the SQL and create a first draft of the report. |
Section 2.1, "Creating the initial report with the Report Wizard" |
Modify the report layout for readability using the Live Previewer. |
Section 2.2, "Making simple formatting modifications to the report" |
Add a format exception to a field using the Conditional Formatting dialog box so that the appearance of the field changes when a specified condition is met. |
|
Modifying the code generated by the Format Exception dialog box in order to do additional processing when a specified condition is met. |
Section 2.4, "Adding more functionality to the generated format trigger code" |
Add a formatting exception to a repeating frame in order to make a change that affects a number of report objects at once. |
Section 2.5, "Adding a formatting exception to a repeating frame" |
Modify code generated by the Format Exception dialog boxes to further customize the report. |
To get started, open Report Builder. If the Welcome dialog box appears, click Use the Report Wizard and click OK. If not, choose File->New->Report. Click Use the Report Wizard and click OK.
At some point before you generate the report, you will need to log into the database. Choose File->Connect to connect to the database. Enter the appropriate log on information. See Section 1.3, "Obtaining database access before you start" for details.
The Report Wizard is a great way to start building a report. The Report Wizard alone may give you a report that satisfies your requirements. If it doesn't, you can use the Data Model view, the Live Previewer, and the Layout Model view to further refine your report. For this report, you will start with the Report Wizard, and then use the Live Previewer and Layout Model to modify the layout and add conditional formatting to the report. The steps in this section will help you to create the initial report.
|
Tip: If you are unsure about what to do on any page of the wizard, click Help.
SELECT symbol,
company,
current_price,
trade_date,
number_traded_today,
todays_high,
todays_low
FROM stocks
Tip: Groups are created to organize the columns in your report. When you create a query, Report Builder automatically creates a group that contains the columns selected by the query. You create additional groups to produce break levels in the report in order to create a group above or group left report.
Column | Label | Width |
---|---|---|
Todays High |
Today's High |
9 |
Todays Low |
Today's Low |
9 |
Tip: It is good practice when you are designing your report to save it frequently under a different file name. If you generate an error or if you don't like some of the changes you made, you easily can go back to the previously saved file and make revisions from that point.
At this point, you could return to the Report Wizard and update any of its settings (for example, labels or widths) and regenerate the report. However, in this section, you will make a few edits in the Live Previewer to improve the appearance of the report.
|
Tip: If you accidentally select something and want to deselect it, shift-click on it again to deselect.
Optional Exercise:
Explore the Live Previewer to see what other changes you can make.
The Conditional Formatting dialog box is a great way to start applying formatting exceptions to your layout objects. (For example, you can make a field's value bold when it exceeds a specified maximum value). The Conditional Formatting dialog box alone may satisfy your requirements for creating a formatting exception.
Tip: When you use the Conditional Formatting dialog box, it generates a Format Trigger for the selected object. Consequently, once you directly edit a Format Trigger for an object, you should not go back and use the Conditional Formatting dialog box to make more modifications. If you do, you may lose some of the customized modifications that you made directly to the Format Trigger.
In this section, you will set conditional formatting for two summary fields, :Maxcurrent_pricePerSymbol
and :Mincurrent_pricePerSymbol
. Doing this will flag values if they are outside of the specified maximum and minimum points.
|
Tip: When you select data in the Live Previewer, the corresponding object is highlighted in the Object Navigator, and vice versa.
:Maxcurrent_pricePerSymbol
in the third field next to Equal.
:Mincurrent_pricePerSymbol
to the second row.
Optional Exercises:
In many cases, simply changing formatting attributes as done in Section 2.3, "Adding a formatting exception to a field" may suffice. However, you can also include more sophisticated processing.
The steps in this section will help you to design the report for PDF output and add bookmarks that indicate when stock prices reach a maximum point.
Because you have already generated some code with the Conditional Formatting dialog box, some of the logic you need is already in place.
|
function F_current_priceFormatTrigger return boolean is
begin
-- Automatically Generated from Report Builder.
if ((:current_price = :Maxcurrent_pricePerSymbol) or
(:current_price = :Mincurrent_pricePerSymbol))
then
srw.set_foreground_border_color('black');
srw.set_border_pattern('solid');
srw.set_foreground_fill_color('red');
srw.set_fill_pattern('solid');
srw.set_font_face('Arial');
srw.set_font_size(10);
srw.set_font_weight(srw.bold_weight);
srw.set_font_style(srw.plain_style);
if (:current_price = :Maxcurrent_pricePerSymbol)
then
srw.set_bookmark(:symbol || ' at maximum ');
end if;
end if;
return (TRUE);
end;
Tip: The next four steps require that the Live Previewer be the active window.
Tip: You may be requested to locate the executable that launches your browser. Use the Browse button. Your browser must be configured to use the Acrobat Reader plug-in in order to view the PDF that Report Builder generated.
If you do not have the Acrobat Reader plug-in configured for your browser, you can choose File->Generate to File->PDF, and open the PDF in the stand alone Acrobat Reader.
Tip: When you're making a lot of little changes to your report, it's best to turn off the Web preview feature. Otherwise, the Web preview is constantly updating each small change that you make.
function F_current_priceFormatTrigger return boolean is
begin
-- Automatically Generated from Report Builder.
if ((:current_price = :Maxcurrent_pricePerSymbol) or
(:current_price = :Mincurrent_pricePerSymbol))
then
srw.set_foreground_border_color('black');
srw.set_border_pattern('solid');
srw.set_foreground_fill_color('red');
srw.set_fill_pattern('solid');
srw.set_font_face('Arial');
srw.set_font_size(10);
srw.set_font_weight(srw.bold_weight);
srw.set_font_style(srw.plain_style);
if (:current_price = :Maxcurrent_pricePerSymbol)
then
srw.set_bookmark(:symbol || ' at maximum ');
elsif (:current_price = :Mincurrent_pricePerSymbol)
then
srw.set_bookmark(:symbol || ' at minimum ');
end if;
end if;
return (TRUE);
end;
cond_24.rdf
.
Creating a formatting exception for a single field can be useful, but you can also create a formatting exception that affects a number of objects at once. Report Builder typically groups objects inside of frames or repeating frames. If the objects inside of a frame are transparent, changing the fill color of a repeating frame will effectively change the fill color of the objects inside of it.
In this section, you will change the fill color of an object in a repeating frame.
Name | Function | Source | Reset at |
---|---|---|---|
CS_COUNT |
Count |
symbol |
Report |
By making a simple modification to the code that was generated by the Conditional Formatting and Format Exception dialog boxes, you can make the fill color alternate for even and odd instances of the repeating frame.
Tip: Note that the color specifications in the following code may differ slightly from the colors specified in your code:
function R_G_symbolFormatTrigger return boolean is
begin
-- Automatically Generated from Report Builder.
if (:CS_count mod 2 = '1')
then
srw.set_foreground_fill_color('gray32');
srw.set_fill_pattern('solid');
end if;
-- Automatically Generated from Report Builder.
if (:CS_countmod 2
= '0')
then
srw.set_foreground_fill_color('r50g50b100');
srw.set_fill_pattern('solid');
end if;
return (TRUE);
end;
cond_26.rdf
.
Optional Exercise:
Make the opaque objects on top of R_G_SYMBOL transparent so that you can see its fill color through the other objects.
Tip: Use the Object Navigator to choose the frames contained in the R_G_SYMBOL object.
Congratulations! You have finished the Conditional Formatting sample report. You now know how to:
For more information about conditional formatting, see the online help:
|
|
Copyright © 1999 Oracle Corporation. All Rights Reserved. |
|