Chapter 16 Exercises: Declaratives and Exception Handling

Tier 1: Recall and Recognition (Exercises 1-7)

Exercise 1: DECLARATIVES Syntax

Fill in the blanks to create a valid DECLARATIVES section that handles I/O errors on an input file called CUSTOMER-FILE:

       PROCEDURE DIVISION.
       ____________.

       CUST-ERROR _________.
           USE AFTER __________ ERROR PROCEDURE
               ON ____________.
       CUST-ERROR-HANDLER.
           DISPLAY 'ERROR ON CUSTOMER FILE'
           DISPLAY 'FILE STATUS: ' WS-CUST-STATUS
           .

       _____ DECLARATIVES.

Solution:

       PROCEDURE DIVISION.
       DECLARATIVES.

       CUST-ERROR SECTION.
           USE AFTER STANDARD ERROR PROCEDURE
               ON CUSTOMER-FILE.
       CUST-ERROR-HANDLER.
           DISPLAY 'ERROR ON CUSTOMER FILE'
           DISPLAY 'FILE STATUS: ' WS-CUST-STATUS
           .

       END DECLARATIVES.

Exercise 2: File Status Code Classification

Classify each of the following file status codes by category (successful, end-of-file, invalid key, permanent error, logic error) and describe what each means:

Status Code Category Meaning
00
10
22
23
30
35
39
41
46
93

Solution:

Status Code Category Meaning
00 Successful Operation completed successfully
10 End-of-file AT END condition; no more records to read
22 Invalid key Duplicate key on WRITE to indexed file
23 Invalid key Record not found on READ or START
30 Permanent error Non-recoverable I/O error
35 Permanent error OPEN failed; file not found (non-optional file)
39 Permanent error OPEN failed; file attributes conflict
41 Logic error OPEN attempted on already-open file
46 Logic error Sequential READ without positioning
93 IBM-specific VSAM resource not available

Exercise 3: Inline Exception Phrases

Match each inline exception phrase with the statement(s) it applies to:

Exception Phrase Applicable Statements
a) AT END 1) COMPUTE, ADD, SUBTRACT, MULTIPLY, DIVIDE
b) INVALID KEY 2) READ (sequential)
c) ON SIZE ERROR 3) READ, WRITE, REWRITE, DELETE, START (indexed/relative)
d) ON OVERFLOW 4) STRING, UNSTRING
e) NOT AT END 5) CALL
f) ON EXCEPTION 6) READ (sequential) -- success path

Solution: - a) AT END -- 2) READ (sequential) - b) INVALID KEY -- 3) READ, WRITE, REWRITE, DELETE, START (indexed/relative) - c) ON SIZE ERROR -- 1) COMPUTE, ADD, SUBTRACT, MULTIPLY, DIVIDE - d) ON OVERFLOW -- 4) STRING, UNSTRING - e) NOT AT END -- 6) READ (sequential) -- success path - f) ON EXCEPTION -- 5) CALL

Exercise 4: USE Statement Scope

Indicate whether each of the following USE statements is valid or invalid. For invalid ones, explain why:

a) USE AFTER STANDARD ERROR PROCEDURE ON INPUT b) USE AFTER STANDARD ERROR PROCEDURE ON CUSTOMER-FILE c) USE AFTER ERROR PROCEDURE ON OUTPUT d) USE AFTER STANDARD ERROR PROCEDURE ON I-O e) USE AFTER STANDARD ERROR PROCEDURE ON ALL FILES

Exercise 5: ON SIZE ERROR Behavior

What is the value of WS-RESULT after each of the following code segments executes? Assume WS-RESULT is defined as PIC 9(3) with an initial value of 500.

a)

           COMPUTE WS-RESULT = 999 + 1
               ON SIZE ERROR
                   MOVE 0 TO WS-RESULT
           END-COMPUTE

b)

           COMPUTE WS-RESULT = 999 + 1
           END-COMPUTE

