IBM i message

CPF9803: Cannot allocate object

CPF9803 means a command needed a lock on an object and couldn't get it in time, because another job holds a lock that conflicts. The message names the object and library.

Other names for this code

Also written as CPF9803 cannot allocate, MSGID CPF9803, cannot allocate object, CPF9803 object locked, MONMSG CPF9803.

What it means

CPF9803 is an escape message from QCPFMSG. Its text reads "Cannot allocate object &2 in library &3". Allocate is IBM i's word for taking a lock.

Before a command reads, changes, renames, moves or deletes an object, it asks for a lock of a certain strength. IBM i has five lock states. They are *SHRRD (shared for read), *SHRUPD (shared for update), *SHRNUP (shared, no update), *EXCLRD (exclusive, others may read) and *EXCL (exclusive). *SHRRD is the weakest and *EXCL the strongest. If another job already holds a lock that conflicts with the one requested, the command waits. When the wait time runs out, the command gives up and sends CPF9803.

The wait time comes from the command when it has a WAIT parameter, or from the job's default wait time (DFTWAIT), which is set by the job's class and can be changed with CHGJOB. Commands that change or remove an object usually need an exclusive lock, so even another job just reading the object can block them.

Common causes

  • A user has the object open in an interactive program, often a file used by a screen they left sitting on their desk.
  • A batch job or a never-ending server job is using the object. Database server jobs that run ODBC, JDBC or SQL work for PCs and web servers can keep files open long after the request finished.
  • A save, restore, reorganize or copy of the object is running at the same time.
  • Another job ran ALCOBJ on the object and hasn't released it.
  • The job waits too short a time because its class has a low DFTWAIT, so a brief lock from another job is enough to fail it.

How to find the problem

  1. Run WRKOBJLCK OBJ(ACCTLIB/PAYMAST) OBJTYPE(*FILE). It lists each job holding a lock on the object and the lock state. For a file, the MBR parameter shows member and data locks too.
  2. Take option 5 next to a job in that list to work with it. Its call stack and open files show what it is doing with the object.
  3. On recent releases the SQL view QSYS2.OBJECT_LOCK_INFO gives the same information, which is handy in scripts.
  4. In the job log of the job that failed, F1 on CPF9803 shows the object, and the command just before it shows what was trying to get the lock.

How to fix it

  • Wait for the other job to finish and try again. For a scheduled job, move it to a time when the object is free.
  • Ask the user to leave the screen that has the file open, or end the job that holds the lock if you are allowed to and it is safe.
  • In a CL program that must handle it, monitor for CPF9803, wait a little with DLYJOB, and try again a set number of times before failing.
  • To make sure a step can't be blocked halfway through, take the locks you need at the start with ALCOBJ and a sensible WAIT value, then release them with DLCOBJ.
  • For server jobs holding files, end the connection or recycle the server jobs during a quiet period.

What it looks like

Cannot allocate object PAYMAST in library ACCTLIB.

IBM documentation

IBM Display Message Descriptions (DSPMSGD). Use the documentation for your installed release.

This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.

Read the installed message description:

DSPMSGD MSGID(CPF9803) MSGF(QSYS/QCPFMSG)

Also inspect the full job log and second-level message text, including substitution values.

Report a correction to WND Software.

Questions

How do I see who is locking an object on IBM i?

Use WRKOBJLCK with the object name, library and type. It shows each job holding a lock and the lock state, and option 5 lets you work with that job.

Why does a command fail with CPF9803 when the other user is only reading the file?

Commands that change or delete an object usually need an exclusive lock, and any lock held by another job, even a shared read lock, conflicts with that.

Can I make the command wait longer?

Yes. Use the command's WAIT parameter if it has one, or raise the job's default wait time with CHGJOB DFTWAIT. Waiting longer only helps if the other job lets go soon.