Quiz — Chapter 38: Batch Processing Patterns
Multiple Choice
1. What is the primary purpose of a checkpoint in batch processing?
a) To improve program performance by caching data b) To record the program's state so processing can resume after a failure c) To verify that the program is running correctly d) To communicate between JCL steps
2. In a checkpoint record, which of the following is NOT typically stored?
a) The number of records processed so far b) The key of the last record successfully processed c) The source code of the program d) Current control total values
3. What is a hash total?
a) A cryptographic signature of a file b) A sum of a non-financial field (like account numbers) used to verify completeness c) A count of records containing hash marks d) A total computed using a hashing algorithm
4. In the balanced update pattern, what happens when the master key is less than the transaction key?
a) An error is reported b) The transaction is applied to the master record c) The master record is written unchanged to the new master file d) The transaction is rejected
5. Why is HIGH-VALUES used in the balanced update pattern when a file reaches EOF?
a) To signal an error condition b) To ensure the remaining records from the other file are processed c) To pad the record to its full length d) To indicate the record is invalid
6. What is a Generation Data Group (GDG)?
a) A group of programs that are compiled together b) A collection of chronologically related datasets sharing a common base name c) A set of COBOL copybooks for different data generations d) A method of organizing COBOL source code by version
7. In GDG relative referencing, what does DATASET.NAME(-1) refer to?
a) The first generation ever created b) The generation before the current one c) A deleted generation d) A future generation
8. Which return code conventionally signals a catastrophic failure in a batch program?
a) 0 b) 4 c) 8 d) 16
9. What is the fundamental control total equation for record counts?
a) Records Read = Records Written b) Records Read = Records Written + Records Rejected + Records Skipped c) Records Written = Records Read - Records Rejected d) Records Read + Records Written = Total Records
10. In JCL, what does COND=(8,LT) mean?
a) Execute this step only if a prior step returned less than 8 b) Skip this step if any prior step's return code is less than 8 c) Execute this step if the condition code is 8 d) Skip this step if 8 is less than the condition code
True or False
11. A batch program should continue processing indefinitely regardless of how many errors it encounters. ____
12. Financial control totals should use COMP-3 (packed decimal) rather than COMP-1 (floating point) to avoid rounding errors. ____
13. In the balanced update pattern, if a transaction has action code 'ADD' but a matching master record already exists, the transaction should be applied as an update. ____
14. Writing checkpoints more frequently improves restart performance but increases I/O overhead during normal processing. ____
15. A GDG with a limit of 30 will automatically delete (roll off) the oldest generation when the 31st generation is created. ____
Short Answer
16. Explain why control totals are necessary even when the SORT utility reports a successful completion (return code 0).
17. Describe the difference between a "before image" and an "after image" in an audit trail, and explain why both are needed.
18. In the GlobalBank case study, the SORT step lost 6,891 records despite returning a zero return code. How did the validation step detect this error?
19. Why should each step in a multi-step job stream verify its input control totals against the prior step's output control totals?
20. Explain the trade-off involved in choosing a checkpoint interval. What factors would lead you to checkpoint more frequently? Less frequently?
Code Analysis
21. Examine the following checkpoint write code and identify two potential problems:
2500-WRITE-CHECKPOINT.
MOVE WS-RECORDS-READ TO CHKPT-RECORDS-READ
MOVE WS-FINANCIAL-TOTAL TO CHKPT-FINANCIAL-TOTAL
WRITE CHECKPOINT-RECORD FROM WS-CHECKPOINT-RECORD.
22. The following balanced update code has a bug that causes incorrect results when multiple transactions exist for the same master key. Identify and explain the bug:
2000-PROCESS.
EVALUATE TRUE
WHEN MSTR-KEY < TXN-KEY
WRITE NEW-MASTER FROM WS-MASTER-RECORD
READ MASTER-FILE INTO WS-MASTER-RECORD
WHEN MSTR-KEY = TXN-KEY
PERFORM 2100-APPLY-TRANSACTION
WRITE NEW-MASTER FROM WS-MASTER-RECORD
READ MASTER-FILE INTO WS-MASTER-RECORD
READ TXN-FILE INTO WS-TXN-RECORD
WHEN MSTR-KEY > TXN-KEY
PERFORM 2200-PROCESS-ADD
READ TXN-FILE INTO WS-TXN-RECORD
END-EVALUATE.
Answer Key
1. b) To record the program's state so processing can resume after a failure
2. c) The source code of the program
3. b) A sum of a non-financial field (like account numbers) used to verify completeness
4. c) The master record is written unchanged to the new master file
5. b) To ensure the remaining records from the other file are processed
6. b) A collection of chronologically related datasets sharing a common base name
7. b) The generation before the current one
8. d) 16
9. b) Records Read = Records Written + Records Rejected + Records Skipped
10. b) Skip this step if any prior step's return code is less than 8
11. False — Programs should implement error thresholds to abort when error rates become unacceptable.
12. True
13. False — This should be treated as an error. The transaction specified ADD, but the record already exists. Processing it as an update could mask data entry errors.
14. True
15. True
16. SORT may complete successfully (RC=0) but produce incorrect output. For example, a SUM FIELDS parameter could accidentally consolidate records with duplicate keys, reducing the record count without triggering an error. Control totals (especially hash totals and record counts) catch discrepancies that the SORT utility itself does not detect.
17. A before image records the state of a record before a change; an after image records the state after the change. Both are needed because: (1) auditors need to see what changed, (2) if a rollback is necessary, the before image provides the restoration data, and (3) comparing before and after images allows precise identification of which fields were modified.
18. The validation step compared the hash total of the records it received against the hash total reported by the extract step's control total output. The hash totals did not match because the missing 6,891 records had different account numbers that were no longer included in the sum.
19. To catch data loss, corruption, or processing errors between steps. A file could be truncated during dataset allocation, records could be lost in transit, or a prior step could have produced incorrect output despite a zero return code. Without inter-step verification, errors accumulate silently.
20. Trade-off: More frequent checkpoints mean less reprocessing after a failure (recovery is faster) but add I/O overhead that slows normal processing. Factors favoring more frequent checkpoints: processing is expensive (DB2 updates, complex calculations), data volumes are large, the batch window is tight, master file updates are involved. Factors favoring less frequent checkpoints: processing is simple, data volumes are small, restart cost is low.
21. Problems: (1) The code uses WRITE instead of REWRITE — after the first checkpoint, subsequent checkpoints should REWRITE the existing record. Using WRITE will attempt to add a new record and may fail. (2) The code does not check the file status after the WRITE — if the checkpoint write fails, processing continues without restart capability, which could lead to data corruption on failure.
22. The bug is in the MSTR-KEY = TXN-KEY branch. After applying the transaction, the code immediately writes the updated master and reads the next master. If there are additional transactions for the same master key (e.g., two debits to the same account), the second transaction finds a new master key that does not match, and the second transaction is either lost or treated as an unmatched add. The fix: after applying the transaction, read the next transaction first and check if it also matches the current master key before writing the master.