How an HSAM record is stored

Segments in an HSAM database are loaded in the order in which you present them to the load program.

You should present all segments within a database record in hierarchical sequence. If a sequence field has been defined for root segments, you should present database records to the load program in ascending root key sequence.

The following figure shows an example HSAM database.

Figure 1. Example HSAM database
Root: SKILL1. SKILL1 has children NAME1, NAME2, NAME3. NAME1 has children EXPR1 and EDUC1. NAME2 has children EXPR2, EXPR3, EXPR4. NAME3 has children EDUC2 and EDUC3.

The following figure shows how the example HSAM database shown in the preceding figure would be stored in blocks.

Figure 2. Example HSAM database stored in blocks
Block 1: SKILL1, NAME1, EXPR1, EDUC1. Block 2: NAME2, EXPR2, EXPR3, EXPR4. Block 3: NAME3, EDUC2, EDUC3, beginning of next record. In each segment is a prefix with a segment code and delete byte.

In the data set, a database record is stored in one or more consecutive blocks. You define what the block size will be. Each block is filled with segments of the database record until there is not enough space left in the block to store the next segment. When this happens, the remaining space in the block is padded with zeros and the next segment is stored in the next consecutive block. When the last segment of a database record has been stored in a block, any unused space, if sufficient, is filled with segments from the next database record.

In storage, an HSAM segment consists of a 2-byte prefix followed by user data. The first byte of the prefix is the segment code, which identifies the segment type to IMS. This number can be from 1 to 255. The segment code is assigned to the segment by IMS in ascending sequence, starting with the root segment and continuing through all dependents in hierarchical sequence. The second byte of the prefix is the delete byte. Because DLET calls cannot be used against an HSAM database, the second byte is not used.