Oracle Reports Building Reports 10g (9.0.4) Part Number B10602-01 |
|
Reports Builder enables you to create any type of report that displays barcodes. By using the Oracle 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 Oracle 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 Oracle 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 40.1, "Prerequisites for this example".
Feature | Location |
---|---|
Use the Java importer to add the barcode JavaBean for a paper report. |
Section 40.2.1, "Import the Java classes into Reports Builder" |
Use the Program Unit editor to create a PL/SQL package for a paper report. |
Section 40.2.2, "Create a package to store your information" |
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. |
Section 40.2.4, "Create a data model with two formula columns" |
Create a simple JSP-based Web report. |
|
Create formula columns to call the barcode data for your Web report. |
Section 40.3.2, "Create three formula columns in your data model" |
Edit the JSP code in the Web source view. |
Section 40.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.
http://otn.oracle.com/product/reports/
).
BarcodePaper.zip
and BarCodeWeb.zip
into a temporary directory on your machine (e.g., 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.
oraclebarcode.jar
file, for example:
ORACLE_HOME/Examples/BarCodeBeanPaper/Scripts/oraclebarcode.jar;
or
\ora9ids\reports\j2ee\reports_ ids\web\examples\BarcodeBeanPaper\scripts\oracleb arcode.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 40.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.util.BarCodeConstants.
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;
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. Make sure you save the file in RDF format.
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.
function BeforeReport return boolean is
begin globals.barcode_to_use := BarCodeConstants.BAR_CODE_128; globals.bcobj := barcodemaker.new();
return (TRUE); end;
To modify the type of barcode you want to use, 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.
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
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. Note that this example uses the "Order Entry" portion of the sample schema.
p_order_id
was created, click OK.
The resulting data model should look like this:
function CF_1Formula return VarChar2 is myFileName varchar2(500); result varchar2(500); 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;
LineTotal
.
function LineTotalFormula return Number is begin return (:quantity * :unit_price); end;
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, and another formula column that displays the order total.
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.
2354
.
The steps in this section show you how to build a Web report using JavaServer Pages (JSPs), using the barcode JavaBean you imported in Section 40.2.1, "Import the Java classes into Reports Builder". If you want to build a paper report with a barcode, see Section 40.2, "Create a barcode report for paper".
If you are not familiar with creating a JSP-based Web report and would like to learn how to create one, refer to the Oracle Reports Tutorial, located in the Getting Started with Oracle 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 use 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 40.3.3, "Initialize the barcode JavaBean and set its properties") before you can run the report to the Web.
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 40.1, "Prerequisites for this example" and Section 40.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. The steps in this section will show you how to open an HTML file in Reports Builder and add data to it.
Examples
\BarCodeBeanWeb\source\ShippingLabel.html
.
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. Note that this example uses the "Order Entry" portion of the sample schema.
Your data model should look something like this:
ShippingLabel_<your initials>.jsp
to create 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.
function TrackingNumberFormula return char is begin return(:Customer_id||:Order_ID||:country_ID); end;
function OriginScanFormula return char is begin
return('34324-OH-US');
end;
function DestinationScanFormula return char is begin
return(:postal_code||'-'||:state_province||'-'||:country_ID);
end;
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 enable 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
/BarCodeBeanWeb/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 first update your report with the correct path.
Define Path information for your barcode images
.
d:\\temp\\docroot\\images\\
). Be sure to maintain the integrity of the paths we've provided.
<jsp:useBean id="BC" scope="page" class="oracle.apps.barcode.util.BarCodeConstants" /> <jsp:useBean id="BM" scope="page" class="oracle.apps.barcode.BarCodeMaker" />
Setting the barcodes 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 %>"/>
<%! private String BarCodeData1 = "12345-XX-XX"; %> <%! private String BarCodeData2 = "12345-XX-XX"; %> <%! private String BarCodeData3 = "12345-XX-XX"; %>
Replace this with your RW:FOREACH
open tag.
<rw:foreach id="R_G_SHIPMENT" src="G_SHIPMENT">
</rw:foreach>
**BARCODEShippingTrackingNumber**
.
<!-- 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 %>">
**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 %>">
**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.
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 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:
http://otn.oracle.com/products/reports/
), click Documentation and navigate to the Reports Builder Online Help for the most recent, hosted online help.
|
Copyright © 2002, 2003 Oracle Corporation. All Rights Reserved. |
|