Modify the Web Source of Your JSP Report Summary

30-8 Oracle Reports Users Guide to Building Reports Building a Check Printing Report with Spelled-Out Cash Amounts 31-1 31 Building a Check Printing Report with Spelled-Out Cash Amounts In this chapter, you will learn about reports that format output as checks with cash amounts spelled out in words. By following the steps in this chapter, you can generate the report output shown in Figure 31–1 . Figure 31–1 Check printing report output Concepts To spell out the value of a check, you use a PLSQL function to split the number into its constituent numerals, then use a formula column to combine the words into the spelled-out cash amount. 31-2 Oracle Reports Users Guide to Building Reports Data Relationships ■ This report uses two linked queries. The first query retrieves the information necessary for the check, and the second query retrieves the order details that will be printed on the check stub. ■ One of the queries you will create assumes that the numbers to be spelled are stored in the TOTAL column of the ORDERS table. The text of the spelled-out number will be fetched from the table called Lookup, and returned in the Thousands_text, Thousands_Symbol, Ones_text, and Decimal_Text columns Layout This report uses a default Form style. Example Scenario In this example, you will use the Report Wizard to create your basic report definition. You will create a PLSQL function that spells out the numerical value of the check amount. You will also create a formula column that formats the dollar amounts on your checks. You will import an image of a blank check image, and use the tools in the Paper Layout and Paper Design views to rearrange the fields in your report according to how you want them to display on the resulting check printing report. You will also use these tools to create a stub for every check. As you build this example report, you will: ■ Create a Report Using the Report Wizard to create a simple form report. ■ Create a Formula Column That returns the Spelled-Out Cash Amounts using the PLSQL Editor and the Data Model view. ■ Create a Query That Returns the Items in the Order using the Data Model view to create a second query and link the two queries together. ■ Import a Check Image and Arrange Fields for Printing using the Paper Layout view to import a blank check image and add fields necessary for printing the check and check stub. Use the Paper Design view to arrange the new fields on the blank check image. ■ Create a Check Stub With Payment Information and Order Details using the Paper Design view to create a check stub and the Report Block Wizard to create a simple tabular report that displays order details. Note: Many of the concepts in this example are used in the following example reports: ■ This example, where you import an image of a check and use it as a guide to position fields in the Paper Layout view. In addition, you learn how to create a PLSQL function that returns spelled-out numerical values. ■ Chapter 32, Building a Report Using a Preprinted Form , where you learn formatting techniques for printing reports on preprinted forms when you do not have access to a computer readable version of the forms. Such reports must be designed so that the data prints in exact positions on the form. ■ Chapter 33, Building an Invoice Report , where you import an image of an invoice and use it as a guide to position fields in the Paper Layout view. Building a Check Printing Report with Spelled-Out Cash Amounts 31-3 To see a sample report where the cash amounts are spelled out, open the examples folder named spellcash, then open the Oracle Reports example named spellcash.rdf. For details on how to open it, see Accessing the Example Reports in the Preface.

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

31.2 Create a Report Using the Report Wizard

The steps in this section will show you how to use the Report Wizard to create a simple report definition. To create a report definition:

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 Style page, type a Title for your report, select Form, 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 ORDERS.ORDER_ID, TO_CHARORDERS.ORDER_DATE, DD-MON-YYYY ORDER_DATE, ORDERS.CUSTOMER_ID, ORDERS.ORDER_TOTAL, CUSTOMERS.CUST_FIRST_NAME || || CUSTOMERS.CUST_LAST_NAME CUSTOMER_NAME, CUSTOMERS.CUST_ADDRESS, ROWNUM + 1000 AS CHECK_NO FROM ORDERS, CUSTOMERS WHERE CUSTOMERS.CUSTOMER_ID = ORDERS.CUSTOMER_ID ORDER BY ORDERS.ORDER_ID ASC

8. Click Next.

Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called spellcash_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. 31-4 Oracle Reports Users Guide to Building Reports

9. On the Fields page, click the double right arrows to move all of the fields to

the Displayed Fields list, then click Next. 10. On the Totals page, click Next. 11. On the Labels page, change the labels and field widths as follows, then click Next:

12. On the Template page, select No Template, then click Finish to preview your

report output in the Paper Design view. Since you have only created the initial report definition, the formatting will not display like a check. It should look something like this: Figure 31–2 Paper Design view of the simple report

13. Save your report as spellcash_your_initials.rdf.

31.3 Create a Formula Column That returns the Spelled-Out Cash Amounts

The steps in this section will show you how to create a formula column that is based on a function. The function you create will return verbal or word value for the numerical value of the check. You will then create a formula column that will spell out 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 31.1, Prerequisites for This Example describes the sample schema requirements for this example. Table 31–1 Field description of Labels page Fields Labels Width ORDER_ID Order No. 5 ORDER_DATE Order Date 12 CUSTOMER_ID Customer No. 3 ORDER_TOTAL Order Total 15 CUSTOMER_NAME Customer 40 C_STREET_ADDRESS [blank] 40 C_POSTAL_CODE [blank] 5 C_CITY [blank] 20 C_STATE_PROVINCE [blank] 3 C_COUNTRY_ID [blank] 3 CHECK_NO Check No. 5 Building a Check Printing Report with Spelled-Out Cash Amounts 31-5 the numerical value in the designated currency. In this case, we will use dollars and cents.

31.3.1 Create a PLSQL function

In this section, you will create a function that simply returns the check amount in word format, such as twenty-four sixty-five. The formula column you create in the next section will use the information retrieved by this function to spell out the cash amounts on your checks. To create a PLSQL function:

1. In the Object Navigator, under your report name, double-click Program Units.

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

3. Select Function, then click OK.

4. In the PLSQL Editor, type the following code: FUNCTION Spell val number RETURN CHAR IS sp varchar2100; BEGIN if val 0 then returninitcapto_charto_dateval, SSSSS, SSSSSSP; else return; end if; END;

5. Click Compile. If you see any errors, compare your code against the code shown

in the image below: Figure 31–3 PLSQL Editor displaying the SPELL function

6. When your code successfully compiles, click Close.

Your new function now displays in the Object Navigator: Note: You can enter this code by copying and pasting it from the provided text file called spellcash_code.txt into the PLSQL Editor.