Академический Документы
Профессиональный Документы
Культура Документы
Reports Builder enables you to use any data source you wish. In this chapter, you will learn how to use the XML pluggable data source that is provided with Oracle Reports.
41-1
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 PDS (pluggable data source) architecture to connect to your own data source, as well as to the data sources available with Oracle Reports (XML, JDBC, text, and Express). For more information on pluggable data sources, refer to the Reports Builder online help and the Javadoc documentation for the PDS APIs.
Example Scenario
Suppose you have an international business with warehouses in the United States and overseas. These warehouses are running a de-centralized management system that stores the operational data locally at each site. The inventory of the warehouses are managed by the local managers. However, for planning purposes, a team at corporate headquarters needs to access the inventory data (in SQL), including the most recent data, of every warehouse. The warehouse data is only available as an XML stream. In this example, you will learn how to combine data from a local database (i.e., the warehouse data) and data from an XML feed to create a Web report. In this example, you will use static XML files that weve provided for you. The report will access the XML feed online using the business-to-business interface of your order entry system.
Table 411 Features Demonstrated in this example Feature Manually create a SQL query. Use the Data Wizard to create an XML query. Create a data link between a SQL query and an XML query. Use the Report Wizard to create a layout for your report. Use format triggers and procedures to apply alternating row colors. Location Section 41.2.1, "Create a SQL query for your new report" Section 41.2.2, "Create an XML query to access your XML data source" Section 41.2.3, "Create a data link between two queries" Section 41.2.4, "Create a layout for your report using the Report Wizard" Section 41.2.5, "Apply alternating row colors to your report"
41-2
Table 411 Features Demonstrated in this example Feature Use a group filter to sort your XML data. Location Section 41.2.6, "Filter your XML data using groups"
Go to the Oracle Technology Network Web site (http://otn.oracle.com/products/reports/). Click Getting Started with Oracle Reports. Click Index, then browse through the list of examples and find the "Building a Report using an XML Pluggable Data Source" example. Download the file XML_PDS.zip into a temporary directory on your machine (e.g., d:\temp). Unzip the contents of the file, maintaining the directory structure, into an examples directory on your machine (e.g., d:\orawin90\examples). This zip file contains the following files:
Table 412 Files necessary for building this sample report using XML PDS File Examples\XML_PDS\result\inventory_ report.pdf Examples\XML_PDS\result\inventory_ report.rdf Description The final PDF version of the paper report. The final RDF version of the paper report.
41-3
Table 412 Files necessary for building this sample report using XML PDS File Examples\XML_PDS\scripts\XMLPDS_ code.txt Examples\XML_PDS\scripts\warehouse_ inventory.xml Examples\XML_PDS\scripts\warehouse_ inventory.xsd Description The various SQL statements you will use in this report. The XML data source for the query in your report. The XML data stream for your report.
Note: The index.html file and assets directory are used as part of the Getting Started with Oracle Reports Web site. Please do not delete or move these files
Launch Reports Builder (or, if already open, choose File > New > Report)
41-4
2.
In the Welcome or New Report dialog box, select Build a new report manually, then click OK. Your new report displays in the Object Navigator as something like "MODULE 2." You will also see the Data Model view of your new report.
3.
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 to display the SQL Query Statement dialog box. In the SQL Query Statement field, type the following code:
select W.WAREHOUSE_ID, W.WAREHOUSE_NAME, L.CITY, L.STATE_PROVINCE, C.COUNTRY_NAME WAREHOUSES W, HR.LOCATIONS L, HR.COUNTRIES C ( W.LOCATION_ID = L.LOCATION_ID (+) ) ( L.COUNTRY_ID = C.COUNTRY_ID (+) ) C.COUNTRY_NAME, W.WAREHOUSE_NAME
4.
from
Note: You can also copy and paste the code from the text file weve provided, xmlpds_code.txt. Open the file in a text editor, then copy the List of Warehouse query into the SQL Query Statement field.
5.
Click OK.
Note: If the Connect dialog box displays, enter the user ID, password, and name of the database that contains the sample schema.
The data model displays in the Data Model view, and should look something like this:
41-5
Figure 412 Data Model for the XML PDS example SQL query
6.
You have created a SQL query to retrieve the data for your report.
In the Data Model view, choose Insert > Query to display the Data Wizard. If the Data Wizard Welcome page displays, click Next. On the Query page, click Next. On the Data Source page, click XML Query, then click Next. On the Data page, click Query Definition to display the Define XML Query dialog box. In the Define XML Query dialog box, under Data Definition, click Browse to locate the XSD file weve provided, warehouse_inventory.xsd and open it. Under Data Source, click Browse to locate the XML file weve provided that contains your data, warehouse_inventory.xml and open it.
41-6
If you want to compare your data definition to the one we provided, make sure that you replace the data definition locations with the locations of your files.
8. 9.
Click OK. In the Data Wizard, still on the Data page, click Next. something like this:
10. Click Finish to display your data model in the Data Model view. It should look
Figure 413 Data model for the XML PDS example with XML and SQL queries
You have created an XML query to access the XML data source weve provided.
In the Data Model view, click the Data Link tool in the tool palette. Click the WAREHOUSE_ID column in your first query (Q_1). Drag your cursor until it is over the WAREHOUSE_ID1 column in the second query (Q_2). Your data model should now look something like this:
41-7
Figure 414 Data Model with a data link between a SQL query and an XML query
Youll notice that the WAREHOUSE_ID column is now highlighted at the bottom of Q_1, with a line pointing to the WAREHOUSE_ID1 column.
4.
You have created a data link between the WAREHOUSE_ID columns in the two queries.
41.2.4 Create a layout for your report using the Report Wizard
Before you can run any report, you must define a layout. The easiest way to do this is to use the Report Wizard.
In the Data Model view, right-click on the canvas, then choose Report Wizard. In the Report Wizard, on the Report Type page, select Create Paper Layout only, then click Next. On the Style page, select Group Above. On the Groups page, make sure the G_WAREHOUSE_ID and G_ WAREHOUSE_ID1 groups are listed in the Group Fields list with a Down Print Direction. On the Fields page, click the double right arrows (>>) to move all of the fields to the Displayed Fields list.
5.
41-8
6. 7.
On the Labels page, adjust the labels as desired. On the Template page, select Predefined Template and click Beige, then click Finish to display your report output in the Paper Design view. It should look something like this:
Figure 415 Paper Design view for the XML PDS report
8.
In the Data Model view, click the Summary Column tool in the tool palette.
41-9
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. 3.
Click in the XML query group (G_WAREHOUSE_ID1) to create a summary column. Double-click the new summary column object (CS_1) to display the Property Inspector, and set 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.
In the Object Navigator, click the Program Units node for your report. Click the Create button in the toolbar to display the New Program Unit dialog box. In the New Program Unit dialog box, type linecolors as in the Name field. Select Procedure, and click OK to display the PL/SQL Editor for the new program unit. In the PL/SQL Editor, enter the following PL/SQL 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_color('blue'); else srw.set_text_color('black'); end if; END;
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.
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.
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 PL/SQL code. In this example code, weve 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_color(blue); srw.set_fill_pattern('solid'); else srw.set_foreground_fill_color(red); srw.set_fill_pattern('solid'); end if; END;
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 Body > M_G_WAREHOUSE_ID_GRPFR > R_G_ WAREHOUSE_ID > M_G_WAREHOUSE_ID1_GRPFR > R_G_ WAREHOUSEID1. While F_PRODUCT_ID is selected, press F4 to display the Property Inspector.
Note: If you cant find a particular field, use the Find field at the top of the Object Navigator.
2.
3. 4.
In the Property Inspector, under Advanced Layout, click the Format Trigger property field to display the PL/SQL Editor. In the PL/SQL Editor, use the template to enter the following PL/SQL code:
function F_PRODUCT_IDformatTrigger return Boolean is
41-11
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.
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:
6. 7.
Save your report. Click the Run Paper Layout button in the toolbar to your report to paper. Your report should look something like this:
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. Once youve created a new user parameter by clicking the User Parameter node, then clicking Create, you can press F4 to display its Property Inspector.
Tip:
2. 3.
In the Data Model view, double-click the G_WAREHOUSE_ID1 group in the XML query to display its Property Inspector. In the Property Inspector, under Group:
set the Filter Type property to PL/SQL. click the PL/SQL filter property field to display the PL/SQL Editor.
4.
In the PL/SQL Editor, use the template to enter the following PL/SQL code:
function G_WAREHOUSE_ID1GroupFilter return boolean is begin if :quantity_on_hand < :P_maxqty then return (TRUE); else return (false); end if; end;
41-13
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."
5.
6. 7. 8.
When the code compiles successfully, click Close. Save your report. 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 file Examples\XML_ PDS\source\inventoryreport.rdf to view the results in Reports Builder.
9.
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:
Figure 417
Note: Noticed in the above image that a green circle now displays above G_WAREHOUSE_ID1. This circle indicates that a group filter has been created for the group.
2.
Save your report. You have now created a group filter that sorts the data in your report.
In the Object Navigator, make sure your report (inventoryreport_xml_ <your initials>.rdf) is selected. 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. Your report displays in the Paper Design view, and should look something like this:
41-15
Summary
Figure 418 Final Paper Design view of the XML PDS example report
41.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 Reports Builder Online Help, which you can access in two ways:
From the Oracle Technology Network (http://otn.oracle.com/products/reports/), click Documentation and navigate to the Reports Builder Online Help for the most recent, hosted online help. From Reports Builder, choose Help > Help Contents.
Summary
Note: You can replace your Reports Builder online help with the most recent update by downloading the latest online help set available on the Oracle Technology Network (http://otn.oracle.com/docs/products/reports/). Instructions for replacing your help file are included in the readme.txt in the download file.
41-17
Summary