Numbering sequence in a hierarchy: top to bottom

When a database record is stored in the database, the hierarchical arrangement of segments in the database record is the order in which segments are stored.

Starting at the top of a database record (at the root segment), segments are stored in the database in the sequence shown by the numbers in the following figure.

The sequence goes from the top of the hierarchy to the bottom in the first (left most) path or leg of the hierarchy. When the bottom of the database is reached, the sequence is from left to right. When all segments have been stored in that path of the hierarchy, the sequencing begins in the next path to the right, again proceeding from top to bottom and then left to right. (In the second leg of the hierarchy there is nothing to go to at the right.) The sequence in which segments are stored is loosely called top to bottom, left to right.

The following figure shows sequencing of segment types for the school database shown in How data is stored in a database. The sequence of segment types are stored in the following order:

  1. COURSE (top to bottom)
  2. INSTR
  3. REPORT
  4. STUDENT (left to right)
  5. GRADE (top to bottom)
  6. PLACE (left to right)
Figure 1. Hierarchical sequence of segment types for a school database
Arrows flow between labeled boxes from top box MATH down to James, down to ReportA, up left to Baker, down to Pass, and up left to Room2. Dashed lines show all boxes are Dept. Segs of root Seg. MATH.

The following figure shows the segment occurrences for the school database record as shown in Relationship between segments. Because there are multiple occurrences of segment types, segments are read "front to back" in addition to "top to bottom, left to right." The segment occurrences for the school database are stored in the following order:

  1. Math (top to bottom)
  2. James
  3. ReportA
  4. ReportB (front to back)
  5. Baker (left to right)
  6. Pass (top to bottom)
  7. Coe (front to back)
  8. Inc (top to bottom)
  9. Room2 (left to right)
Figure 2. Hierarchical sequence of segment occurrences for school database
Arrows flow between labeled boxes from top box MATH down to James, down to ReportA, behind to ReportB, up left to Baker, down to Pass, up and behind to Coe, down to Inc, and up left to Room2.

Note that the numbering sequence is still initially from top to bottom. At the bottom of the hierarchy, however, observe that there are two occurrences of the REPORT segment.

Because you are at the bottom of the hierarchy, both segment occurrences are picked up before you move to the right in this path of the hierarchy. Both reports relate to the instructor segment James; therefore it makes sense to keep them stored together in the database. In the second path of the hierarchy, there are also two segment occurrences in the student segment. You are not at the bottom of the hierarchical path until you reach the grade segment Pass. Therefore, sequencing is not interrupted by the two occurrences of the student segment Baker and Coe. This makes sense because you are keeping student and grade Baker and Pass together.

Note that the grade Inc under student Coe is not considered another occurrence under Baker. Coe and Inc become a separate path in the hierarchy. Only when you reach the bottom of a hierarchical path is the top to bottom, left to right sequencing interrupted to pick up multiple segment occurrences. You can refer to sequencing in the hierarchy as top to bottom, front to back, left to right, but front to back only occurs at the bottom of the hierarchy. Multiple occurrences of a segment at any other level are sequenced as separate paths in the hierarchy.

As noted before, this numbering of segments represents the sequence in which segments are stored in the database. If an application program requests all segments in a database record in hierarchical sequence or issues Get-Next (GN) calls, this is the order in which segments would be presented to the application program.