Sample CAF scenarios

One or more tasks can use call attachment facility (CAF) to connect to Db2. This connection can be made either implicitly or explicitly. For explicit connections, a task calls one or more of the CAF connection functions.

A single task with implicit connections

The simplest connection scenario is a single task that makes calls to Db2 without using explicit CALL DSNALI statements. The task implicitly connects to the default subsystem name and uses the default plan name.

When the task terminates, the following events occur:
  • If termination was normal, any database changes are committed.
  • If termination was abnormal, any database changes are rolled back.
  • The active plan and all database resources are deallocated.
  • The task and address space connections to Db2 are terminated.

A single task with explicit connections

The following example pseudocode illustrates a more complex scenario with a single task.
CONNECT
    OPEN        allocate a plan
    SQL or IFI call
    ···
    CLOSE       deallocate the current plan
    OPEN        allocate a new plan
    SQL or IFI call
    ···
    CLOSE
DISCONNECT

A task can have a connection to only one Db2 subsystem at any point in time. A CAF error occurs if the subsystem name in the OPEN call does not match the subsystem name in the CONNECT call. To switch to a different subsystem, the application must first disconnect from the current subsystem and then issue a connect request with a new subsystem name.

Multiple tasks

In the following scenario, multiple tasks within the address space use Db2 services. Each task must explicitly specify the same subsystem name on either the CONNECT function request or the OPEN function request. Task 1 makes no SQL or IFI calls. Its purpose is to monitor the Db2 termination and startup ECBs and to check the Db2 release level.
TASK 1             TASK 2          TASK 3          TASK n
 
CONNECT
                   OPEN            OPEN            OPEN
                   SQL             SQL             SQL
                   ...             ...             ...
                   CLOSE           CLOSE           CLOSE
                   OPEN            OPEN            OPEN
                   SQL             SQL             SQL
                   ...             ...             ...
                   CLOSE           CLOSE           CLOSE
DISCONNECT