CPF1002: Cannot allocate object
CPF1002 means the Allocate Object (ALCOBJ) command couldn't get the lock it asked for, because another job holds a conflicting lock on the object. The text reads "Cannot allocate object <name>."
Other names for this code
Also written as MSGCPF1002, CPF1002 cannot allocate object, cannot allocate object AS400, ALCOBJ CPF1002, iSeries CPF1002, MONMSG CPF1002.
What it means
IBM i protects objects with locks. Reading usually takes a shared lock, while changing, clearing or deleting needs exclusive use. There are five lock states, from *SHRRD (shared for read) up to *EXCL (exclusive), and each one is allowed alongside some states and not others.
ALCOBJ lets a program take locks up front, before doing work that needs them. A nightly job often runs ALCOBJ OBJ((PAYLIB/ before clearing or reorganizing a file. If another job holds a lock that conflicts with the one requested, ALCOBJ waits for the time given in its WAIT parameter. The default comes from the job's class. If the lock still isn't free when the time runs out, ALCOBJ ends with CPF1002 and none of the objects in that request are locked.
The other job may have released the lock a moment later, so a lock holder can be hard to catch after the fact.
Common causes
- An interactive user has the file open, for example in an inquiry program, when a batch job asks for an exclusive lock.
- Another batch job that uses the same object is still running, often because the schedule overlapped.
- A server job, such as an ODBC or JDBC connection, keeps the file open after the client finished with it.
- A previous step of the same job allocated the object at a conflicting level and didn't release it with DLCOBJ.
- The WAIT value is too short for normal activity on the object.
How to find the problem
- Read CPF1002 in the job log with
DSPJOBLOG. It names the object, and earlier messages may name the lock state. - While the problem is happening, run
WRKOBJLCK OBJ(lib/object) OBJTYPE(type). It lists every job holding a lock and the lock state. For a database file, also check member locks with the MBR parameter. - On current releases, the QSYS2.
OBJECT_ LOCK_ INFO view gives the same information through SQL, which is easier to log from a program. - Check the jobs that are usually active at that time with
WRKACTJOB, and compare the job scheduler entries for overlaps.
How to fix it
- Wait for the other job to finish, or ask the user to leave the program, then run the step again.
- Give ALCOBJ a longer WAIT if the conflict is short-lived, or add a retry loop around it with
MONMSG MSGID(CPF1002). - Ask for a weaker lock if the job doesn't need full exclusive use, for example *EXCLRD so other jobs can still read.
- Reschedule overlapping jobs, or end idle server jobs that hold the file open.
- Release locks your job no longer needs with
DLCOBJ. One DLCOBJ is needed for each ALCOBJ.
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(CPF1002) MSGF(QSYS/QCPFMSG)
Also inspect the full job log and second-level message text, including substitution values.
Related codes
Questions
What is the difference between CPF1002 and CPF9803?
Both mean an object couldn't be locked. CPF1002 comes from the ALCOBJ command. CPF9803 is sent by many other commands when they can't allocate the object they need.
Why can't I find the lock holder with WRKOBJLCK?
The other job may have released its lock by the time you look. Log WRKOBJLCK output or query QSYS2.OBJECT_LOCK_INFO from the program as soon as CPF1002 happens.
Does ALCOBJ lock some objects if it fails on one?
No. If any object in the request can't be allocated, none of the objects in that request are locked.