Retry is a pattern you implement to handle transient failures safely. Keep attempts bounded and add backoff.
Like calling a busy office: you try again a few times, waiting longer between calls, and eventually leave a message if no answer.
1234567891011121314151617181920212223WORKING-STORAGE SECTION. 01 ATTEMPTS PIC 9 VALUE 0. 01 MAX-ATTEMPTS PIC 9 VALUE 3. 01 OPEN-STATUS PIC XX. ... PROCEDURE DIVISION. OPEN-TRY. ADD 1 TO ATTEMPTS OPEN INPUT MYFILE MOVE FILE-STATUS OF MYFILE TO OPEN-STATUS IF OPEN-STATUS NOT = '00' IF ATTEMPTS < MAX-ATTEMPTS PERFORM BACKOFF GO TO OPEN-TRY ELSE DISPLAY 'Open failed after retries, RC=8' STOP RUN END-IF END-IF. ... BACKOFF. *> Implement wait (site-specific) DISPLAY 'Waiting before retry # ' ATTEMPTS.
Adjust for your compiler; use proper sleep APIs where available.
Mistake | Problem | Fix |
---|---|---|
Infinite loops | Hangs and resource waste | Add max attempts |
No delay | Hammering a busy resource | Use backoff |
Retrying non-transient errors | Wastes time | Check error codes; fail fast |
Concept | Tip | Example |
---|---|---|
Max attempts | Keep small (3-5) | MAX-ATTEMPTS = 3 |
Backoff | Wait longer each time | 1s, 2s, 4s |
Failover | Return code, message | RC=8 |
1. Is RETRY a standard COBOL verb?
2. What is a good strategy for transient errors?
3. Where do you store attempt counters?
4. What should happen after max attempts?
5. Which JCL concept relates to post-failure recovery?