c)

           ADD 600 TO WS-RESULT
               ON SIZE ERROR
                   DISPLAY 'OVERFLOW DETECTED'
               NOT ON SIZE ERROR
                   DISPLAY 'ADDITION SUCCESSFUL'
           END-ADD

Exercise 6: DECLARATIVES vs Inline Handling

For each scenario below, state whether you would use a DECLARATIVES section, inline exception handling (AT END, INVALID KEY, etc.), file status checking, or a combination. Justify your answer.

a) Reading a sequential transaction file until end-of-file. b) A batch program that processes five different files and needs centralized error logging for any I/O failure. c) Writing to an indexed file where duplicate keys are a normal business condition (e.g., duplicate transaction IDs that should be logged but not treated as fatal). d) Opening a file that might not exist on certain days of the month.

Exercise 7: Scope Terminator Identification

The following code is missing its scope terminators. Add the correct END-verb for each statement:

           READ TRANS-FILE INTO WS-TRANS-REC
               AT END
                   SET WS-EOF-TRANS TO TRUE
               NOT AT END
                   ADD 1 TO CT-TRANS-READ
           ____________

           WRITE MASTER-RECORD FROM WS-MASTER-REC
               INVALID KEY
                   PERFORM 9100-HANDLE-DUP-KEY
               NOT INVALID KEY
                   ADD 1 TO CT-RECORDS-WRITTEN
           ____________

           DIVIDE WS-TOTAL-AMOUNT BY WS-RECORD-COUNT
               GIVING WS-AVERAGE-AMOUNT ROUNDED
               ON SIZE ERROR
                   MOVE 0 TO WS-AVERAGE-AMOUNT
           ____________

Tier 2: Comprehension and Application (Exercises 8-15)

Exercise 8: Complete File Status Checking

Write a paragraph called 1000-OPEN-FILES that opens three files (INPUT-TRANS, MASTER-FILE, and ERROR-LOG) and checks the file status after each OPEN. If any file fails to open, display an appropriate error message including the file name and status code, set an error flag, and skip opening subsequent files. The program should not STOP RUN inside this paragraph.

Solution:

       1000-OPEN-FILES.
           OPEN INPUT INPUT-TRANS
           IF WS-TRANS-STATUS NOT = '00'
               DISPLAY 'OPEN FAILED FOR INPUT-TRANS'
               DISPLAY 'FILE STATUS: ' WS-TRANS-STATUS
               SET FL-OPEN-ERROR TO TRUE
           ELSE
               OPEN I-O MASTER-FILE
               IF WS-MASTER-STATUS NOT = '00'
                   DISPLAY 'OPEN FAILED FOR MASTER-FILE'
                   DISPLAY 'FILE STATUS: ' WS-MASTER-STATUS
                   SET FL-OPEN-ERROR TO TRUE
               ELSE
                   OPEN OUTPUT ERROR-LOG
                   IF WS-ERROR-STATUS NOT = '00'
                       DISPLAY 'OPEN FAILED FOR ERROR-LOG'
                       DISPLAY 'FILE STATUS: '
                           WS-ERROR-STATUS
                       SET FL-OPEN-ERROR TO TRUE
                   END-IF
               END-IF
           END-IF
           .

Exercise 9: Error Recovery with INVALID KEY

Write a COBOL paragraph that reads a customer record from an indexed file using a customer ID. If the record is not found (status 23), attempt to read from a backup file. If the backup also fails, write the customer ID to an exception log. Include all file status checking.

Exercise 10: Arithmetic Error Protection

A bank calculates daily interest on savings accounts using the formula:

daily-interest = balance * (annual-rate / 365)

Write a paragraph called 3000-CALCULATE-INTEREST that: - Protects against division by zero if the rate is zero - Uses ON SIZE ERROR to catch overflow conditions - Rounds to the nearest cent - Logs any calculation errors to an error counter and an error detail table

Data definitions:

       01  WS-ACCOUNT-BALANCE    PIC S9(11)V99.
       01  WS-ANNUAL-RATE        PIC 9V9(6).
       01  WS-DAILY-INTEREST     PIC S9(9)V99.
       01  WS-DAYS-IN-YEAR       PIC 9(3)  VALUE 365.
       01  WS-WORK-RATE          PIC 9V9(12).

