SOLUTIONS TO REVIEW QUESTIONS: Chapter 7
Debugging Exercises
1. 1) Correct.
2) Correct in COBOL 85 only; otherwise TO and GIVING may not be used
in the same ADD statement.
ADD AMT1, AMT2 GIVING AMT3
3) Correct. Although the syntax is correct, however, this is probably not what the programmer had intended. See Debugging Exercise 2 for a corrected statement.
4) ROUNDED must be to the left of the equal sign.
COMPUTE AMT4 ROUNDED = AMT1 + AMT2
5) Correct.
6) The receiving field cannot be a literal.
DIVIDE 2 INTO AMT1
or
DIVIDE AMT1 BY 2 GIVING AMT1
7) The word TIMES is not permitted.
MULTIPLY AMT4 BY AMT3
3. If the result of the MULTIPLY operation is greater than 9,999.99, high-order truncation will occur. To avoid this potential problem:
a. Use the GIVING option and specify a receiving field AMT3 with a PICTURE clause of 9(6)V9(4).
b. Keep the statement as coded and use the ON SIZE ERROR clause to trap the possibility of obtaining a result with more than 4 digits to the left of the decimal place. If truncation of digits to the right of the decimal place is an issue, ROUNDED might be used if appropriate to the application.
4. AMT1 = the original value of AMT1 divided by 2
AMT2 = the original value of AMT2 times the original value of AMT1
AMT3 = the square of the sum (AMT1 + AMT2)
AMT4 = the sum of the original values of AMT1 and AMT2
AVERAGE = the average of the original values of AMT1 and AMT2