SOLUTIONS TO REVIEW QUESTIONS: Chapter 4
I. True-False Questions
1. T
2. T
3. T
4. T
5. T
6. F ARE-THERE-MORE-RECORDS would be defined in the WORKING- STORAGE SECTION.
7. T While this approach is correct, it can lead to confusion. It is better to use
values whose meaning is obvious, such as those used in the chapter.
8. T
9. T
10. T
II. General Questions
1.
|
Entry |
Division |
Purpose |
|
|
a. |
DATE-COMPILED |
IDENTIFICATION |
Indicates the date of the compilation. |
|
b. |
WORKING-STORAGE SECTION |
DATA |
Defines and describes all fields not part of input or output files. |
|
c. |
paragraph-name |
IDENTIFICATION or PROCEDURE or ENVIRONMENT |
Defines a separate group of ENVIRONMENT statements or sentences; same as a module or routine in the PROCEDURE DIVISION. |
|
d. |
CONFIGURATION SECTION |
ENVIRONMENT |
Indicates source and object computer. |
|
e. |
FD |
DATA |
Describes a file. |
|
f. |
level numbers |
DATA |
Used to indicate the hierarchy of data within a record. |
|
g. |
LABEL RECORDS |
DATA |
Indicates whether a file will have header and trailer labels. |
|
h. |
FILE SECTION |
DATA |
Includes a description of all input and output files. |
|
i. |
SELECT |
ENVIRONMENT |
Defines a file and assigns it to a specific device. |
|
j. |
AUTHOR |
IDENTIFICATION |
Indicates the programmer’s name |
|
k. |
STOP RUN |
PROCEDURE |
Terminates the program. |
|
l. |
AT END clause |
PROCEDURE |
Indicates what is to be done when there are no more input records to read. |
|
m. |
VALUE |
DATA |
Initializes a data field in WORKING-STORAGE. |
|
n. |
PICTURE |
DATA |
Indicates the size and type of data in a field. |
|
o. |
FILE-CONTROL |
ENVIRONMENT |
Describes the files and devices to be used. |
|
p. |
OPEN |
PROCEDURE |
Opens input and output files and activates them for processing. |
2. The SELECT statement assigns the device to the file used in the READ statement.
3. To activate and deactivate the device on which the files are located.
4. When we want fields to have initial values.
5. a. Valid
b. Invalid
MOVE is a reserved word.
c. Valid
d. Invalid
Special characters (%) are not permitted in paragraph
names.
6. The AT END clause is required whenever reading a sequential file. The computer must be told what to do when there are no more records to process. The NOT AT END clause allows the programmer to specify what should be done when a record is successfully read.
III. Interpreting Instruction Formats
1. Incorrect. Only one file may be specified in a READ.
2. Incorrect. The OPEN statement must specify if a particular file is to be used for input or output. Also, the word AND is not permitted.
3. Incorrect. The AT END clause is used with the READ statement.
4. Correct.
5. Incorrect. The CLOSE does not specify whether a file was used for input or output.
SOLUTIONS TO DEBUGGING EXERCISES
1. The OPEN statement does not indicate which file is input and which is output. The statement should be:
OPEN INPUT SALES-FILE
OUTPUT PRINT-FILE
2. The MOVE statement can only move fields, not files. The statement should be:
MOVE SALES-RECORD TO PRINT-RECORD
3. The WRITE statement must specify a record rather than a file. The statement should be:
WRITE PRINT-RECORD
4. The logic error is in paragraph 200-PROCESS-RTN. The MOVE and WRITE statements are executed even when the READ statement detects that there are no more input records. In COBOL 85 the routine
could be coded:
200-PROCESS-RTN.
READ SALES-FILE
AT END
MOVE ’NO ’ TO ARE-THERE-MORE-RECORDS
NOT AT END
MOVE SALES-RECORD TO PRINT-RECORD
WRITE PRINT-RECORD
END-READ.
5. No. Commas are optional in a COBOL program.
6. SALES-FILE was assigned to a device using the SELECT statement in the ENVIRONMENT DIVISION.
7. Yes, this would cause an error because the file is being processed sequentially. The computer must be told what to do when the end of file is reached.
8. Paragraph-names must end with a period.