Exception handling in CL without Command level MONMSG

0 pts.
Tags:
Development
Lifecycle development
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 ??
ASKED: March 21, 2005  4:28 AM
UPDATED: April 8, 2005  12:06 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • WLT000
    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 pointsBadges:
    report
  • KrisDV
    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 pointsBadges:
    report
  • HardyWan
    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 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following