Using Coroutines in COBOL

You can implement coroutines in COBOL using CALL, CONTINUE, and EXIT PROGRAM statements. The CALL statement creates a synchronous task that is an active coroutine and changes the parent process into a continuable coroutine. The task can return control to its parent by executing an EXIT PROGRAM statement. The parent can return control to its task by executing a CONTINUE <task variable> statement.

The EXIT PROGRAM statement, in addition to transferring control to the parent, also specifies where execution resumes when the parent later continues the task. The simple form EXIT PROGRAM specifies that the task resume from the beginning. The EXIT PROGRAM RETURN HERE form specifies that the task resume with the statement that follows the EXIT PROGRAM statement.

In COBOL85, the EXIT PROGRAM statement in a nested program merely causes the nested program to be exited. To return control from a synchronous task to a parent program, the EXIT PROGRAM statement must occur in the main program rather than in a nested program.