| Oracle9i Reports Building Reports Release 9.0 Part Number A92101-01 |
|
Reports Builder enables you to create any type of report that displays barcodes. By using the Oracle9i Reports barcode JavaBean, you can build reports for the Web or for paper that display a barcode to make tasks like tracking shipping orders and employee identification numbers easier. In Reports 6i, you had to use a barcode font to generate the barcode. In Oracle9i Reports Builder, the JavaBean automatically generates the barcode for you.
To learn more about the barcode JavaBean, visit the Oracle Technology Network (http://otn.oracle.com/products/reports/), then click Getting Started with Oracle9i Reports and click PL/SQL-Java Bridge in the navigation bar.
You will build two reports in this section, one for paper and one for the Web. The paper report shows an invoice for a single customer who has ordered multiple items from a company. The barcode indicates the tracking information for the order.
To build either of these reports, you must first refer to Section 1.1, "Prerequisites for this example".
| Feature | Location |
|---|---|
|
Use the Java importer to add the barcode JavaBean for a paper report. |
Section 1.2.1, "Import the Java classes into Reports Builder" |
|
Use the Program Unit editor to create a PL/SQL package for a paper report. |
|
|
Create a Before Report trigger to set up your barcode JavaBean for a paper report. |
|
|
Use the Data Model view and toolbar to create a data model with a formula column for a paper report. |
|
|
Create a simple JSP-based Web report. |
|
|
Create formula columns to call the barcode data for your Web report. |
Section 1.3.2, "Create three formula columns in your data model" |
|
Edit the JSP code in the Web source view. |
Section 1.3.3, "Initialize the barcode JavaBean and set its properties" |
|
View your JSP-based Web report in a browser. |
To build the examples in this manual, you must have the example files we've provided, as well as access to the sample schema that is shipped with the Oracle9i database.
If you haven't already done so, you can download the files you'll need to complete this example from the Oracle Technology network and install them on your machine.
d:\temp").
d:\orawin90\examples).
This zip file contains the following files:
If you don't know if you have access to the sample schema provided with the Oracle9i database, contact your database administrator. You should have access to the "Order Entry" portion of the schema to complete this example.
Before you use a Reports JavaBean (for paper or the Web), you need to perform several steps. You first need to set up your environment to use the correct classpath for the bean. For a paper report, you must then use the Java Importer to import the JavaBean into Reports Builder. For a Web report, you must call the JavaBean from your JSP-based (JavaServer Page) report.
In this section, you will update the Reports class path with the location of the JavaBean. When you launch Reports Builder, it will use this new class path to recognize the location of the barcode bean.
ORACLE_HOME/Examples/BarCodeBeanPaper/Scripts/oraclebarcode.jar;
You are now ready to begin building your report.
In this section, you will create a paper-based report that shows the invoice for a particular customer. This invoice will display the address of the customer, his order, and a barcode that represents the tracking number for the order. The company can scan this barcode to find out the status of the order.
Next, you will import the JavaBean, then create a barcode report for paper (Acrobat PDF). If you want to learn how to create a barcode JSP-based report for the Web, skip to Section 1.3.
To create a paper report using the barcode JavaBean, you must first import two Java classes into Reports Builder. When you import these Java classes, Reports Builder automatically creates the packages you need to build the report.
oracle.apps.barcode.BarCodeMaker.
In this report, you want to create a package where the information will be stored.
globals.
PACKAGE globals IS
bcobj ora_java.jobject; barcode_to_use varchar2(256); tempdir varchar2(100); directory_sep varchar2(2);
END
You can also copy and paste the code from the complete example (Examples\BarCodeBeanPaper\source\ShippingManifest.rdf). Open the RDF in the Object Navigator. Under the example name, open the Program Units node. You should see the "Globals" package body listed. Open this package, then copy and paste the code from this package into your new program unit.
shippingmanifest_<your initials>.rdf (e.g., shippingmanifest_vw) and make sure you save it to a new directory (e.g., "My Examples"), where your new files are stored.
You have created a package that will contain the global information for your report.
You can use the Before Report trigger to initialize specific tasks that will run before the report runs. Here, you will define the type of barcode you want to use in your report, as well as the temporary directory where your barcode images will be stored.
SHIPPINGMANIFEST_<your initials>, click the Report Triggers node.
function BeforeReport return boolean is
begin globals.barcode_to_use := BarCodeConstants.BAR_CODE_128; globals.bcobj := barcodemaker.new();
return (TRUE); end; You can change the value BarCodeConstants.BAR_CODE_128 to any other valid value. To determine which values are valid, check the contents of the package by opening the BarCodeConstants package spec in the Object Navigator, under the Program Units node.
You have created a trigger that will set up the barcode type for you when you run the report.
In this section, you will manually create the query that the report will use to retrieve data from the sample schema. You will also create a formula column that will communicate with the JavaBean to create the barcode, then return the file name of the generated image.
SHIPPINGMANIFEST_<your initials>, double-click Data Model to display the Data Model view for your report.
SELECT ALL CUSTOMERS_A1.CUST_FIRST_NAME,
CUSTOMERS_A1.CUSTOMER_ID, CUSTOMERS_A1.CUST_LAST_NAME, CUSTOMERS_A1.CUST_ADDRESS.STREET_ADDRESS, CUSTOMERS_A1.CUST_ADDRESS.POSTAL_CODE, CUSTOMERS_A1.CUST_ADDRESS.CITY, CUSTOMERS_A1.CUST_ADDRESS.STATE_PROVINCE, CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID, ORDERS.ORDER_ID, ORDERS.ORDER_DATE, ORDERS.ORDER_TOTAL, ORDER_ITEMS.LINE_ITEM_ID, PRODUCTS.PRODUCT_NAME, ORDER_ITEMS.UNIT_PRICE, ORDER_ITEMS.QUANTITY, COUNTRIES.COUNTRY_NAME FROM CUSTOMERS CUSTOMERS_A1, ORDER_ITEMS, ORDERS, PRODUCTS, HR.COUNTRIES
WHERE ((ORDER_ITEMS.ORDER_ID = ORDERS.ORDER_ID)
AND (ORDERS.CUSTOMER_ID = CUSTOMERS_A1.CUSTOMER_ID) AND (ORDER_ITEMS.PRODUCT_ID = PRODUCTS.PRODUCT_ID) AND (CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID = HR.COUNTRIES.COUNTRY_ID)) AND ORDERS.ORDER_ID = :P_ORDER_ID
ORDER BY order_ID, line_item_ID
You can also copy and paste the code from the complete example
(Examples\BarCodeBeanPaper\source\ShippingManifest.rdf). Open
the RDF in the Object Navigator. Under the example name, double-click Data
Model to display the Data Model view. Double-click the query (entitled Q_1) to
display the SQL Query Statement field.
If you are not connected to a database that contains the sample schema we've provided, you must log in now. If you're not sure what your connection string is, contact your database administrator.
p_order_id was created, click OK.
The resulting data model should look like this:
The Property Inspector for the formula column (CF_1) displays.
function CF_1Formula return Char is myFilename varchar2(20); result varchar2(20); barcodeData VarChar2(50) := :customer_ID || :order_ID; begin myFileName := srw.create_temporary_filename; barcodemaker.setBarWidthInch(globals.bcobj, 0.005); barcodemaker.setBaseCodeData(globals.bcobj,barcodeData); barcodemaker.setBarCodeType(globals.bcobj,globals.barcode_to_use); barcodemaker.setFullPath(globals.bcobj, myFileName); barcodemaker.renderBarCode(globals.bcobj); return(myfilename); end;
You can also copy and paste the code from the complete example (Examples\BarCodeBeanPaper\source\ShippingManifest.rdf). Open the RDF in the Object Navigator. In the Data Model view, open the Property Inspector for the formula column called "CF_1." Click the PL/SQL Formula property to display the code for the formula column.
Yes.
Image.
You have created the data model for your barcode report, which contains a formula column that retrieves the barcode information and displays the barcode image on your report.
Your data model and the PL/SQL for the formula column should look similar to this:
Before you can run your report, you must create a layout.
You have completed the layout for your paper report. When the report runs, the Runtime Parameter Form displays. Next to P_ORDER_ID, type 2354.
Your report displays in the Paper Design view, and should look something like the following:
The steps in this section show you how to build a Web report using JavaServer Pages (JSPs), that uses the barcode JavaBean you imported in Section 1.2.1, "Import the Java classes into Reports Builder". If you want to build a paper report with a barcode, see Section 1.2, "Create a barcode report for paper".
If you are not familiar with creating a JSP-based Web report and would like an introduction to building them, refer to the Oracle9i Reports Tutorial, located in the Getting Started with Oracle9i Reports Web site on the Oracle Technology Network (http://otn.oracle.com/reports/).
The report you will create in this section is the same as the one you created for paper. You will create a report that displays the invoice for a particular customer. This invoice will display the address of the customer, his order, and a barcode that represents the tracking number for the order. The company can scan this barcode to find out the status of the order.
You can run the final version of the JSP report we've provided to see what you'll build in these steps, but please note that you will need to update the location of the images in the source code (see Section 1.3.3.1, "Update the paths to the assets") before you can run the report to the Web.
If you're not familiar with creating a JSP-based Web report, refer to the Oracle9i Reports Tutorial to learn how to create a simple JSP-based Web report.
|
Note: Before you begin this section, make sure you have all the necessary files, and that you've imported the Java classes, and set up the class path. See Section 1.1, "Prerequisites for this example" and Section 1.2.1, "Import the Java classes into Reports Builder". |
When you create a JSP-based Web report, you can use an existing HTML file as a template.
If you don't know how to open the file, follow these steps:
SELECT ALL CUSTOMERS_A1.CUST_FIRST_NAME,
CUSTOMERS_A1.CUSTOMER_ID, CUSTOMERS_A1.CUST_LAST_NAME, CUSTOMERS_A1.CUST_ADDRESS.STREET_ADDRESS, CUSTOMERS_A1.CUST_ADDRESS.POSTAL_CODE, CUSTOMERS_A1.CUST_ADDRESS.CITY, CUSTOMERS_A1.CUST_ADDRESS.STATE_PROVINCE, CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID, ORDERS.ORDER_ID, ORDERS.ORDER_DATE, ORDERS.ORDER_TOTAL, COUNTRIES.COUNTRY_NAME FROM CUSTOMERS CUSTOMERS_A1, ORDERS, HR.COUNTRIES
WHERE ((ORDERS.CUSTOMER_ID = CUSTOMERS_A1.CUSTOMER_ID) AND (CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID = HR.COUNTRIES.COUNTRY_ID)) AND ORDERS.ORDER_ID = :P_ORDER_ID ORDER BY order_ID
If you are not connected to a database that contains the sample schema we've provided, you must log in now. If you're not sure what your connection string is, contact your database administrator.
G_SHIPMENT, then press Enter.
Doing so renames the group "G_SHIPMENT."
ShippingLabel_<your initials>.jsp.
Doing so creates the JSP-based Web source for this report.
You have now created the query that will pull in the data for your report.
You will need to create three formula columns in your report to retrieve the tracking number for the order, the origin of the order, and the destination for the order.
TrackingNumber.
function TrackingNumberFormula return char is begin
return(:Customer_id||:Order_ID||:country_ID);
end;
You can also copy and paste the code from the complete example
(Examples\BarCodeBeanWeb\source\ShippingManifestWeb.rdf). Open the RDF in the
Object Navigator. Double-click the Data Model node to display the data model.
In the group, scroll down to find the "TrackingNumber" formula column, then
open the Property Inspector for the column. Click the field next to "PL/SQL
Formula" to display the code.
The new formula column, TrackingNumber, displays in the data model.
To create the OriginScan formula column:
function OriginScanFormula return char is begin
return('34324-OH-US');
end; You can also copy and paste the code from the complete example (Examples\BarCodeBeanWeb\source\ShippingManifestWeb.rdf). Open the RDF in the Object Navigator. Double-click the Data Model node to display the data model. In the group, scroll down to find the "OriginScan" formula column, then open the Property Inspector for the column. Click the field next to "PL/SQL Formula" to display the code.
The new formula column, OriginScan, displays in the data model.
To create the DestinationScan formula column:
DestinationScan.
function DestinationScanFormula return char is begin
return(:postal_code||'-'||:state_province||'-'||:country_ID);
end; You can also copy and paste the code from the complete example (Examples\BarCodeBeanWeb\source\ShippingManifestWeb.rdf). Open the RDF in the Object Navigator. Double-click the Data Model node to display the data model. In the group, scroll down to find the "DestinationScan" formula column, then open the Property Inspector for the column. Click the field next to "PL/SQL Formula" to display the code.
The new formula column, DestinationScan, displays in the data model.
You have created the three formula columns that will hold the values for the tracking number, the origin, and the destination of the order. Your data model should look something like this:
To tell your JSP-based Web report to communicate with the JavaBean, you need to initialize it in the JSP. Unlike using the JavaBean with a paper report, you do not need to use the Java importer to import the Java classes.
In this section, you will also learn how to set the properties for the bean so that the correct data is being used to produce the barcode.
If you don't want to bother with typing the code in yourself, you can always open the source file (Examples/BarCodeWeb/source/ShippingManifestWeb.rdf) and copy the appropriate pieces of the Web source into your report.
To ensure that the JavaBean references the correct barcode images, you must update your report with the correct path.
ShippingLabel_<your initials>.
In the Data Model view of your report, click the Web Source icon.
Define Path information for your barcode images.
To initialize the JavaBean:
<jsp:useBean id="BC" scope="page" class="oracle.apps.barcode.util.BarCodeConstants" /> <jsp:useBean id="BM" scope="page" class="oracle.apps.barcode.BarCodeMaker" />
To set the JavaBean properties:
Setting the barcode's properties.
<jsp:setProperty name="BM" property="BarCodeType" value="<%= BC.BAR_CODE_ 128 %>" /> <jsp:setProperty name="BM" property="BarWidthInch" value="0.01"/> <jsp:setProperty name="BM" property="Directory" value="<%= BarcodePhysicalPath %>"/>
To define the barcode variables:
<%! private String BarCodeData1 = "12345-XX-XX"; %> <%! private String BarCodeData2 = "12345-XX-XX"; %> <%! private String BarCodeData3 = "12345-XX-XX"; %>
To create a For Each loop:
Replace this with your RW:FOREACH open tag.
<rw:foreach id="R_G_SHIPMENT" src="G_SHIPMENT>
</rw:foreach>
**BARCODETrackingNumber**.
<!-- Get the value of the TrackingNumber and assign it to the variable --> <rw:getValue id="BarCodeData1" src="TrackingNumber"/> <!-- Set the data for tbe barcode and the filename --> <jsp:setProperty name="BM" property="BaseCodeData" value="<%= BarCodeData1 %>"/> <jsp:setProperty name="BM" property="FileName" value="<%= BarCodeData1 %>"/> <!-- Render the barcode --> <% BM.renderBarCode(); %> <!-- View the image in the page --> <img src="assets/barcodes/<%= BarCodeData1 %>">
The line beginning with "<!--" are comments. If you don't want comments in your code, you don't have to add these lines.
**BARCODEOriginScan**.
<!-- Get the value of the OriginScan and assign it to the variable --> <rw:getValue id="BarCodeData2" src="OriginScan"/> <!-- Set the data for tbe barcode and the filename --> <jsp:setProperty name="BM" property="BaseCodeData" value="<%= BarCodeData2 %>"/> <jsp:setProperty name="BM" property="FileName" value="<%= BarCodeData2 %>"/> <!-- Render the barcode --> <% BM.renderBarCode(); %> <!-- View the image in the page --> <img src="assets/barcodes/<%= BarCodeData2 %>">
The line beginning with "<!--" are comments. If you don't want comments in your code, you don't have to add these lines.
**BARCODEDestinationScan**.
<!-- Get the value of the DestinationScan and assign it to the variable --> <rw:getValue id="BarCodeData3" src="DestinationScan"/> <!-- Set the data for tbe barcode and the filename --> <jsp:setProperty name="BM" property="BaseCodeData" value="<%= BarCodeData3 %>"/> <jsp:setProperty name="BM" property="FileName" value="<%= BarCodeData3 %>"/> <!-- Render the barcode --> <% BM.renderBarCode(); %> <!-- View the image in the page --> <img src="assets/barcodes/<%= BarCodeData3 %>">
Since you've created a Web report, you must run this report to the Web to see your results.
ShippingManifestWeb_<your initials>, is selected in the Object Navigator.
Your report displays in your Web browser, and should look something like this:
Congratulations! You have created a paper report and a JSP-based Web report that use the barcode JavaBean to generate barcode images.
You now know how to:
For more information on JSPs (JavaServer Pages), refer to the Oracle9i Reports Tutorial or the Reports Builder online help.
|
|
![]() Copyright © 2002 Oracle Corporation. All Rights Reserved. |
|