***************************************************************** * * Module Name: NEP * * This module illustrates the use of a cancel handler. The main * procedure is a forever loop which puts the program into a * delay wait state for 60 seconds, wakes up (very briefly) and * goes back to sleep again for another 60 seconds, etc. This is * intended to simulate a never ending program that you might run * in batch which is wating for a record to arrive in a data queue * or something to that effect. * * The program is representative of a program that should not be * easily cancelled. It therefore registers a cancel handler. * When the program is cancelled, the cancel handler will submit * another job to batch running this same program. This resubmit * action is only overriden if the user modifies the contents of * a 1-byte data area called ACTION to contain the value 'q' or * 'Q'. To prepare this software to be run perform the following * steps. * * 1) This program requires one of the exports of service program * CONDHDLR. If you haven't already done so, follow the steps * outlined in that module to compile and create that service * program. Note, NEP does not require you to also follow the * steps for running the CONDHDLR demo. * 2) Compile CLP program CRTACTION (option 14 in PDM). * 3) Invoke program CRTACTION to create the ACTION data area * in your library. You need to pass the name of the library * to the CRTACTION program. Here is how you might decide to * invoke this program. * * Call CRTACTION Parm( MYLIB ) * * Note, at run time this library must be in your library list. * 4) Compile this module, NEP with option 15 in PDM * (CRTRPGMOD). * * 5) Issue the following command. * CrtPgm Pgm( NEP ) BndSrvPgm( CONDHDLR) ActGrp( *Caller ) * * To see how this program works * * 1) Change the data area with the following command * * ChgDtaAra Action Value( 'X' ) * * 2) Submit the NEP program to batch. Here is a command you can * use. * * SbmJob Job( NEP ) Cmd( Call NEP ) JobQ( Whatever) * * The JobQ parameter is unnecessary if you don't mind submitting * to the default job queue (usually QBATCH). You might, however, * want to pick another job queue if the default job queue is * queued up. * * 3) Now cancel the NEP job with the *IMMED option. You should notice * that another job appears in its place (either waiting in the * job queue or in execution) with the same name but a different * job number. This happens because the cancel handler notices that * the ACTION data area contains neither a 'q' nor a 'Q'. * * 4) Issue the following command. * * ChgDtaAra Action Value( 'q' ) * * 5) Cancel the NEP job again with the *IMMED option. This time * the job cancels with no new job to take its place because * the cancel handler this time sees that the ACTION data area * contains the value 'q'. * ***************************************************************** * Standard Types D MsgIdType S 7 Based( DummyPtr ) D FeedbackType S 12 Based( DummyPtr ) * Prototypes D pExtractMsgId PR Like( MsgIdType ) D Feedback Like( FeedbackType ) D pCnclHdlr PR D OptionalPtr * Options( *Omit ) D Const D As400Cmd PR ExtPgm( 'QCMDEXC' ) D Cmd 500 Const D LenCmd 15P 5 Const * Other data D MyProcPtr S * ProcPtr D Inz( %Paddr( 'PCNCLHDLR' ) ) D FeedbackMsg S 50 D Feedback S Like( FeedbackType ) D MsgId S Like( MsgIdType ) D DummyVar S 1 D EndedMsg C 'Program Ended' D DlyJob C 'DlyJob 60' D Forever S N Inz( *On ) D ActionDtaAra S 1 DtaAra( ACTION ) * Register pCnclHdlr as this program's cancel handler C CallB 'CEERTX' C Parm MyProcPtr C Parm *Omit C Parm Feedback * If we get a negative feedback, then end this program C Eval MsgId = pExtractMsgId( Feedback ) C If MsgId <> *Blank C Eval FeedbackMsg = 'CEERTX returned ' C + MsgId C FeedbackMsg Dsply C EndedMsg Dsply DummyVar C Eval *INLR = *On C Return C EndIf * Loop harmlessly forever. When operator cancels this program, * cancel handler takes over. If you really want this program * to end, then place a 'Q' into your ACTION data area. C DoW Forever C CallP As400Cmd( DlyJob: %Size( DlyJob ) ) C EndDo * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * = * pCnclHdlr - Cancel handler. This routine checks the contents of * a 1-byte data are called Action. If it does not * contain a value of 'Q' (for quit) it resubmits * itself to batch, thus making it difficult to * cancel this particular program. P pCnclHdlr B D pCnclHdlr PI D OptionalPtr * Options( *Omit ) D Const * Local data definitions D SbmJob C 'SbmJob Job( NEP ) + D Cmd( Call NEP )' * Retrieve current contents of the ACTION data area C In ActionDtaAra * If the Action data area is not 'Q' (for quit) then * resubmit this job C If ActionDtaAra <> 'Q' C And ActionDtaAra <> 'q' C CallP As400Cmd( SbmJob: %Size( SbmJob ) ) C EndIf P pCnclHdlr E