How variable-length segments are stored and processed
When a variable-length segment is initially loaded, the space used to store its data portion is the length specified in the MINBYTES operand or the length specified in the size field, whichever is larger.
If the space in the MINBYTES operand is larger, more space is allocated for the segment than is required. The additional space can be used when existing data in the segment is replaced with data that is longer.
The prefix and data portion of HDAM, PHDAM, HIDAM, and PHIDAM variable-length segments can be separated in storage when updates occur. When this happens, the first four bytes following the prefix point to the separated data portion of the segment.
The following figure shows the format of a HISAM variable-length segment. It is also the format of an HDAM, PHDAM, HIDAM, or PHIDAM variable-length segment when the prefix and data portion of the segment have not been separated in storage.

The following figure shows the format of an HDAM, PHDAM, HIDAM, or PHIDAM variable-length segment when the prefix and data portion of the segment have been separated in storage.

After a variable-length segment is loaded, replace operations can cause the size of data in it to be either increased or decreased. When the length of data in an existing HISAM segment is increased, the logical record containing the segment is rewritten to acquire the additional space. Any segments displaced by the rewrite are put in overflow storage. Displacement of segments to overflow storage can affect performance. When the length of data in an existing HISAM segment is decreased, the logical record is rewritten so all segments in it are physically adjacent.
When a replace operation causes the length of data in an existing HDAM, PHDAM, HIDAM, or PHIDAM segment to be increased, one of two things can happen:
- If the space allocated for the existing segment is long enough for the new data, the new data is simply placed in the segment. This is true regardless of whether the prefix and data portions of the segment were previously separated in the data set.
- If the space allocated for the existing segment is not long enough for the new data, the prefix and data portions of the segment are separated in storage. IMS puts the data portion of the segment as close to the prefix as possible. Once the segment is separated, a pointer is placed in the first four bytes following the prefix to point to the data portion of the segment. This separation increases the amount of space needed for the segment, because, in addition to the pointer kept with the prefix, a 1-byte segment code and 1-byte delete code are added to the data portion of the segment (see Figure 1). In addition, if separation of the segment causes its two parts to be stored in different blocks, two read operations will be required to access the segment.
When a replace operation causes the length of data in an existing HDAM, PHDAM, HIDAM, or PHIDAM segment to be decreased, one of three things can happen:
- If prefix and data are not separated, the data in the existing segment is replaced with the new, shorter data followed by free space.
- If prefix and data are separated but sufficient space is not available immediately following the original prefix to recombine the segment, the data in the separated data portion of the segment is replaced with the new, shorter data followed by free space.
- If prefix and data are separated and sufficient space is available immediately following the original prefix to recombine the segment, the new data is placed in the original space, overlaying the data pointer. The old separated data portion of the segment is then available as free space in HD databases.