Use SET TIMER CANCEL with caution

Document ID : KB000028857
Last Modified Date : 14/02/2018
Show Technical Document Details

TIMER TASKs are maintained in the CA-IDMS CV as a linked list of control blocks called ICEs. Each ICE has pointers containing the address of the next and prior ICE in the list.

When any SET TIMER statement uses a TIMER ID, it is the address of the ICE which is stored in the field referenced by the TIMER ID clause.

If you have code which does the following:- 

SET TIMER START INTERVAL 60 SECONDS TASK CODE 'TASKA' TIMER ID WS-TIMER-ID.

a timer task is created and the address of the ICE returned in WS-TIMER-ID.  You can then issue this:-

SET TIMER CANCEL TIMER ID WS-TIMER-ID. 

and that timer task will be removed.

The problem is that it is almost impossible to be sure that the address saved in WS-TIMER-ID still points to the same ICE.  

In practice, what happens most is that the SET TIMER START and SET TIMER CANCEL statements are in different programs, or different executions of the same program.  If the ICE has expired in the mean time and another SET TIMER START issued by any other program in the CV, then that timer task could occupy the same address in storage.  If that happens, the SET TIMER CANCEL will still work, but cancel the newly established timer task successfully, and complete with a 0000 ERROR-STATUS.  There is no way to know that that wasn't the timer task your program was intending to cancel.

The only way to avoid this is if the SET TIMER START and the SET TIMER CANCEL are in the same execution of the same program and the logic of the program is such that it is impossible for the timer task to have expired.

If what you are trying to achieve cannot be done in such a way that the logic dictates that the correct timer task will still be at the same ICE address, then an alternate solution must be found.

If the reason that your program wants to cancel an existing timer task is just because it really wants to set a new one but also be sure that none already exists so that a duplicate won't be created, it is recommended to use callable DCMT to issue a DCMT D TIME TASKS and analyze the output. If one already exists then suppress the call to set a new one.

For more information on the SET TIMER statement, see the CA IDMS DML Reference Guide for COBOL manual in the chapter entitled "Data Manipulation Language Statements".

For more information on programmatically invoking DCMT, see the CA IDMS Callable Services Guide manual in the chapter entitled "Invoking System Tasks from Programs", under "Invoking DCMT and DCUF Commands from Programs".