Create a query Create a formula column that calculates bonuses

Building a Report that Includes PLSQL 40-7

5. Click Compile.

6. When there are no compilation errors, click Close to display the data model for

your report in the Data Model view. It should look something like this: Figure 40–6 Data Model with BONUS formula column 7. Save your report.

40.3.3 Create a report-level function that calculates total compensation

The steps in this section will show you how to write a function that returns the total compensation for each sales representative the values of columns SALARY plus COMM plus BONUS, as well as other employees SALARY plus BONUS.

1. In the Object Navigator, click the Program Units node, then choose Edit Create.

2. In the New Program Unit dialog box, in the Name field, type FINAL_CALC.

3. Select Function, then click OK.

4. In the PLSQL Editor, use the template to enter the following PLSQL code:

FUNCTION FINAL_CALC RETURN NUMBER IS BEGIN IF :JOB_ID = SA_REP THEN RETURN :BONUS + :SALARY + :COMMISSION_PCT :SALARY; ELSE RETURN :BONUS + :SALARY; END IF; END; Note: You can enter this code by copying and pasting it from the provided text file called plsql_code.txt. This code is for the Bonus Formula Column. Note: If there are compilation errors, compare your code closely against the code we have provided. 40-8 Oracle Reports Users Guide to Building Reports

5. Click Compile.

6. When the code is compiled without errors, click Close.

The new function, FINAL_CALC, now displays in the Object Navigator: Figure 40–7 Object Navigator with FINAL_CALC function 7. Save your report.

40.3.4 Create a second formula column for total compensation

The steps in this section will show you how to create another formula column that will calculate the total compensation. The value calculated by the report-level function FINAL_CALC will be assigned to the column TOTAL_COMP. If you are not sure how to create a formula column, refer to Section 40.3.2, Create a formula column that calculates bonuses . To create the TOTAL_COMP formula column:

1. In the Data Model view, follow the steps above to create a second formula column

below the BONUS formula column. 2. 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 TOTAL_COMP. ■ Under PlaceholderFormula, click the PLSQL Formula property field to display the PLSQL Editor.

3. In the PLSQL Editor, use the template to enter the following PLSQL code:

function TOTAL_COMPFormula return Number is begin return FINAL_CALC; end; Note: You can enter this code by copying and pasting it from the provided text file called plsql_code.txt. This code is for Final Calc. Note: You can enter this code by copying and pasting it from the provided text file called plsql_code.txt. This code is for the Total Comp Formula Column. Building a Report that Includes PLSQL 40-9

4. Click Compile.

5. When the code is compiled without errors, click Close to display the data model

for your report in the Data Model view. It should look something like this: Figure 40–8 Data Model with BONUS and TOTAL_COMP formula columns 6. Save your report.

40.4 Create the Report Layout Using the Report Block Wizard

Now that you have created the necessary formula columns and functions, you can create the layout for your report. To create the report layout: 1. Click the Paper Layout button in the toolbar to display the Paper Layout view.

2. In the Paper Layout view, choose Insert Report Block.

3. In the Report Block Wizard, on the Style page, select Tabular, then click Next.

4. On the Groups page, click G_FIRST_NAME in the Available Groups list and

click Down to specify the Print Direction and move this group to the Displayed Groups list, then click Next. 5. On the Fields page, click the double right arrows to move all of the fields to the Displayed Fields list. The Displayed Fields list should look like this: Figure 40–9 Displays Fields list 40-10 Oracle Reports Users Guide to Building Reports

6. Click Next.

7. On the Labels page, change the labels as follows, then click Next:

8. On the Template page, click Finish to display your report layout in the Paper

Layout view. It should look something like this: Figure 40–10 Paper Layout view of the PLSQL example report

9. Click the Run Paper Layout button in the toolbar to run and display your report in

the Paper Design view. 10. In the Paper Design view, click the Flex Off button in the toolbar.

11. Delete the Last Name label.

12. Change the text for the First Name label to Name.

13. Adjust the width of the new Name label to span over both the first name and last

name columns. 14. Adjust the sizes of the first name and last name columns so that one character displays between the columns.

15. In the Object Navigator, double-click the properties icon next to the F_FIRST_

NAME field to display the Property Inspector, and set the following properties: ■ Under General Layout, set the Vertical Elasticity property to Fixed, and set the Horizontal Elasticity property to Variable.

16. Repeat the above step for the F_LAST_NAME field.

17. Click the Paper Layout button in the toolbar to display the Paper Layout view. 18. In the Paper Layout view, click the Frame tool in the tool palette.

19. Draw a frame around the two fields: F_FIRST_NAME and F_LAST_NAME.

20. With the frame selected, choose Tools Property Inspector to display the

Property Inspector, and set the following properties: ■ Under General Information, set the Name property to M_NAME. 21. In the Paper Layout view, make sure Flex Off is selected in the toolbar.

22. With the frame selected, choose Layout Move Backward until the frame

encloses both the F_FIRST_NAME and F_LAST_NAME fields. Note: If the fields do not display in the correct order, simply click the field name and drag the field to the correct position in the list. Fields Labels COMMISSION_PCT Commission TOTAL_COMP Total Compensation