0 pts.
 Exception handling in CL without Command level MONMSG
i Have a CL program in which commands are added quite frequently . Because of the frequent addition of commands - adding command level MONMSGs to monitor each error is rendering the program BULKY. Is there any way to trap all possible error messages on all the commands in the CL program without using a Command Level MONMSG. Using program level MONMSG like CPF0000 will trap all errors - and then the user can be informed that an error has taken place using SNDPGMMSG. However, how will the user be informed of the exact error message - and on which CL command the error takes place on ??

Software/Hardware used:
ASKED: March 21, 2005  4:28 AM
UPDATED: April 8, 2005  12:06 PM

Answer Wiki:
Try something like the following. It will write the diagnostic messges to the job log before issuing the exception message. Be sure to place the error handling code at the bottom of your program. Insert a GOTO before it to skip to the ENDPGM or use a RETURN statement. /*----------------------------------------------------------------------------*/ /* Standard error handling variables. */ /* */ /* &ERRORSW Logical(1) - Switch identifying error processing has begun. */ /* &MSGDTA Char(100) - Substitution data for the message. */ /* &MSGF Char(10) - Message file containing the message. */ /* &MSGFLIB Char(10) - Library containing the message file. */ /* &MSGID Char(7) - Message number. */ /* */ DCL VAR(&ERRORSW) TYPE(*LGL) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(100) DCL VAR(&MSGF) TYPE(*CHAR) LEN(10) DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) MONMSG MSGID(CPF0000) EXEC(GOTO STDERR1) /* */ /* */ /* */ EXIT: RETURN /* */ /* Standard error handling routine */ /* */ STDERR1: IF &ERRORSW SNDPGMMSG MSGID(CPF9999) + MSGF(QCPFMSG) MSGTYPE(*ESCAPE) /* Func chk */ CHGVAR VAR(&ERRORSW) VALUE('1') /* Set to fail if + error occurs */ STDERR2: RCVMSG MSGTYPE(*DIAG) MSGDTA(&MSGDTA) MSGID(&MSGID) + MSGF(&MSGF) MSGFLIB(&MSGFLIB) IF COND(&MSGID *EQ ' ') THEN(GOTO + CMDLBL(STDERR3)) SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) + MSGDTA(&MSGDTA) MSGTYPE(*DIAG) GOTO CMDLBL(STDERR2) /* Loop back for addl + diagnostics */ STDERR3: RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) + MSGF(&MSGF) MSGFLIB(&MSGFLIB) MONMSG MSGID(CPF1005) /* Ignore if not allocated */ SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) + MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE) ENDPGM
Last Wiki Answer Submitted:  March 23, 2005  11:29 am  by  Rchevalier   0 pts.
All Answer Wiki Contributors:  Rchevalier   0 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

PGM
DCL VAR(&PROCESS) TYPE(*CHAR) LEN(20) +
VALUE(‘Start up’)
DCL VAR(&ERRORMSG) TYPE(*CHAR) LEN(80)

MONMSG MSGID(CPF0000) EXEC(GOTO ERROR)

CHGVAR VAR(&PROCESS) VALUE(‘Initialize Tape’)
INZTAP DEV(TAP01)

CHGVAR VAR(&PROCESS) VALUE(‘Save Library ABC’)
SAVLIB LIB(ABC) DEV(TAP01)

GOTO CMDLBL(ENDPGM)

ERROR:
RCVMSG MSGTYPE(*EXCP) RMV(*NO) MSG(&ERRORMSG)
SNDPGMMSG MSG(‘An error occured during:’ |> + &PROCESS)
SNDPGMMSG MSG(&ERRORMSG)

ENDPGM: ENDPGM

 0 pts.

 

If I recall well, you can restrict the monmsg also to a range f.e. MONMSG CPF4000 will catch all errors in the 4001-4999 range. Combined with the CL you should be able to catch messages and treat them accordingly

 0 pts.

 

rchevalier had already provided you a perfect solution. I just want to highlight that most CL commands allow R=Retry choice after clearing the encountered error. It may not be a good idea (especially from production support point of view) to have a “MONMSG ALL” CL job.

 0 pts.