Prerequisites for This Example Run Your Report to Paper

45-10 Oracle Reports Users Guide to Building Reports Figure 45–5 Paper Design view for the XML PDS report 8. Save your report. You have created the layout for your paper report.

45.2.5 Apply alternating row colors to your report

Now that you have created the report, you can make it more user-friendly by using a summary column to apply alternating row colors. To create a summary column to count the rows: 1. In the Data Model view, click the Summary Column tool in the tool palette. If you are still in the Paper Design view, you can click the Data Model button in the toolbar to display the Data Model view.

2. Click in the XML query group G_WAREHOUSE_ID1 to create a summary

column.

3. Double-click the new summary column object CS_1 to display the Property

Inspector, and set the following properties: ■ Under General Information, set the Name property to LineNo. ■ Under Column, make sure the Column Type property is set to Summary, and that the Datatype property is set to Number. ■ Under Summary, set the Function property to Count, and set the Source property to PRODUCT_NAME. To create a procedure that changes the row colors:

1. In the Object Navigator, click the Program Units node for your report.

2. Click the Create button in the toolbar to display the New Program Unit dialog box.

3. In the New Program Unit dialog box, type linecolors as in the Name field.

Note: You can also run the provided report inventory_ report.rdf. Before you can run the report, double-click the XML query in the Data Model view, and point the XML data source to the appropriate XSD and XML files. Building a Report with an XML Pluggable Data Source 45-11

4. Select Procedure, and click OK to display the PLSQL Editor for the new program

unit. 5. In the PLSQL Editor, enter the following PLSQL code to change the text color of the alternating rows to blue: PROCEDURE LineColors IS BEGIN if :LineNo mod 2=0 then srw.set_text_colorblue; else srw.set_text_colorblack; end if; END;

6. Click Compile to compile the procedure.

If any errors display, make sure the code is correct, and that you created the summary column in the steps above.

7. Click Close.

To create a format trigger for each field that calls the procedure:

1. In the Object Navigator, under your report name, expand the Paper Layout node

and navigate to Main Section Body M_G_WAREHOUSE_ID_GRPFR R_ G_WAREHOUSE_ID M_G_WAREHOUSE_ID1_GRPFR R_G_ WAREHOUSE_ID1 .

2. Under R_G_WAREHOUSE_ID1, double-click F_PRODUCT_ID to display the

Property Inspector. Note: You can copy and paste this code from the procedure provided in the xmlpds_code.txt file. Just copy the text under Line Colors Procedure. Note: Optionally, you can also change the fill colors of the alternating rows by following the steps in the above section, and using the following PLSQL code. In this example code, we have changed the fill color of alternating rows to red and blue: PROCEDURE LineColors IS BEGIN if :LineNo mod 2=0 then srw.set_foreground_fill_colorblue; srw.set_fill_patternsolid; else srw.set_foreground_fill_colorred; srw.set_fill_patternsolid; end if; END; Note: If you cannot find a particular field, use the Find field at the top of the Object Navigator. 45-12 Oracle Reports Users Guide to Building Reports

3. In the Property Inspector, 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 the following PLSQL code: function F_PRODUCT_IDformatTrigger return Boolean is begin LineColors; return TRUE; end; 5. Add a format trigger for the following fields, using the same code as in the previous step. Be sure not to delete the first line of the code, where the format trigger name is defined: ■ F_PRODUCT_NAME ■ F_QUANTITY_ON_HAND ■ F_WAREHOUSE_ID1 6. Save your report. 7. Click the Run Paper Layout button in the toolbar to run your report to paper. Your report should look something like this: Figure 45–6 XML PDS Report with Alternating Row Colors You have now applied alternating row colors to your report.

45.2.6 Filter your XML data using a group filter

If you have a lot of data in your XML file, you might want to consider sorting and filtering it. You can do so by creating a group filter and a hierarchy. The steps in this section will show you how to create a filter that will only show the inventory items for a user-defined quantity amount. The filter will be based on a parameter that the user Note: Make sure you do not touch the boldface text. Simply type in the code below this text to create the format trigger. You can copy and paste this code from the procedure provided in the xmlpds_code.txt file. Just copy the text under Format Trigger Code. Building a Report with an XML Pluggable Data Source 45-13 can enter at runtime. You will then create a hierarchy in your data model to group the data in your report. To create a user parameter and a group filter: 1. In the Object Navigator, under the User Parameters node, create a new user parameter called P_MAXQTY, with a Datatype of Number, Width of 20, and Initial Value of 50 see Section 4.11.2, Creating a user parameter . 2. In the Data Model view, double-click the G_WAREHOUSE_ID1 group in the XML query to display its Property Inspector.

3. In the Property Inspector, under Group:

■ set the Filter Type property to PLSQL. ■ click the PLSQL filter property field to display the PLSQL Editor. 4. In the PLSQL Editor, use the template to enter the following PLSQL code: function G_WAREHOUSE_ID1GroupFilter return boolean is begin if :quantity_on_hand :P_maxqty then return TRUE; else return false; end if; end;

5. Click Compile, and fix any errors.

6. When the code compiles successfully, click Close.

7. Save your report. 8. Click the Run Paper Layout button in the toolbar to run your report to paper. Notice how a Parameter Form now displays where you can adjust the quantity of items displayed in your report. You can also run the provided report inventoryreport.rdf to view the results in Reports Builder. 9. Save your report. To create a hierarchy for the XML query: 1. In the Data Model view, click the PRODUCT_ID column in the XML query, then drag it between the query name and the G_WAREHOUSE_ID1 group. Your data model should look like this: Note: You can also copy and paste this code from the provided file called xmlpds_code.txt. Copy the code under the heading Group Filter Code. Note: If you are not familiar with compiling PLSQL, refer to a PLSQL reference manual. 45-14 Oracle Reports Users Guide to Building Reports Figure 45–7 Data Model with Group Hierarchy 2. Save your report. You have now created a group hierarchy that sorts the data in your report.

45.3 Run Your Report to Paper

To run your paper report: 1. In the Object Navigator, make sure your report inventoryreport_xml_your_ initials .rdf is selected. 2. Click the Run Paper Layout button in the toolbar to run your report to paper. Notice how the Parameter Form now displays, with the initial value of 50. 3. Your report displays in the Paper Design view, and should look something like this: Note: Notice in the above image that a green circle displays above G_WAREHOUSE_ID1. This circle indicates that a group filter has been created for the group. Building a Report with an XML Pluggable Data Source 45-15 Figure 45–8 Final Paper Design view of the XML PDS example report

45.4 Summary

Congratulations You have successfully used an XML data source for a paper report. You now know how to: ■ create a SQL query from scratch. ■ use the Data Wizard to create an XML query. ■ create a data link between a SQL query and an XML query. ■ create a layout for your report using the Report Wizard. ■ apply alternating row colors to your report using format triggers and procedures. ■ filter your XML data using a group filter and hierarchy. 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 . 45-16 Oracle Reports Users Guide to Building Reports Building a Report with a Text Pluggable Data Source 46-1 46 Building a Report with a Text Pluggable Data Source In this chapter, you will learn about reports that include data from a Text pluggable data source PDS, which is provided with Oracle Reports. By following the steps in this chapter, you can generate the report output shown in Figure 46–1 . Figure 46–1 Report output using a Text PDS Concepts ■ The information you must publish is often derived from data in various corporate data sources. These data sources may be SQL-based relational databases or non-SQL-based, such as character-delimited text. Often, you must combine data from one or more of these data sources to publish meaningful information. For example, you may need to combine data that exists in a relational database with data from a multidimensional database to compare trends and performance. ■ Oracle Reports enables you to leverage capabilities, such as aggregation, summarization, formatting, and scheduling, on data from any data source. You can leverage the pluggable data source PDS architecture to connect to your own 46-2 Oracle Reports Users Guide to Building Reports data source, as well as to the data sources available with Oracle Reports XML, JDBC, and Text. ■ For more information on pluggable data sources, refer to the Oracle Reports online Help. If your data source cannot use an existing PDS, the PDS API enables you to write your own PDS and incorporate it into Oracle Reports to access your own unique data sources. The API is documented in Oracle Reports Java API Reference, available on the Oracle Technology Network Oracle Reports Documentation page http:www.oracle.comtechnologydocumentationreports.html . Example Scenario In this example, you have downloaded the US Census Bureau data in CSV comma-separated values format and want to generate a report. You will learn how to use character-delimited text as a data source to create a paper report. As you build this example report, you will: ■ Set Up the textpds.conf File to Configure Reports Builder to recognize your text file as a pluggable data source. ■ Use the Report Wizard to Create a Report based on the text data source. To see a sample report that uses a Text PDS, open the examples folder named text_ pds, then open census_report.rdf. For details on how to open it, see Accessing the Example Reports in the Preface. The example files used in this chapter are listed and described in Table 46–1 .

46.1 Prerequisites for This Example

To build the example in this chapter, you must have the example files we have provided see Example Scenario , above.

46.2 Set Up the textpds.conf File

Before you can use a text file as a data source, you must set up the Text PDS configuration file textpds.conf with your text files format information. With this data definition in the configuration file, Oracle Reports Builder can recognize your text file as a valid data source. To set up your textpds.conf: 1. In a text editor, such as Notepad, open the file textpds.conf, located in the ORACLE_HOME reportsconf directory. Table 46–1 Example report files File Description text_pds\census_report.rdf The finished RDF for your report. text_pds\census_report.pdf A PDF version of your finished report. text_pds\census_csv.txt The character-delimited data downloaded from the US Census Bureau Web site. text_pds\config.txt Code for the textpds.conf file. Note: You must edit your configuration file before you launch or restart Reports Builder for the changes to take effect. Building a Report with a Text Pluggable Data Source 46-3 2. In another text editor window, open the provided file config.txt file. 3. Copy the text we have provided in config.txt and paste it into textpds.conf before the textPDS entry, so that the resulting textpds.conf file contains an entry like this: Figure 46–2 Snapshot of the textpds.conf entry

4. Save the textpds.conf file.

You have set up your textpds.conf file for the character-delimited text data source.

46.3 Use the Report Wizard to Create a Report

When you create a report, you can either use the Report Wizard to assist you or create the report yourself. To build the simple report in this example, you can use the Report Wizard. Before you use a Text pluggable data source, you might want to examine the text file first to see what it looks like. You can open the census_csv.txt file in a text editor, like Notepad or WordPad, to see the data we will be using in this example. To create a simple report:

1. Now that you have updated the textpds.conf file, launch Reports Builder.

2. In the Welcome 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.

Note: ORACLE_HOME is where Reports Builder is installed on your computer. Note: The fileFormat entry in textpds.conf enables Reports Builder to recognize your text file as a data source. When you choose Text PDS in the Report Wizard, the defined format CensusCSV, in this example displays as an option. In the fileFormat entry, you also define the properties of each column in the file. Tip: If Reports Builder was already open when you modified the textpds.conf file, you must shut down Reports Builder and restart it for Reports Builder to recognize your text file as a valid data source.