Exercise 11: Complete DECLARATIVES Section

Write a complete DECLARATIVES section for a program that processes the following files: - DAILY-TRANS (INPUT) -- transaction file - MASTER-ACCT (I-O) -- account master file - REJECT-FILE (OUTPUT) -- rejected transactions - AUDIT-LOG (OUTPUT) -- audit trail

Each declarative handler should: 1. Capture the file status code 2. Increment a file-specific error counter 3. Set a file-specific error flag 4. Write an error detail record to a WORKING-STORAGE error table (up to 100 entries)

Exercise 12: Defensive READ Loop

Write a complete read-process loop for a sequential file that handles: - Normal end-of-file (status 10) - Physical I/O errors (status 30) - File not found on open (status 35) - Record length conflict (status 04 -- record read successfully but shorter/longer than expected)

The loop should continue processing even if individual records cause errors, keeping a count of good records, short records, and error records.

Solution:

       2000-PROCESS-LOOP.
           PERFORM 2100-READ-TRANSACTION
           PERFORM UNTIL FL-EOF-TRANS
               EVALUATE TRUE
                   WHEN WS-TRANS-STATUS = '00'
                       ADD 1 TO CT-GOOD-RECORDS
                       PERFORM 2200-PROCESS-TRANSACTION
                   WHEN WS-TRANS-STATUS = '04'
                       ADD 1 TO CT-SHORT-RECORDS
                       DISPLAY 'SHORT RECORD AT ' CT-RECORDS-READ
                       PERFORM 2200-PROCESS-TRANSACTION
                   WHEN WS-TRANS-STATUS = '30'
                       ADD 1 TO CT-ERROR-RECORDS
                       DISPLAY 'I/O ERROR AT RECORD '
                           CT-RECORDS-READ
                       DISPLAY 'FILE STATUS: '
                           WS-TRANS-STATUS
                   WHEN OTHER
                       ADD 1 TO CT-ERROR-RECORDS
                       DISPLAY 'UNEXPECTED STATUS: '
                           WS-TRANS-STATUS
                       DISPLAY 'AT RECORD: ' CT-RECORDS-READ
               END-EVALUATE
               PERFORM 2100-READ-TRANSACTION
           END-PERFORM
           .

       2100-READ-TRANSACTION.
           READ TRANS-FILE INTO WS-TRANS-RECORD
           ADD 1 TO CT-RECORDS-READ
           EVALUATE WS-TRANS-STATUS
               WHEN '00'
                   CONTINUE
               WHEN '04'
                   CONTINUE
               WHEN '10'
                   SET FL-EOF-TRANS TO TRUE
               WHEN OTHER
                   CONTINUE
           END-EVALUATE
           .

Exercise 13: Error Logging Subroutine

Write a reusable paragraph called 9000-LOG-ERROR that accepts error information through WORKING-STORAGE fields and writes a formatted error record to an error log file. The error record should include: - Error timestamp (current date and time) - Error source (paragraph name) - Error type (FILE-IO, ARITHMETIC, DATA-VALID, LOGIC) - Error severity (INFO, WARNING, ERROR, CRITICAL) - File status code (if applicable) - Error description (up to 50 characters)

Include the WORKING-STORAGE definitions and the error log FD.

Exercise 14: Conditional File Processing

Write a program segment that attempts to open an optional input file. If the file is not present (status 05 on OPEN or 35), the program should log a message and continue processing without that file. If the file IS present, process it normally. This pattern is common in banks where certain feed files only arrive on business days.

Exercise 15: Multiple Error Condition Handling

Write a paragraph that performs a REWRITE on an indexed master file record and handles all possible outcomes: - Success (00) - Record not found (23) -- the record was deleted between READ and REWRITE - File is full (24) - Permanent I/O error (30) - File not open (41) - Any other unexpected status

