In a previous blog, we demonstrated how to use the CICS asynchronous API to start a child task and fetch its response using the
FETCH CHILD command. In that example,
FETCH CHILD waits for the child task to finish before it returns, which could take anywhere from milliseconds to minutes â€“ and while it's waiting for the child to finish, the parent task is suspended in CICS, which means that it's subject to
DTIMOUT and could even be purged before the
FETCH CHILD command returns.
Using the new
NOSUSPEND options on the
FETCH CHILD and
FETCH ANY commands, you have more control over parent-child behaviour, making it even easier to reach response time requirements with asynchronous applications.
Using TIMEOUT with FETCH commands
TIMEOUT option allows you to specify the maximum time in milliseconds that the parent task will wait for a child task to complete. When
TIMEOUT is specified with a non-zero value, the parent task will not be subject to
DTIMOUT. Here's what a
FETCH CHILD command looks like in a COBOL program with a 1 second timeout value:
TIMEOUT1 is defined as shown below, and can be changed dynamically in the program or by reading from a file or database to suit your environment.
If the child task finishes before
TIMEOUT is reached the command will return immediately. If the child task hasnâ€™t finished before
TIMEOUT is reached, a
NOTFINISHED condition will occur with a RESP2 value of 53. You can check the condition and decide the next step in your application. The same applies to the
FETCH ANY command.
Using NOSUSPEND with FETCH commands
Sometimes it is acceptable for your business application to present any possible result to the end user, but an immediate response is important to them. In these cases, the
NOSUSPEND option can be used to get an available result without wasting any time waiting. A
FETCH command with
NOSUSPEND looks like this:
If the child task has finished when the command is issued, the command will return immediately with a
NORMAL response. If the child hasnâ€™t finished, the
NOTFINISHED condition will occur with RESP2 value of 52.
Using these options in your application
You can use
NOSUSPEND on your
FETCH CHILD and
FETCH ANY commands to improve application versatility and meet business needs in a variety of situations:
- For any child tasks that you will definitely need a response from, use
- For child tasks from which you need the response in a timely fashion, specify a
TIMEOUTvalue on your
- For child tasks where no response is acceptable, specify
The following is a COBOL example,
ASYNCPG1, which demonstrates the various flavours of
FETCH commands. The parent program starts four child tasks, and it needs the response from the first child
SUB1, so we have:
For the second child
SUB2, the parent program can wait for up to 1000 milliseconds when fetching the response, so we have:
For the third and fourth children,
SUB4, the parent program can have any result, but can't afford to wait, so we have:
The complete source code from which these snippets were taken is available on GitHub. Go to the IBM Knowledge Center for more detailed information about
NOSUSPEND on FETCH CHILD and FETCH ANY.