IMS status code

IMS status II: Segment already exists

IMS status code II means an ISRT call tried to add a segment that already exists. A segment of that type with the same unique key is already there, under the same parent or, for a root, in the database.

Other names for this code

Also written as status code II, IMS II, DL/I status II, II status code, duplicate segment IMS.

What it means

When a segment type has a unique sequence field, IMS doesn't allow two occurrences with the same key under one parent. For a root segment with a unique key, that means two roots with the same key in the database. When an ISRT would break that rule, IMS rejects it with II and adds nothing.

Only ISRT returns II, including the ISRT command in EXEC DLI programs. A segment type whose sequence field allows duplicates, or that has no sequence field, doesn't get II for a repeated key. In load mode (PROCOPT=L) the same situation is reported as LB instead. A duplicate key in a unique secondary index is reported as NI.

II can be a real error or an expected result. A program that loads new records shouldn't see it. A program that adds a record if it's missing and updates it otherwise can simply try the ISRT and treat II as "already there".

Common causes

  • The record being added already exists, for example because the same input file was processed twice or a transaction was submitted twice.
  • The program built the key wrongly, so two different input records produce the same key.
  • The program meant to update an existing segment but issued ISRT instead of a get hold followed by REPL.
  • For a dependent segment, the program's position or parent SSAs put the new segment under a parent that already has a twin with that key.
  • A rerun after a failure repeated inserts that had already been committed before the failure.

How to find the problem

  1. Display the key in the I/O area at the time of the ISRT, and the parent SSAs if there are any.
  2. Issue a GU with the same parent SSAs and a qualified SSA on the new segment's key. If it returns the segment, the duplicate is real.
  3. Check the DBD for the segment's sequence field. If it's defined as unique, duplicates are rejected.
  4. If the job was rerun, check how far the earlier run got and whether its updates were committed.

How to fix it

  • If the data is a true duplicate, skip or report the input record.
  • For add-or-update logic, on II issue a GHU for the segment and then a REPL with the new data.
  • Fix the key-building logic if different records should have different keys.
  • Make restart logic skip records already committed before the failure.

IBM documentation

IBM documentation: status II. Use the documentation for your installed release.

Report a correction to WND Software.

Questions

Is II always an error?

No. Many programs expect it when they insert a record that may already exist, and switch to an update when they get it.

What is the difference between II and NI?

II means the segment's own key already exists. NI means the insert or update would put a duplicate key into a unique secondary index.

Is II the same as SQLCODE -803?

It's the closest IMS equivalent. Both mean an insert would create a duplicate in something defined as unique.