Skip Headers
Oracle® Reports Building Reports
10g Release 2 (10.1.2)
B13895-01
  Go To Documentation Library
Library
Go To Product List
Product
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

14 Building a Group Left Formula Report

In this chapter, you will learn about group left formula reports, containing formula columns. By following the steps in this chapter, you can generate the report output shown in Figure 14-1.

Figure 14-1 Formula report output

Description of Figure 14-1  follows
Description of "Figure 14-1 Formula report output"

Concepts

Data Relationships

Layout

This report uses the default group left format with no modifications.

Example Scenario

As you build this example report, you will:

To see a sample formula report, open the examples folder called formula, then open the Oracle Reports example report named formula.rdf. For details on how to open it, see "Accessing the Example Reports" in the Preface.

14.1 Prerequisites for this example

To build the example in this chapter, you must have access to the Order Entry sample schema provided with the Oracle Database. If you do not know if you have access to this sample schema, contact your database administrator.

14.2 Use the Report Wizard to create a simple 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. Using the wizard enables you to define the layout for the report, as well as set the data definition.

To create a simple report:

  1. Launch Reports Builder (or, if already open, choose File > New > Report).

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

  5. On the Title page, select Group Left, then click Next.

  6. On the Data Source page, click SQL Query, then click Next.

  7. On the Data page, enter the following SELECT statement in the Data Source definition field:

    SELECT ALL CUSTOMERS_A1.CUSTOMER_ID, ORDERS.ORDER_ID, ORDERS.ORDER_TOTAL
    FROM CUSTOMERS CUSTOMERS_A1, ORDERS
    WHERE (ORDERS.CUSTOMER_ID = CUSTOMERS_A1.CUSTOMER_ID)
    ORDER BY CUSTOMERS_A1.CUSTOMER_ID
    

    Note:

    You can enter this query in any of the following ways:
    • Copy and paste the code from the provided text file called formula_code.txt into the Data Source definition field.

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

    • Type the code in the Data Source definition field.


  8. Click Next.


    Note:

    If you are not already connected to a database, you will be prompted to connect to the database when you click Query Builder or Next. Ensure that you connect to a database that has the appropriate schema for this example. Section 14.1, "Prerequisites for this example" describes the sample schema requirements for this example.

  9. On the Groups page, select CUSTOMER_ID and click the right arrow (>) to move this field to the Groups Fields list, then click Next.

  10. On the Fields page, click the double right arrow button (>>) to move all of the fields to the Displayed Fields list, then click Next.

  11. On the Totals page, click ORDER_TOTAL and click Sum, then click Next.

  12. 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 14-2 Paper Design view for the formula report

    Description of Figure 14-2  follows
    Description of "Figure 14-2 Paper Design view for the formula report"

  13. Save the report as formulareport_your_initials.rdf.

14.3 Create two formula columns

Frequently, you want to base calculations on values in your data source. One way you can do this is by using formula columns. The steps in this section will show you how to create two formula columns that calculate the following values:

14.3.1 Create a formula column to calculate the tax

To create a formula column that calculates the tax:

  1. In Reports Builder, click the Data Model button in the toolbar to display the Data Model view of your report.

    The data model should look something like this:

    Figure 14-3 Data Model of the Formula Report

    Description of Figure 14-3  follows
    Description of "Figure 14-3 Data Model of the Formula Report"

  2. Click the Formula Column tool in the tool palette, then click in the G_ORDER_ID group under ORDER_TOTAL to create a formula column.


    Tip:

    To view the names of the tools in the tool palette and the toolbar, drag and hold your mouse over each icon and hint text will display describing the icon.

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

    • 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 TAXFormula return Number is
    	tax number;
    begin
      tax := :ORDER_TOTAL * .07;
      return (tax);
    end;
    
  5. Click Compile.

  6. If no errors display, click Close. If errors display, verify that your code looks exactly like the above code, paying close attention to the column names.

  7. Close the Property Inspector.

You have created a formula column that calculates the tax (7%) of each order.

14.3.2 Create a formula column that calculates customer order totals

To create a formula column that calculates customer order totals:

  1. Repeat Steps 2 and 3 from Section 14.3.1, "Create a formula column to calculate the tax": click the Formula Column tool in the tool palette, then click in the G_ORDER_ID group under TAX. Then, double-click CF_1 to display the Property Inspector.

  2. Change the name of the column to SALES_TOTAL.

  3. Open the PL/SQL Editor and modify your formula so that it looks like this:

    function SALES_TOTALFormula return Number is
    	sales_total number;
    begin
      sales_total := :ORDER_TOTAL + :TAX;
      return (sales_total);
    end;
    
  4. Click Compile.

  5. If no errors display, click Close. If errors display, verify that your code looks exactly like the above code, paying close attention to the column names.

  6. Close the Property Inspector.

You have created a formula column that calculates the total orders of each customer. Your data model should now look something like this:

Figure 14-4 Data Model with Formula Columns

Description of Figure 14-4  follows
Description of "Figure 14-4 Data Model with Formula Columns"

14.3.3 Add the formula columns to the report layout

Now that you have created your formula columns, you must add them to your report layout. The easiest way to do this is to return to the Report Wizard.

To add formula columns to your report layout:

  1. In the Data Model view, right-click on the canvas, then choose Report Wizard.

  2. In the Report Wizard, click the Fields tab. In the Available Fields list, you should now see your two new formula columns. Click each one, then click the right arrow (>) to move them to the Displayed Fields list.

  3. Click Finish to display your report output in the Paper Design view. It should look something like this:

Figure 14-5 Final formula report output

Description of Figure 14-5  follows
Description of "Figure 14-5 Final formula report output"

14.4 Summary

Congratulations! You have successfully created a formula paper report. You now know how to:

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 Reports Builder or hosted on the Oracle Technology Network (OTN), as described in Section 3.1.1, "Using the Oracle Reports online Help".