Terminating Processes from COBOL Programs

You can use the DETACH statement to terminate the process associated with a given task variable. The task variable must have been previously used in a CALL, PROCESS, or RUN statement.

The DETACH <task variable> statement has the same effect as using the CHANGE statement to assign the STATUS task attribute a value of TERMINATED. However, from the standpoint of COBOL programming style, the DETACH is the preferable statement to use for terminating processes.

The program that contained the DETACH statement continues execution asynchronously while the system terminates the specified process. If a program is to reuse the task variable in another process initiation statement, the program should first read the STATUS attribute to determine whether the system has finished terminating the process. If the process is terminated, then the STATUS attribute returns a value of TERMINATED.

The DETACH statement is also used to detach events from interrupt procedures. This use of DETACH is described under Attaching or Detaching an Interrupt in Using Events and Interlocks.