SOLUTIONS TO REVIEW QUESTIONS:  Chapter 3

SOLUTIONS TO DEBUGGING EXERCISES 

1.         *A 1  B              2                  3                  4                  5                  6 
123456789012345678901234567890123456789012345678901234567890123 


              DATA DIVISION. 
              FILE SECTION. 
              FD SALES-FILE. 
              01 INPUT-RECORD. 
                    05 TRANS-NO-IN                           PIC 9(4). 
                    05 TRANSACTION-NAME-IN      PIC X(20). 
                    05 ADDRESS-IN. 
                         10 NUMBER-IN                         PIC X(4). 
                         10 STREET-IN                            PIC X(15). 
                         10 CITY-IN                                 PIC X(3). 
                    05 CREDIT-RATING-IN. 
                         10 CREDIT-CODE-IN                PIC X. 
                         10 LIMIT-OF-PURCHASE-IN   PIC X. 
                    05 UNIT-PRICE-IN                         PIC 99V9. 
                    05 QTY-PURCHASED-IN              PIC 9(5). 
                    05 DISCOUNT-PERCENT-IN        PIC V99. 

2.     a. Incorrect. First, there is a space missing in the picture clause; it should be coded as PIC 9(5). Second, the statement MOVE SPACES TO WS-TOTAL will cause a compiler error; the figurative constant SPACES is alphanumeric, while WS-TOTAL is a numeric field. To initialize WS-TOTAL to zero, code 
                    MOVE ZERO TO WS-TOTAL 
                                        or 
                    MOVE 0 TO WS-TOTAL.

        b. Correct. The figurative constant ZEROS may be used with both numeric and alphanumeric fields. 

        c. Incorrect. As the VALUE clause is presently written, the initial value of TAX-RATE will be 50.00 because the literal 0850 has an implied decimal point after its rightmost position. Assuming that the intention was to initialize the field to 08.50, then the entry should be coded

                     05 TAX-RATE PIC 99V99 VALUE 08.50.