For each condition, take appropriate action (retry, log, set flag, etc.).


Tier 3: Analysis and Problem Solving (Exercises 16-22)

Exercise 16: Debugging a Broken Error Handler

The following program compiles but crashes with an abend when processing bad records instead of handling them gracefully. Identify all bugs and explain the fix for each.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. ERRTEST.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT TRANS-FILE ASSIGN TO TRANSIN
               FILE STATUS IS WS-TRANS-STATUS.
           SELECT MASTER-FILE ASSIGN TO MASTER
               ORGANIZATION IS INDEXED
               ACCESS MODE IS RANDOM
               RECORD KEY IS MR-ACCT-NUM.
       DATA DIVISION.
       FILE SECTION.
       FD  TRANS-FILE.
       01  TRANS-RECORD.
           05  TR-ACCT-NUM    PIC X(10).
           05  TR-AMOUNT      PIC 9(7)V99.
           05  FILLER         PIC X(61).
       FD  MASTER-FILE.
       01  MASTER-RECORD.
           05  MR-ACCT-NUM    PIC X(10).
           05  MR-BALANCE     PIC 9(7)V99.
           05  FILLER         PIC X(61).
       WORKING-STORAGE SECTION.
       01  WS-TRANS-STATUS    PIC XX.
       01  WS-EOF             PIC X VALUE 'N'.
       PROCEDURE DIVISION.
       DECLARATIVES.
       MASTER-ERR SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON MASTER-FILE.
       MASTER-ERR-PARA.
           DISPLAY 'MASTER FILE ERROR'
           STOP RUN.
       END DECLARATIVES.
       MAIN-SECTION SECTION.
       0000-MAIN.
           OPEN INPUT TRANS-FILE
           OPEN I-O MASTER-FILE
           READ TRANS-FILE
               AT END MOVE 'Y' TO WS-EOF
           END-READ
           PERFORM UNTIL WS-EOF = 'Y'
               MOVE TR-ACCT-NUM TO MR-ACCT-NUM
               READ MASTER-FILE
               ADD TR-AMOUNT TO MR-BALANCE
               REWRITE MASTER-RECORD
               READ TRANS-FILE
                   AT END MOVE 'Y' TO WS-EOF
               END-READ
           END-PERFORM
           CLOSE TRANS-FILE MASTER-FILE
           STOP RUN.

Exercise 17: Error Recovery Strategy Design

A batch program processes daily ATM transactions against a checking account master file. The input file typically contains 500,000 records. Design a comprehensive error-handling strategy that addresses:

a) File-level errors: input file missing, master file locked by another job, output disk full. b) Record-level errors: account not found, non-numeric amount field, negative withdrawal exceeding balance. c) Batch-level controls: transaction count must match header record, total debits and credits must balance. d) Recovery requirements: if the program fails mid-run, it should be restartable from a checkpoint.

Provide pseudocode and key COBOL code fragments for each component of the strategy.

Exercise 18: File Status 39 Investigation

A programmer reports that their program gets file status 39 when opening an indexed file. The SELECT statement says:

           SELECT ACCOUNT-FILE ASSIGN TO ACCTMAST
               ORGANIZATION IS INDEXED
               ACCESS MODE IS DYNAMIC
               RECORD KEY IS AR-ACCT-NUM
               FILE STATUS IS WS-ACCT-STATUS.

And the FD says:

       FD  ACCOUNT-FILE
           RECORD CONTAINS 200 CHARACTERS.
       01  ACCOUNT-RECORD.
           05  AR-ACCT-NUM    PIC X(10).
           05  AR-ACCT-NAME   PIC X(30).
           05  AR-BALANCE     PIC S9(11)V99.
           05  FILLER         PIC X(147).

The file was created by another program with RECORD CONTAINS 250 CHARACTERS. Explain: - Why status 39 occurs - What the programmer needs to change - How to prevent this in the future using COPY members

Exercise 19: Cascading Error Handling

