3/10/08 Create a Universal SIGNOFF command

How would you like to be able to use the SIGNOFF command to perform any of the three following common connections?



SIGNOFF – normal signoff
ENDGRPJOB – end an active secondary job on a single workstation
ENDPASTHR – end a session to another system

This can be accomplished with the following command and control language code.

Modified SIGNOFF command


SIGNOFF: CMD PROMPT('Sign Off')
PARM KWD(LOG) TYPE(*CHAR) LEN(7) RSTD(*YES) +
DFT(*NOLIST) VALUES(*NOLIST *LIST) +
PROMPT('Job log')
PARM KWD(DROP) TYPE(*CHAR) LEN(5) RSTD(*YES) +
DFT(*DEVD) VALUES(*DEVD *YES *NO) +
PROMPT('Drop line')
PARM KWD(ENDCNN) TYPE(*CHAR) LEN(4) RSTD(*YES) +
DFT(*NO) VALUES(*YES *NO) PROMPT('End +
connection')

SIGNOFF CLP

SIGNOFF: PGM PARM(&LOG &DROP &ENDCNN)

/*=================================================================*/
/* Declare standard error handling variables */
/*=================================================================*/
DCL VAR(&ERRORSW) TYPE(*LGL)
DCL VAR(&MSG) TYPE(*CHAR) LEN(512)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(512)
DCL VAR(&MSGF) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&KEYVAR) TYPE(*CHAR) LEN(4)
DCL VAR(&KEYVAR2) TYPE(*CHAR) LEN(4)
DCL VAR(&RTNTYPE) TYPE(*CHAR) LEN(2)

/*=================================================================*/
/* Declare program parameters */
/*=================================================================*/
DCL VAR(&LOG) TYPE(*CHAR) LEN(07)
DCL VAR(&DROP) TYPE(*CHAR) LEN(05)
DCL VAR(&ENDCNN) TYPE(*CHAR) LEN(04)

/*=================================================================*/
/* Declare program variables */
/*=================================================================*/
DCL VAR(&GRPJOB) TYPE(*CHAR) LEN(10)

/* Setup the generic monitor message for standard error handling */
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(STDERR1))

/* Determine if this is a group job */
RTVGRPA GRPJOB(&GRPJOB)

IF COND(&GRPJOB *EQ '*NONE') THEN(DO)
ENDPASTHR
MONMSG MSGID(CPF0000) EXEC(DO)
QSYS/SIGNOFF LOG(&LOG) DROP(&DROP) ENDCNN(&ENDCNN)
ENDDO
ENDDO
ELSE CMD(DO)
ENDGRPJOB
ENDDO
GOTO CMDLBL(ENDJOB)

/*=================================================================*/
/* S T A N D A R D E R R O R H A N D L I N G R O U T I N E */
/*=================================================================*/
STDERR1:
IF &ERRORSW SNDPGMMSG MSGID(CPF9999) +
MSGF(QCPFMSG) MSGTYPE(*ESCAPE)
CHGVAR &ERRORSW '1' /* Set to fail on error */
RCVMSG MSGTYPE(*EXCP) RMV(*NO) KEYVAR(&KEYVAR)
STDERR2:
RCVMSG MSGTYPE(*PRV) MSGKEY(&KEYVAR) RMV(*NO) +
KEYVAR(&KEYVAR2) MSG(&MSG) +
MSGDTA(&MSGDTA) MSGID(&MSGID) +
RTNTYPE(&RTNTYPE) MSGF(&MSGF) +
SNDMSGFLIB(&MSGFLIB)
IF (&RTNTYPE *NE '02') GOTO STDERR3
IF (&MSGID *NE ' ') SNDPGMMSG +
MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
MSGDTA(&MSGDTA) MSGTYPE(*DIAG)
IF (&MSGID *EQ ' ') SNDPGMMSG +
MSG(&MSG) MSGTYPE(*DIAG)
RMVMSG MSGKEY(&KEYVAR2)
STDERR3:
RCVMSG MSGKEY(&KEYVAR) MSGDTA(&MSGDTA) +
MSGID(&MSGID) MSGF(&MSGF) +
SNDMSGFLIB(&MSGFLIB)
SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE)
ENDJOB:
ENDPGM

The key to make this work is that the command and CL program are compiled into a system override library that is put at the beginning of the system library list. Add the library before the QSYS library by modifying the QSYSLIBL system value.




Disclaimer: Vision Solutions makes every effort to provide accurate system management information and programming code; however the company cannot be held liable for the accuracy of information nor its compatibility in your own environment. Please review and test thoroughly before implementing. © Copyright 2008, Vision Solutions, Inc. All rights reserved. IBM, System i, iSeries, and AS/400 are trademarks of International Business Machines Corporation.

No comments: