I finally figured out how to make a COBOL program register a condition handler. The code runs, but it doesn't do what I want it to do. Please tell me if I am overlooking something.
Here's the module that registers the handler:
There is no program called PROOF1. The condition handler kicks in and sets a status code to "10" (resume).
AFAIK, there is no way for the first module to know (at the point of the goback) whether the handler kicked in or not. The only think I can think of is to have the condition handler update something external (a database file, a data area, an environment variable, etc.) that the first module could test. That would slow down the program immensely.
Am I missing something?
Here's the module that registers the handler:
Code:
Identification division. Program-ID. QAD02910L. Environment division. Configuration section. Special-names. Linkage SYS for "CEEHDLR" Linkage procedure for "MONMSGHDLR". Data division. Working-storage section. 01 procPtr procedure-pointer. 01 pErrHdlr_UserData pointer. 01 errhdlr_UserData pic x(4). 01 fc pic x(12) value low-value. Procedure division. Main-process. set procPtr to entry "MONMSGHDLR" move "xxxx" to errhdlr_UserData set pErrHdlr_UserData to address of errhdlr_UserData call "CEEHDLR" using procPtr, pErrhdlr_UserData, fc call "PROOF1" goback.
Code:
IDENTIFICATION DIVISION. PROGRAM-ID. MonmsgHdlr. DATA DIVISION. WORKING-STORAGE SECTION. 01 MSG PIC X(128). LINKAGE SECTION. 01 CURR-TOKEN PIC X(12). 01 TOKEN-PTR PIC S9(9) BINARY. 01 RC PIC S9(9) BINARY. 01 NEW-TOKEN PIC X(12). PROCEDURE DIVISION USING CURR-TOKEN, TOKEN-PTR, RC, NEW-TOKEN. PROC-DIV SECTION. MAIN-001. DISPLAY "MonmsgHandler is active...". MOVE 10 TO RC. MOVE "*OMIT" TO NEW-TOKEN. MAIN-END. EXIT PROGRAM.
Am I missing something?
Comment