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:
- COURSE (top to bottom)
- INSTR
- REPORT
- STUDENT (left to right)
- GRADE (top to bottom)
- PLACE (left to right)

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:
- Math (top to bottom)
- James
- ReportA
- ReportB (front to back)
- Baker (left to right)
- Pass (top to bottom)
- Coe (front to back)
- Inc (top to bottom)
- Room2 (left to right)

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.