IMS status NI: Duplicate key in unique secondary index
IMS status code NI means an ISRT or REPL would have created a duplicate key in a secondary index that doesn't allow duplicates. The segment's own key may be fine. The clash is in the index.
Other names for this code
Also written as status code NI, IMS NI, DL/I status NI, NI status code, duplicate secondary index key.
What it means
A secondary index lets programs reach segments by a field other than the primary key. IMS keeps it up to date itself. When a program inserts a source segment, or replaces one and changes a field the index key is built from, IMS adds or changes the matching index entry. If the index is defined as unique and that key value is already in the index, IMS can't make the change, so it returns NI.
NI comes back on ISRT and REPL. Because IMS may already have changed the database before it found the clash, it backs out the call's changes. In batch DL/I, that backout needs a log IMS can use. A batch job that isn't set up for that can end abnormally instead of receiving NI. Fast Path DEDB secondary indexes report NI too.
NI is an error. The insert or replace didn't happen.
Common causes
- Two source segments really do have the same value in the field the index is built on, such as two customers with the same tax ID.
- A REPL changed the indexed field to a value another segment already uses.
- The indexed field is blank or zero on many segments, and the index wasn't set up to leave those values out, so the second blank one clashes.
- The index was meant to allow duplicates but was defined without a subsequence field to make each entry unique.
- After a reorganization or index rebuild, the index definition doesn't match the primary DBD's view of it, so new entries clash. IBM has fixed problems of this kind in tools such as the Online Reorganization Facility.
How to find the problem
- Find the secondary index the segment feeds. In the DBD, look for the LCHILD and XDFLD statements on the source segment and note the SRCH fields.
- Display the I/O area and build the index key value from those fields.
- Read through the index with that key, using a PCB that has the index as its processing sequence (PROCSEQ). If a segment comes back, that's the clash.
- In batch, check the job's log and backout setup if the job abended instead of receiving NI.
How to fix it
- If the data is a true duplicate, reject or report the input.
- If duplicates are valid, change the index to allow them, for example by adding a subsequence field such as /SX or /CK. That's a DBD change and the index has to be rebuilt.
- If blank or default values shouldn't be indexed, use the NULLVAL option or an index suppression exit to leave them out.
- Rebuild the index if it's out of step with the database, and apply any fixes your tools vendor lists for NI during reorganization.
IBM documentation
IBM documentation: status NI. Use the documentation for your installed release.
Related codes
Questions
What is the difference between NI and II?
II means the segment's own key already exists in the database. NI means the segment is fine but its secondary index key clashes with another entry.
Can a REPL get NI?
Yes. If the REPL changes a field the index key is built from, IMS has to change the index entry, and the new value can clash.
Why did my batch job abend instead of getting NI?
IMS needs to back out the partly done call. If the batch job isn't set up with a log IMS can use for that, it can end abnormally instead of returning NI.