Defining Segments

A segment in DL/I is defined using a single SEGM statement and one or more FIELD statements.
SEGM Statement
The SEGM statement names and defines segments. For each child segment, the PARENT parameter specifies the name of the related parent segment. Note that the SEGM statement for SEGA (in Figure 7) specifies 0 (zero) for PARENT, indicating that this segment is the root (that is, it has no parent). The BYTES parameter specifies the length of each segment.
FIELD Statement
Each SEGM statement is followed immediately by one or more FIELD statements, which name and define the fields for the segment. An application can access the desired database records by specifying selection criteria for the segment fields. The application specifies the selection criteria in a
segment search argument
(SSA) on the appropriate function call. Only those records whose segment occurrences match the search criteria will be returned to the application.
Sequence Fields
If the NAME parameter on the FIELD statement contains the value SEQ, the field is a
sequence field
. A sequence field can have different functions depending on whether it is specified for a root segment or a dependent child segment. The differences are as follows:
  • If specified for a root segment, a sequence field controls the physical placement of each root segment occurrence and provides direct access to the associated database record.
  • If specified for a child segment, a sequence field causes occurrences of the segment to be stored in ascending order, based on the actual values in the sequence field.
    A sequence field for a child segment assumes that the segment can have more than one occurrence within a given parent occurrence (for example, C1a, C1b, and C1c in Figure 8). As the hierarchical path is traversed from right to left within the parent occurrence, the child occurrence with the lowest value will be found first, and the child occurrence with the highest value will be found last.
Unique or Duplicate Values in Sequence Fields
When defining child segments with sequence fields, you must also specify the value U or M in the NAME parameter. U declares that each occurrence's sequence field value must be unique under the same parent occurrence. M declares that multiple occurrences can have the same sequence field value under the same parent occurrence (that is, duplicate sequence field values are allowed).
Storage Sequence for Duplicate Values
If sequence fields have duplicate values, the RULES parameter for the SEGM statement lets you control how new occurrences of the child segment will be stored relative to existing occurrences under the same parent occurrence. The possible RULES values are:
    -- Stores a new occurrence before all existing occurrences with the same value
  • LAST
    -- Stores a new occurrence after the existing occurrences
  • HERE
    -- Stores a new occurrence immediately before the current occurrence
Concatenated Keys
Concatenated keys
provide an efficient way to access specific segment occurrences. Such a key is constructed by concatenating the value in an occurrence's sequence field with the values in the sequence fields from each higher level segment occurrence in the hierarchical path.
For example, using the hierarchical structure defined in Figure 7, the concatenated key for SEGC is made up of its own sequence field (FIELDD), the sequence field (FIELDC) for SEGB, and the sequence field (FIELDA) for SEGA. The key for a given SEGC occurrence would be determined by the actual values contained in the sequence fields.