Write a complete COBOL program that demonstrates cascading error handling. The program should: 1. Attempt to open a primary data source (indexed file) 2. If that fails, attempt a secondary data source (sequential backup) 3. If that also fails, attempt to read from an emergency flat file 4. If all three fail, write a critical alert record and terminate gracefully

Each fallback should log which data source is being used and why the previous one failed.

Exercise 20: ON SIZE ERROR vs ROUNDED Interaction

Explain the interaction between ROUNDED and ON SIZE ERROR in the following scenarios and state the final value of WS-RESULT (PIC 9(3)V99) and whether ON SIZE ERROR is triggered:

a) COMPUTE WS-RESULT ROUNDED = 999.999 b) COMPUTE WS-RESULT ROUNDED = 999.994 c) COMPUTE WS-RESULT ROUNDED = 999.996 d) DIVIDE 1 BY 3 GIVING WS-RESULT ROUNDED ON SIZE ERROR DISPLAY 'ERR' e) COMPUTE WS-RESULT ROUNDED = -1.00 (note: WS-RESULT is unsigned)

Exercise 21: Error Table Design

Design a WORKING-STORAGE error tracking system that can hold up to 500 errors during a batch run. The table should support: - Adding new errors with automatic overflow protection - Retrieving errors by error type - Generating a summary count by error type at the end of the run - Writing all accumulated errors to an error report

Provide the complete WORKING-STORAGE definitions and the ADD-ERROR, GET-ERRORS-BY-TYPE, and WRITE-ERROR-SUMMARY paragraphs.

Exercise 22: VSAM Status Code Analysis

A production program logs the following file status values during a single run against a VSAM KSDS file. Reconstruct the sequence of events and identify what likely happened:

14:01:00  OPEN I-O    STATUS=00
14:01:01  READ        STATUS=00  KEY=1000001
14:01:01  REWRITE     STATUS=00
14:01:01  READ        STATUS=00  KEY=1000002
14:01:01  REWRITE     STATUS=00
14:01:02  READ        STATUS=00  KEY=1000003
14:01:02  REWRITE     STATUS=02
14:01:02  READ        STATUS=23  KEY=1000004
14:01:02  WRITE       STATUS=00  KEY=1000004
14:01:03  READ        STATUS=23  KEY=1000005
14:01:03  WRITE       STATUS=22  KEY=1000005
14:01:03  READ        STATUS=93  KEY=1000006
14:01:05  READ        STATUS=00  KEY=1000006
14:01:05  REWRITE     STATUS=00
14:01:05  CLOSE       STATUS=00

Tier 4: Synthesis and Design (Exercises 23-28)

Exercise 23: Comprehensive Error-Handling Framework

Design and code a reusable COBOL error-handling framework implemented as a set of copybooks and a CALL-able subprogram. The framework should provide:

  1. A standard error record layout (COPY member)
  2. A centralized error logging subprogram that accepts error parameters and writes to an error file
  3. Standard file I/O wrapper paragraphs that automatically check file status after every operation
  4. Error severity levels with configurable thresholds (e.g., stop after 100 warnings, stop immediately on critical)

Provide: the COPY member, the subprogram source, and an example main program that uses the framework.

Hint: The subprogram should use a LINKAGE SECTION to receive error details from callers. The severity threshold should be maintained in WORKING-STORAGE of the subprogram across calls.

Exercise 24: Retry Logic for VSAM Contention

In a high-volume online environment, VSAM files can experience record-level contention (file status 93) when multiple jobs or CICS transactions try to access the same record simultaneously. Write a complete retry mechanism that:

  1. Attempts to read a VSAM record
  2. If status 93 is returned, waits briefly and retries
  3. Implements exponential backoff (wait 100ms, then 200ms, then 400ms)
  4. Gives up after 5 retries and logs the failure
  5. Includes a COBOL-standard-compliant wait mechanism (since COBOL has no native SLEEP)

Hint: Use a CALL to the IBM Language Environment service CEE3DLY for the wait, or implement a busy-wait loop for non-IBM platforms. Document both approaches.

