You are on page 1of 4

SOLUTIONS TO REVIEW QUESTIONS I. 1.

True-False Questions F An indexed file is created with ACCESS IS SEQUENTIAL and read with ACCESS IS RANDOM or ACCESS IS SEQUENTIAL.

2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. II. 1.

T T T T T T F T T F F We would use REWRITE EMPLOYEE-REC. AT END would be used if the file was accessed sequentially. The relative file's key field is defined in WORKING-STORAGE.

General Questions SELECT MASTER-INVENTORY-FILE ASSIGN TO device ORGANIZATION IS INDEXED ACCESS IS SEQUENTIAL RECORD KEY IS key-field. SELECT TRANS-FILE ASSIGN TO device ORGANIZATION IS INDEXED ACCESS IS RANDOM RECORD KEY IS TRANSACTION-NO ALTERNATE RECORD KEY IS INVOICE-NUMBER. The REWRITE statement is used to write updated records back onto disk.

2.

3.

4.

When used with a WRITE statement, the INVALID KEY option will detect different conditions depending on whether the access mode is random or sequential. With random access, the INVALID KEY clause will detect an attempt to store a record with a key field value that already exists in the file. With sequential access, the INVALID KEY will detect both a duplicate key or a record that is is out of sequence. When used with a READ statement the INVALID KEY option will be triggered if the record cannot be found. AT END would be used if the file was accessed sequentially.

5.

A disk file is opened as I-O when records are to be read, changed, and rewritten back onto the file. Validating Data The program should include a routine to verify that: a. b. TRANS-AMT-IN is a valid numeric value. TRANS-CODE-IN contains a valid value.

III. 1.

2.

A control listing of totals should include: a. b. c. the number of transaction records processed from the TRANSACTION-IN file. the number of transaction records containing errors. a detailed explanation of each error found in the transaction file.

3.

A batch total should be included for TRANS-AMT-IN.

SOLUTIONS TO DEBUGGING EXERCISES In order to correct this program, it is necessary to know what the values of TRANS-CODE represent. The following solutions assume that there are two possible actions to be taken: if TRANS-CODE contains an X, then the program is to delete the corresponding record from the indexed file; otherwise the program should add a record to the indexed file. 1. The hyphen is missing in I-O. The OPEN statement should read: OPEN INPUT TRANS-FILE I-0 INDEX-FILE 2. 3. The READ should have an INVALID KEY clause instead of an AT END clause. a. The WRITE statement itself is coded correctly, but is in the wrong location.

First, the WRITE and the preceding MOVE should be executed only if there was no corresponding indexed record found by the READ statement. These statements should be coded within the INVALID KEY segment of the READ statement. Second, the MOVE and WRITE should be executed only if TRANS-CODE contains something other than X, so they must be preceded by an IF statement that tests the value of TRANS-CODE.
b. The syntax error in the DELETE statement is that it must specify the file name rather than the record name. There should be an INVALID KEY clause for the DELETE. There is also a logic error in the location of the DELETE statement. Since the DELETE should be executed only when the corresponding indexed record was found by the READ statement, it (and the corresponding IF) should be located within the NOT INVALID KEY segment of the READ statement There is a syntax error because there is no INVALID KEY clause. The REWRITE statement will also cause a run time error because the record originally read has since been deleted by the previous statement in the code and a logic error since it doesnt make sense to even attempt to REWRITE the record in this situation.

c.

4.

When TRANS-CODE = X, the corresponding master record is deleted. Then after the IF statement, the record is written again. Instead of doing both of these operations for each transaction record, the program should do only one of the them. The deletion should take place if (1) the READ statement located the corresponding record on the indexed file and (2) TRANS-CODE contains an X. A record should be added only when (1) the READ statement did not find a record in the indexed file, and (2) TRANS-CODE does not contain an X. Module 200-CALC-RTN should be rewritten as shown below. MOVE TRANS-NO TO DISK-TRANS-NO READ INDEX-FILE INVALID KEY IF TRANS-CODE = X MOVE RECORD DOES NOT EXIST; CANNOT DELETE TO MSSGE WRITE PRINT-REC FROM ERROR-REC ELSE MOVE TRANS-AMT TO DISK-AMT WRITE DISK-TRANS-REC END-IF NOT INVALID KEY IF TRANS-CODE = X DELETE DISK-TRANS-FILE ELSE MOVE RECORD ALREADY EXISTS; CANNOT ADD TO MSSGE WRITE PRINT-REC FROM ERROR-REC END-IF END-READ.

You might also like