Add a Layout Object for a Parameter

Building a Ranking Report 34-7

7. In the Runtime Parameter Form, type a value for of Top Customers, then click

the Run Report button in the toolbar. You should now see as many records as you asked for in the Runtime Parameter Form and they should be in order from largest total purchases to smallest total purchases. 8. Save your report.

34.6 Add a Percentage Ranking

Another way to rank customers is by percentage of total sales. The idea is the same as ranking by count, but with an important difference. Since you need to fetch all of the data in order to compute a running percent of total summary, you dont want to use a group filter to weed out data. You need to use a format trigger on the repeating frame to compare the running total to your cutoff parameter. To fetch the data for the percentage calculation:

1. In the Object Navigator, double-click the view icon next to the Data Model node.

2. In the Data Model view that displays, click the SQL Query tool in the tool palette then click in an open area of the Data Model view, somewhere to the right of query Q_1, to display the SQL Query Statement dialog box.

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

SELECT CUSTNAME CNAME2, SUMAMOUNT SUM_AMT2 FROM SALES GROUP BY CUSTNAME ORDER BY SUMAMOUNT DESC

4. Click OK. Your data model should now look like the following image.

Tip: As an additional exercise, you could now change the Initial Value property of CUTOFF_CNT to see its effect on the Runtime Parameter Form. Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called rank_code.txt SELECT statement for Percentage Calculation 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. 34-8 Oracle Reports Users Guide to Building Reports Figure 34–5 Data Model view of the Ranking Report 5. Save your report. To create a parameter for the percentage cutoff:

1. In the Object Navigator, under the Data Model node, click the User Parameters

node.

2. Choose Edit Create to create a new user parameter under the User Parameters

node. 3. If the Property Inspector is not already displayed, right-click the new user parameter P_1, then choose Property Inspector to display the Property Inspector, and set the following properties: ■ Under General Information, set the Name property to CUTOFF_PCT. ■ Under Parameter, set the Datatype property to Number, set the Width property to 2, and set the Initial Value property to 75.

4. In the Data Model view, click the group object G_CNAME2, then click and drag

the bottom handle down about 0.25 inches 0.5 centimeters to make the group bigger. 5. Click the Summary Column tool in the tool palette.

6. Click in the empty space beneath SUM_AMT2 to create a summary column.

7. Double-click the new summary column object CS_1 to display the Property

Inspector, and set the following properties: ■ Under General Information, set the Name property to R_PCT. ■ Under Column, set the Datatype property to Number, and set the Width property to 10. ■ Under Summary, set the Function property to of Total, set the Source property to SUM_AMT2, set the Reset At property to Report, and set the Compute At property to Report. To create a second layout for the list of customers by percentage: 1. Click the Paper Layout button in the toolbar to display the Paper Layout view. 2. In the Paper Layout view, click the Report Block tool in the tool palette. 3. Starting about 1 inch 2.5 centimeters below the existing layout, click and drag a box about the same size as the existing layout to define the size of the second layout and display the Report Block Wizard.

4. On the Style page of the Report Block Wizard, select Tabular, then click Next.