Create Ranking Logic for Top number of Customers

Building a Ranking Report 34-5 9. Click the Run Paper Layout button in the toolbar to display the Runtime Parameter Form, which enables you to change the default values for CUTOFF_ CNT and INCR_CNT. 10. Click the Run Report button to display the report output in the Paper Design view. 11. Save your report as rank_your_initials.rdf. Figure 34–3 Tabular report output restricted to top three customers

34.4 Add a Layout Object for a Parameter

As a way for users to quickly tell the number of customers displayed in the list, you need to display the value of CUTOFF_CNT in the report. To perform this task, you will create a boilerplate text object that references the parameter.

1. In the Object Navigator, double-click the view icon next to the Paper Layout node

to display the Paper Layout view. 2. Position the Paper Layout view and Object Navigator side-by-side so that they are visible simultaneously.

3. In the Object Navigator, in the Find field, type M_G_CNAME_GRPFR.

4. Click M_G_CNAME_GRPFR in the Object Navigator to select it in the Paper

Layout view. 5. Click the title bar of the Paper Layout view to make it the active window.

6. Select M_G_CNAME_GRPFR and all of its contents by press CTRL-A on your

keyboard.

7. Use the down arrow key to move the items down about 1 inch 2.5 centimeters.

8. From the font lists in the toolbar, choose Arial Western, point size 10.

9. Click the Text tool in the tool palette.

Tip: Notice that, if the Paper Design view is still open while you add this logic, the report now returns no records in the Paper Design view. To fix this issue, you should display one of the other views for example, the Data Model view and then come back to the Paper Design view. You will be prompted by the Runtime Parameter Form to enter values for the two parameters, INCR_CNT and CUTOFF_CNT. Note: You can also use the Find field in the Object Navigator to locate specific objects. When you select an item in the Object Navigator while the Paper Layout view is displayed, the corresponding object is selected in the Paper Layout view. 34-6 Oracle Reports Users Guide to Building Reports

10. Click directly above the label Customer Name to create a new boilerplate text

object and type the following text: Top CUTOFF_CNT Customers: 11. Move to an open area of the Paper Layout view and click the mouse button to exit text mode. Notice that the text object you just created is still selected, you can now adjust its positioning with the arrow keys. 12. Click the Bold button in the toolbar to make the new text bold.

13. Shift-click the labels Customer Name and Total Purchase so that they are selected

simultaneously with the object you just created. 14. Click the Underline button in the toolbar. 15. Click in an open area of the Paper Layout view to deselect everything.

16. Click F_SUM_AMT, then choose Tools Property Inspector to display the

Property Inspector, and set the following properties: ■ Under Field, set the Format Mask property by typing the following: -NNN,NN0.00 17. Click the Paper Design button in the toolbar to display the Paper Design view. If the Runtime Parameter Form displays, click the Run Report button in the toolbar. Figure 34–4 Tabular report output with parameter value displayed

18. Save your report.

34.5 Create a Parameter Form

By default, both of your user parameters appear in the Runtime Parameter Form. In reality, you only want users to set CUTOFF_CNT. You do not want them to be able to set INCR_CNT the amount by which your counter is increased for each record. To prevent users from seeing INCR_CNT on the Runtime Parameter Form, you will build your own Parameter Form. To create a Parameter Form:

1. Choose Tools Parameter Form Builder.

2. In the Parameter Form Builder dialog box, scroll down the list of parameters until

you find INCR_CNT. 3. Click INCR_CNT to deselect it. 4. Change the label for CUTOFF_CNT to: of Top Customers:

5. Click OK.

6. Click the Run Paper Layout button in the toolbar.

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.