Exercise 25: Graceful Degradation Pattern

Write a batch program for a financial institution that processes end-of-day account statements. The program must demonstrate graceful degradation:

  • If the primary account master file is available, use it
  • If the primary is unavailable, switch to a read-only backup copy and flag all statements as "unverified"
  • If the statement print file becomes full, switch to an overflow file
  • If the audit log file cannot be opened, continue processing but write audit entries to SYSOUT instead
  • Produce a processing summary that clearly identifies which degradation paths were taken

Hint: Define a WS-DEGRADATION-FLAGS group item with 88-level conditions for each degradation state.

Exercise 26: Checkpoint/Restart with Error Recovery

Design and implement a checkpoint/restart mechanism for a batch program that updates 10 million account records. The mechanism should:

  1. Write a checkpoint record every 10,000 records containing: last key processed, running totals, timestamp
  2. On restart, read the last checkpoint and resume from that point
  3. Handle the case where the checkpoint file itself is corrupted
  4. Use file status checking at every step of the checkpoint logic

Provide the complete WORKING-STORAGE definitions, the checkpoint WRITE paragraph, and the restart READ paragraph.

Hint: Write checkpoints to two alternating slots so that if a checkpoint write fails mid-way, the previous checkpoint is still intact.

Exercise 27: COBOL 2002 Exception Handling

Using the COBOL 2002 standard's RAISE and RESUME statements (where supported), rewrite the error-handling logic from Exercise 19 (cascading data source fallback) using structured exception handling instead of file status code checking.

Compare the two approaches in terms of: - Code clarity - Number of lines of code - Ease of adding new error conditions - Compiler and runtime support across platforms

Hint: Not all COBOL compilers support RAISE/RESUME. GnuCOBOL has partial support. IBM Enterprise COBOL does not support them as of V6.4. Discuss the practical implications.

Exercise 28: Error Handling for Inter-Program Communication

Write a pair of programs (a calling program and a called subprogram) that demonstrate robust error handling across the CALL boundary:

  1. The calling program passes account data to a subprogram for validation
  2. The subprogram validates the data and returns a status structure containing: - Overall return code (0=success, 4=warnings, 8=errors, 16=critical) - Number of individual errors - An error detail table (up to 20 errors)
  3. The calling program evaluates the return and takes appropriate action for each severity level

Include the COPY member for the shared communication area, the calling program, and the subprogram.

Hint: Use a well-defined LINKAGE SECTION interface. The error detail table in the communication area should include field name, error code, and error description for each error found.


Tier 5: Enterprise Integration Challenges (Exercises 29-35)

Exercise 29: Multi-File Reconciliation with Full Error Handling

A bank receives three files each night from different clearinghouses: ACH transactions, wire transfers, and check images. Write a complete reconciliation program that:

  1. Opens all three files with full error handling (any file might be missing on a given day)
  2. Matches transactions across files using account number and amount
  3. Handles: unmatched transactions, duplicate transactions, amount mismatches, date discrepancies
  4. Writes matched records to an output file, unmatched to a suspense file, and all errors to an error file
  5. Produces a reconciliation summary report with counts and totals for each category

The program must handle file status errors at every I/O operation and continue processing even when individual records fail.

Hint: Use a three-way merge pattern. Keep one record from each file in memory and advance the file with the lowest key. Handle the case where one or more files are empty or missing entirely.

Exercise 30: Production Abend Recovery Procedure

You are the on-call programmer. A critical overnight batch job that posts transactions to the general ledger has abended with file status 34 (boundary violation -- disk full) after processing 3.7 million of 5.2 million records. Write:

a) The immediate recovery procedure (step by step) b) The JCL changes needed to provide more space c) The COBOL code changes needed to make the program restartable from where it left off d) The management notification (what happened, impact, resolution, prevention)

Hint: Address the space issue first (compress the output dataset or allocate additional extents). Then implement restart logic that reads the last successful record key from a checkpoint file. Prevent recurrence by allocating output with secondary space and adding a disk-space check before the batch run.

