Skip Headers
Oracle® Fusion Middleware Oracle Reports User's Guide to Building Reports
11g Release 1 (11.1.1)

Part Number B32122-03
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

43.2 Create a Barcode Report for Paper

In this section, you will import the barcode JavaBean, then 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.

43.2.1 Import the Java classes into Reports Builder

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.

Note:

You do not need to perform this task if you are creating a Web report, as you will write JSP code that calls the JavaBean.

To import the Java classes:

  1. Launch Reports Builder.

    Note:

    You must launch Reports Builder now so that the new REPORTS_CLASSPATH is used.

  2. Close the Welcome dialog box by clicking Cancel.

  3. Choose Program > Import Java Classes to display the Import Java Classes dialog box.

  4. Under Select Java Classes, navigate to:

    oracle.apps.barcode.util.BarCodeConstants
    

    Note:

    If you do not see this class listed, try exiting Reports Builder and make sure the REPORTS_CLASSPATH reads correctly. Then, launch Reports Builder again.

  5. Select the class, then click Import.

  6. Once the packages have been created, import the second JavaBean: oracle.apps.barcode.BarCodeMaker.

  7. Click Close.

  8. In the Object Navigator, under the report named MODULE 1, click the Program Units node. You will notice that Reports Builder created two package specifications and two package bodies named BARCODECONSTANTS and BARCODEMAKER.

43.2.2 Create a package to store your information

In this report, you want to create a package where the information will be stored.

To create a package for storing your information:

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

  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 globals.

  4. Select Package Spec, then click OK to display the PL/SQL Editor:

  5. In the PL/SQL Editor, type the following code:

    PACKAGE globals IS
      bcobj ora_java.jobject;
      barcode_to_use varchar2(256);
      tempdir varchar2(100);
      directory_sep varchar2(2);
    END;
    

    Note:

    You can also enter this code by copying and pasting it from the provided text file called barcode_code.txt.

  6. Click Compile to make sure there are no errors in your code.

    Note:

    If your code does not compile, make sure you have typed in exactly the code we have provided.

  7. Once the code is compiled, click Close.

  8. In the Object Navigator, click your report name (for example, MODULE 1).

  9. Save the report as shippingmanifest_your_initials.rdf.

You have created a package that will contain the global information for your report.

43.2.3 Create a Before Report trigger

You can use a Before Report trigger to perform specific tasks before the report is run. 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.

To create a Before Report trigger:

  1. In the Object Navigator, under SHIPPINGMANIFEST_your_initials, expand the Report Triggers node, then double-click the icon next to BEFORE REPORT to display the PL/SQL Editor.

  2. In the PL/SQL Editor, use the template to enter the following PL/SQL code:

    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.

    Note:

    You can enter this code by copying and pasting it from the provided text file called barcode_code.txt.

  3. Click Compile to make sure there are no errors.

    Note:

    If you have errors, make sure you have imported the necessary Java classes and compare your code closely with the code above. If you change the code, be sure to compile it again.

  4. When the code is compiled, click Close. Notice how the node icon next to the BEFORE REPORT trigger has changed.

  5. Save your report.

You have created a trigger that will set up the barcode type for you when you run the report.

43.2.4 Create a query in the Data Model view

In this section, you will manually create the query that the report will use to retrieve data from the sample schema.

To create the query:

  1. In the Object Navigator, under SHIPPINGMANIFEST_your_initials, double-click the view icon next to the Data Model node to display the Data Model view for your report.

  2. 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.

  3. In the SQL Query Statement field, enter the following SELECT statement:

    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
    

    Note:

    You can enter this query in any of the following ways:

    • Copy and paste the code from the provided text file called barcode_code.txt into the SQL Query Statement field.

    • Click Query Builder to build the query without entering any code manually.

    • Type the code in the SQL Query Statement field.

  4. Click OK.

    If you are not connected to a database that contains the sample schema we have provided, you must log in now. If you are not sure what your connection string is, contact your database administrator. Note that this example uses the Order Entry sample schema.

  5. When a message displays indicating that the bind parameter p_order_id was created, click OK.

  6. In the data model you just created, select all of the following columns using Shift-click, then drag them below the current query to create a detail group:

    • LINE_ITEM_ID

    • PRODUCT_NAME

    • UNIT_PRICE

    • QUANTITY

    The resulting data model should look like this:

    Figure 43-2 Data Model for the query

    Description of Figure 43-2 follows
    Description of "Figure 43-2 Data Model for the query"

43.2.5 Create a formula column to retrieve the barcode image

In this section, you will create a formula column that will communicate with the JavaBean to create the barcode, then return the file name of the generated image.

