IBM i message

CPF5026: Duplicate key not allowed for member

CPF5026 means a write or update to a database file failed because the new key matches a record that already exists, and the member requires unique keys. The record isn't written, and the message CPF5009 just before it names the records involved.

Other names for this code

Also written as CPF5026 duplicate key, MSGID CPF5026, duplicate key not allowed for member, RNQ1021 CPF5026, IBM i duplicate key.

What it means

CPF5026 has the text "Duplicate key not allowed for member" followed by the member name. IBM lists it as the duplicate key message among the database I/O messages that a program can monitor. It is a notify message with severity 30. When nothing handles it, the job gets a reply choice of C to cancel or I to ignore, and the default reply is cancel.

The write or update is rejected and the file stays as it was. The second-level text points you to the diagnostic message CPF5009, sent just before it. CPF5009 names the record that failed and the record that already holds the key.

The unique rule can come from the physical file itself, from a logical file with the UNIQUE keyword, or from a unique SQL index or constraint. Any of these over the same data can cause CPF5026. IBM uses a separate message, CPF5034, when the clash is in another member's access path, and CPF5084 and CPF5085 when the clash is with a key that another job hasn't committed yet.

Programs normally see it through their language. In ILE RPG it is file status 01021, record already exists, and the default handler sends RNQ1021. In ILE COBOL it is file status 22. An SQL INSERT or UPDATE that breaks a unique rule gets SQLCODE -803 instead.

Common causes

  • A program wrote a new record whose key is already in the file, for example a customer added twice or an order number reused.
  • An update changed a key field to a value that another record already has.
  • A logical file or SQL index with a unique key sits over the file, and the program never checks that key.
  • A batch load ran twice, or loaded into a file that still held last run's data.
  • Two jobs generated the same next number at the same time because the counter wasn't locked while it was read and updated.

How to find the problem

  1. Run DSPJOBLOG and find CPF5009 just before CPF5026. Press F1 on it to see the member, the record number being written or updated and the record number that already has the key.
  2. If the member named belongs to a logical file, run DSPDBR on the physical file to list everything built over it, and DSPFD ... TYPE(*ACCPTH) on the logical file to see its key fields.
  3. Read the existing record by its record number with SQL and compare its key with the one the program was writing.
  4. For a program failure, check the RNQ1021 or COBOL message that follows. It names the program and the statement that did the write.

How to fix it

  • If CPF5026 itself is waiting for a reply, answer C if the program shouldn't continue, or I to skip this one record when you know that is safe for the data. An RPG program shows its own inquiry, RNQ1021, instead.
  • Fix the key, or update the existing record instead of writing a new one.
  • Make the program check for the record first, or handle the duplicate (RPG status 01021, COBOL status 22) and report it rather than stopping.
  • Make next-number routines lock the counter record while they read and update it, so two jobs can't take the same number.
  • Clear or reconcile the target file before rerunning a load.

What it looks like

Duplicate record key in member CUSTMAST.
Duplicate key not allowed for member CUSTMAST.

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(CPF5026) MSGF(QSYS/QCPFMSG)

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

Report a correction to WND Software.

Questions

Is it safe to reply I to CPF5026?

It skips the write or update that failed, and the program carries on. That is fine for a known duplicate in a reload, but in normal processing it can leave work half done, so check with the application owner first.

What is the difference between CPF5026 and CPF5009?

CPF5009 is a diagnostic that names the two records with the same key. CPF5026 is the notify message that actually fails the operation.

Why do I get CPF5026 when the physical file has no unique key?

Another access path over the file requires unique keys. That can be a logical file with UNIQUE, a unique SQL index or a primary key or unique constraint.