U command code

As IMS satisfies each level in a retrieval or ISRT call, a position on the segment occurrence that satisfies that level is established. The U command code prevents position from being moved from a segment during a search of its hierarchic dependents.

If the segment has a unique sequence field, using this code is equivalent to qualifying the SSA so that it is equal to the current value of the key field. When a call is being satisfied, if the position is moved above the level that the U code was issued at, the code has no effect for the segment type whose parent changed position.

U is especially useful when unkeyed dependents or non-unique keyed segments are being processed. The position on a specific occurrence of an unkeyed or non-unique keyed segment can be held by using this code.

Example: Suppose you want to find out about the illness that brought a patient named Mary Warren to the clinic most recently, and about the treatments she received for that illness. The following figure shows the PATIENT, ILLNESS, and TREATMNT segments for Mary Warren.

Figure 1. U command code example
Shows PATIENT, ILLNESS, and TREATMENT segments. There are 5 key boxes: PATNO=05810, ILLDATE=19860120, ILLDATE=19860412, DATE=19860412, DATE19860418. PATNO=05810 retrieves ILLDATE=19860120, and ILLDATE=19860412 retrieves DATE=19860412.
To retrieve this information, retrieve the first ILLNESS segment and the TREATMNT segments associated with that ILLNESS segment. To retrieve the most recent ILLNESS segment, you can issue the following GU call:
GU    PATIENTb(PATNObbb=b05810
      ILLNESSb*L
After this call, IMS establishes a position at the root level on the PATIENT segment with the key 05810 and on the last ILLNESS segment. Because other ILLNESS segments with the key 19860412 may exist, you can think of this one as the most recent ILLNESS segment. You might want to retrieve the TREATMNT segment occurrences that are associated with that ILLNESS segment. You can do this by issuing the GN call below with the U command code:
GN     PATIENTb*U
       ILLNESSb*U
       TREATMNT

In this example, the U command code indicates to IMS that you want only TREATMNT segments that are dependents of the ILLNESS and PATIENT segments on which IMS has established position. Issuing the above GN call the first time retrieves the TREATMNT segment with the key of 19860412. Issuing the GN call the second time retrieves the TREATMNT segment with the key 19860418. If you issue the call a third time, IMS returns a not-found status code. The U command code tells IMS that, if it does not find a segment that satisfies the lower qualification under this parent, it cannot continue looking under other parents. If the U command code was not in the PATIENT SSA, the third GN call causes IMS to move forward at the root level in an attempt to satisfy the call. If you supply a U command code for a qualified SSA, IMS ignores the U.

If used in conjunction with command code F or L, the U command code is disregarded at the level and all lower levels of SSA for that call.