Segment Structure


A segment is the smallest structure of the IMS database.IMS cannot able to retrieve data which is less than a segment. Segments can be divided into smaller parts called as fields.

A field can be used in application program. A database record can contain a maximum of 255 types of segments. The number of segment occurrences of any type is limited based on the space allocated for the database.

Segment types can be of fixed length or variable length and user can define the length. Segments consist of two major parts, a prefix and the data item. The prefix portion of a segment is used to store information that IMS uses in managing the database.

Note! SHSAM and SHISAM database segments consist only of the data, and GSAM databases have no segments.

Format of Segment -


Prefix Data
segment code delete byte counters and pointers size field (only for Variable length Segments) seq. (key) field data

Format of a fixed-length segment -


Prefix Data
segment code delete byte counters and pointers seq. (key) field data

Format of variable length segment -


Prefix Data
segment code delete byte counters and pointers seq. (key) field data

Segment Code -


It occupies only one byte.This field used by IMS and used to identify the segment in database. Only 255 segments can be existed. Unique number between 1 - 255 will be allocated to the segment during the loading. Segment numbers will be assigned in ascending order and stores in the same way. Root segment will be always assigns with 1 and the depending segments will be assigns with corresponding numbers.

Delete Byte -


It occupies only one byte. Delete byte describes the status of the Segment. IMS will decide the status by the segment by using the this byte. The space occupied may or may not be available for use.

Counters and Pointers -


It occupies 4 bytes for element.Counter is used for to define logical relationships. Pointers are normally the addresses of respective segments. This area exists in HDAM, HIDAM and HISAM databases.

Note!
  • Hierarchic direct access method (HDAM)
  • Hierarchic indexed direct access method (HIDAM)
  • Hierarchic indexed sequential access method (HISAM).

Size Field -


This field occupies 2 bytes. This field will be there for variable length records. For variable-length segments, this field states the size of the segment. In total the field contains, variable length record plus including the size field (2 bytes).

Sequence (Key) Field/Key Field -


Unique identifier of a segment. The sequence field referred to as the key field. Key field can be used to keep occurrences of a segment type under a common parent, based on the data or value entered in this field.

Key fields are the logical relationships and secondary indexes of the database. The key field not only can contain data but also can be used in special ways that help to organize the database.

IMS will store the records in ascending numerical order. The fields can be sorted in alphabetical order by defining the name field as a unique key field. The data or value in the key field is called the key of the segment. The key field can be defined as unique or non-unique. key field not required to define in every segment type.

The sequence field is also called as the key field. It can be used to keep occurrences of a segment type in sequence under a common parent. The above arrangement can be done based on the data or value entered in this field. A key field can be defined in the root segment of a HISAM, HDAM, or HIDAM database to give direct access to an application program.

A key field can be used in HISAM and HIDAM databases to allow database records to be retrieved sequentially. Key fields are used for logical relationships and secondary indexes.

The data or value in the key field is called the key of the segment. The key field can be defined as unique or non-unique. It is not required to define a key field in every segment type.

CONCATENATED KEY:

The concatenation of all the keys of the parent with the key of the segment.

Data -


The data fields to contain the actual data being stored in the database. Data fields, including sequence fields, can be defined to IMS for use by applications programs.

Database record -


One root with all of its children . Database record is combination of root segment and all subordinate segments. It is a single occurrence of the root segment. Each database record can contains only one root segment. It may have multiple occurrences of dependent segments.