Allocate data queues

If all users of a data queue allocate it before using it, this helps to ensure that a data queue is not accessed by more than one job at a time.

If your application requires that a data queue is not accessed by more than one job at a time, it should be coded to include an Allocate Object (ALCOBJ) command before using a data queue. The data queue should then be deallocated using the Deallocate Object (DLCOBJ) command when the application is finished using it.

The ALCOBJ command does not, by itself, restrict another job from sending or receiving data from a data queue or clearing a data queue. However, if all applications are coded to include the ALCOBJ command before any use of a data queue, the allocation of a data queue already allocated to another job will fail, preventing the data queue from use by more than one job at a time.

When an allocation fails because the data queue is already allocated to another job, the system issues an error message, CPF1002. The Monitor Message (MONMSG) command can be used in the application procedure to monitor for this message and respond to the error message. Possible responses include sending a message to the user and attempting to allocate the data queue again.

Related tasks
Monitor for messages in a CL program or procedure
Related information
Allocate Object (ALCOBJ) command
Deallocate Object (DLCOBJ) command
Monitor Message (MONMSG) command