To create a formula column:

  1. In the Data Model view, click the Formula Column tool in the tool palette.

  2. Click in the master group (G_CUST_FIRST_NAME) to create a new formula column.

  3. Double-click the new formula column object (CF_1) to display the Property Inspector, and set the following properties:

    • Under General Information, set the Name property to ImageFilename.

    • Under Column:

      • Set the Datatype property to Character

      • Set the Width property to 500

      • Set the Read from File property to Yes

      • Set the File Format property to Image

    • Under Placeholder/Formula, click the PL/SQL Formula 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 ImageFilenameFormula 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;
    

    Note:

    You can enter this code by copying and pasting it from the provided text file called barcode_code.txt.

  5. Click Compile to make sure there are no errors.

    Note:

    If you have errors, make sure you have imported the necessary Java classes and compare your code closely with the code above. If you change the code, be sure to compile it again.

  6. When the code is compiled, click Close.

43.2.6 Create a formula column that returns the order total

To create the second formula column:

  1. In the Data Model view, create a formula column in the detail group G_LINE_ITEM_ID.

  2. Open the Property Inspector for the formula column, and set the following properties:

    • Under General Information, set the Name property to LineTotal.

    • Under Column, make sure the Datatype property is set to Number.

    • Under Placeholder/Formula, click the PL/SQL Formula property field to display the PL/SQL Editor.

  3. In the PL/SQL Editor, use the template to enter the following PL/SQL code:

    function LineTotalFormula return Number is
    begin
      return (:quantity * :unit_price);
    end;
    

    Note:

    You can enter this code by copying and pasting it from the provided text file called barcode_code.txt.

  4. Click Compile to make sure there are no errors.

  5. When the code is compiled, click Close.

  6. Save the report.

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:

Figure 43-3 Data Model with two new formula columns

Description of Figure 43-3 follows
Description of "Figure 43-3 Data Model with two new formula columns"

43.2.7 Create a layout for your report

Before you can run your report, you must create a layout.

To create a paper layout:

  1. Under your report's node in the Object Navigator, right-click Paper Layout, then choose Report Wizard.

  2. In the Report Wizard, on the Report Type page, select Create Paper Layout Only, then click Next.

  3. On the Style page, select Group Above, then click Next.

  4. On the Data Source page, click Next.

  5. On the Data page, click Next.

  6. On the Groups page, make sure the following fields are listed in the Group Fields list (if not, use the arrows to move the field to the appropriate list):

    • ORDER_ID

    • ORDER_DATE

    • CUSTOMER_ID

    • CUST_FIRST_NAME

    • CUST_LAST_NAME

    • STREET_ADDRESSS

    • POSTAL_CODE

    • COUNTRY_NAME

    • CITY

    • STATE_PROVINCE

    • COUNTRY_ID

    • ORDER_TOTAL

    • CF_1

  7. On the Fields page, click the double right arrows (>>) to move all of the fields to the Displayed Fields list, then click Finish.

  8. In the Paper Layout view, click the Run Paper Layout button in the toolbar to run your report.

  9. In the Runtime Parameter Form, next to P_ORDER_ID, type 2354.

  10. Once your report displays in the Paper Design view, you can rearrange your layout objects in the Paper Layout view to make your report look something like Figure 43-4. To create this format:

    • In the Paper Layout view, remove the surrounding parent frame M_G_CUST_FIRST_NAME_GRPFR, then click the Confine Off button and the Flex Off button in the toolbar.

    • Using the shippingmanifest.rdf example report as a guide, add three rectangles and three text objects for:

      • Shipping Details: Set text properties to Arial, 16, bold. Create a frame to add the following fields: cust_first_name, cust_last_name, street_address, city, state_province, postal, country_name.

      • Tracking Details: Set text properties to Arial, 16, bold. Move the ImageFilename object onto this rectangle.

      • Order Details: Set text properties to Arial, 16, bold. Move the labels and fields for Order ID and Order Date onto this rectangle. Move the field F_Order_Total onto this rectangle and set text properties to Courier New, 24, bold.

    • Set the text properties for all other field values to Courier New, 10. Additionally, set F_Line_Total to bold.

    • Format numeric field values to display currency, decimals, and right align them.

    • Set Fill Color for each rectangle, totals field, and table header as desired.

    Figure 43-4 Paper Design view of the barcode paper report

    Description of Figure 43-4 follows
    Description of "Figure 43-4 Paper Design view of the barcode paper report"

    Note:

    If you are not sure whether you produced the desired results, you can always open the example report called ShippingManifest.pdf in Acrobat Reader. Or, you can run ShippingManifest.rdf to paper and the report will display in the Paper Design view.

  11. Save the report. You have now finished building a barcode report for paper.