Exercise 31: Idempotent Transaction Processing

Financial regulators require that if a batch program is rerun (due to an error and restart), no transaction should be applied twice. Design and code an idempotent transaction posting program that:

  1. Maintains a "posted transactions" control file keyed by transaction ID
  2. Before posting each transaction, checks if it was already posted in a previous run
  3. Handles all error conditions on both the control file and the master file
  4. Produces an audit trail showing which transactions were posted, skipped (already posted), or rejected (errors)

Hint: The control file is a VSAM KSDS keyed by transaction ID. Before posting a transaction, attempt a READ on the control file. Status 23 (not found) means the transaction is new and should be posted. Status 00 means it was already posted and should be skipped.

Exercise 32: Error Handling Under CICS (Conceptual)

Without writing actual CICS code, design the error-handling strategy for a CICS online program that allows bank tellers to transfer funds between accounts. Address:

a) How CICS error handling differs from batch (HANDLE CONDITION, RESP/RESP2) b) What happens to file I/O error handling under CICS (no DECLARATIVES, no file status) c) How you would handle: account not found, insufficient funds, VSAM contention, CICS abend d) Transaction integrity -- how CICS SYNCPOINT relates to error recovery

Hint: In CICS, you use EXEC CICS HANDLE CONDITION or the RESP option on each EXEC CICS command instead of file status codes. CICS provides automatic transaction backout on abends.

Exercise 33: Financial Calculation Error Matrix

Create a comprehensive test plan for a loan payment calculation module that must handle:

  • Principal amounts from $0.01 to $999,999,999.99
  • Interest rates from 0.000% to 99.999%
  • Terms from 1 month to 480 months (40 years)
  • Early payoff calculations
  • Negative amortization scenarios

For each combination, identify: - Which calculations might cause ON SIZE ERROR - What the maximum intermediate result size needs to be - Where ROUNDED is necessary - Edge cases that could produce incorrect results without proper error handling

Provide the WORKING-STORAGE definitions with field sizes justified by your analysis, and the calculation paragraphs with complete error handling.

Exercise 34: Error Handling Audit

Review the following production program fragment and produce an audit report identifying every missing or inadequate error-handling practice. For each finding, rate the severity (Critical, High, Medium, Low) and provide the corrected code.

       PROCEDURE DIVISION.
       0000-MAIN.
           OPEN INPUT TRANS-FILE
           OPEN I-O ACCT-FILE
           OPEN OUTPUT REPORT-FILE
           READ TRANS-FILE
               AT END STOP RUN
           END-READ
           PERFORM UNTIL WS-EOF = 'Y'
               MOVE TR-ACCT-NUM TO AR-ACCT-NUM
               READ ACCT-FILE
               IF AR-BALANCE > 0
                   COMPUTE AR-BALANCE =
                       AR-BALANCE - TR-AMOUNT
                   REWRITE ACCT-RECORD
               END-IF
               READ TRANS-FILE
                   AT END MOVE 'Y' TO WS-EOF
               END-READ
           END-PERFORM
           CLOSE TRANS-FILE ACCT-FILE REPORT-FILE
           STOP RUN.

Exercise 35: Disaster Recovery File Processing

Design a COBOL program for a bank's disaster recovery scenario. The bank's primary data center has failed, and the DR site has: - A backup of the account master file that is 24 hours old - The current day's transaction file (replicated in real time) - No access to the primary site's error logs or control files

The program must: 1. Reapply all of today's transactions to the 24-hour-old backup 2. Handle transactions that reference accounts created today (not in backup) 3. Detect and handle out-of-sequence transactions 4. Produce a variance report comparing expected balances to actual 5. Flag all accounts that could not be fully reconciled

Provide the complete program design, key data structures, and critical COBOL paragraphs with full error handling.

Hint: Create a "pending accounts" table for transactions that reference unknown account numbers. After all transactions are processed, check if any pending accounts were created by ADD-ACCOUNT transactions earlier in the file. This requires a two-pass approach or a memory-based lookup table.