IMS Hierarchical Database Basics


A database segment definition defines the fields for a set of segment instances similar to the way a relational table defines columns for a set of rows in a table. In this way, segments relate to relational tables, and fields in a segment relate to columns in a relational table.

The name of an IMS segment becomes the table name in an SQL query.

A fundamental difference between segments in a hierarchical database and tables in a relational database is that, in a hierarchical database, segments are implicitly joined with each other. In a relational database, you explicitly join two tables. A segment instance in a hierarchical database is already joined with its parent segment and its child segments, which are all along the same hierarchical path. In a relational database, this relationship between tables is captured by foreign and primary keys.

Figure 7-1 illustrates a hierarchical database and Figure 7-2 on page 69 illustrates the relational representation of the database shown in Figure 7-1.

Figure 7-1. Example of a Hierarchical Dealership Database


Figure 7-2. Relational Representation of the Dealership Database


The dealership sample database contains five segment types, which are shown in Figure 7-1. The root segment is the Dealer segment. Under the Dealer segment is its child segment, the Model segment. Under the Model segment are its children: the segments Order, Sales, and Stock.

The Dealer segment identifies a dealer selling cars, and the segment contains a dealer name and a unique dealer number in the fields DLRNAME and DLRNO.

Dealers carry car types, each of which has a corresponding Model segment. A Model segment contains a type code in the field MODTYPE.

There is an Order segment for each car that is ordered for the dealership. A Stock segment is created for each car that is available for sale in the dealer's inventory. When the car is sold, a Sales segment is created.

Figure 7-2 on page 69 shows a relational representation of the hierarchical dealership database record shown in Figure 7-1 on page 68.

If a segment does not have a unique key, which is similar to a primary key in relational databases, view the corresponding relational table as having a generated primary key added to its column (field) list. An example of a generated primary key is in the Model table (segment) in Figure 7-2. Similar to referential integrity in relational databases, you cannot insert a child segment (Order) into the database without it being a child of a specific parent segment (Model).

Also note that the field (column) names have been renamed. You can rename segments and fields to more meaningful names.

The hierarchical data structure in Figure 7-3 on page 71 describes the data as seen by the application program. It does not represent the physical storage of the data. The physical storage is of no concern to the application program.

Figure 7-3. Hierarchical Data Structure


The basic building element of a hierarchical data structure is the parent/child relationship between segments of data, illustrated in Figure 7-3.

Each occurrence (or instance) of a parent segment is associated with 0 or more occurrences of a child segment. Each child segment occurrence is associated with one, and only one, occurrence of a parent segment.

Sometimes it is necessary to distinguish between a segment type (the kind of segment) and the segment occurrence (the particular instance of its contents and location).

As shown in Figure 7-3, a parent can have several child segment types. Also, a child segment can, at the same time, be a parent segment; that is, it can have children below it. The segment with no parent segment (the one at the top) is called the root segment.

All the parent and child occurrences for a given root segment are grouped together in a database record. The collection of all of the database records with the same root and hierarchical structure (in Figure 7-3, each PART segment with its dependent STOCK, PURCHASE ORDER, and DETAIL segments) is an IMS database (the PART database).

For a given database record, only one segment can appear at the first level in the hierarchy, but multiple segments can appear at lower levels in the hierarchy. For example, multiple STOCK and PURCHASE ORDER segments can exist for one PART segment. Since each dependent segment in the hierarchy has only one parent, or immediate superior segment, the hierarchical data structure is sometimes called a tree structure. Each branch of the tree is called a hierarchical path. A hierarchical path to a segment contains all consecutive segments from the top of the structure down to that segment.

Through the concept of program sensitivity, IMS can restrict a program to "seeing" only those segments of information that are relevant to the processing being performed. For example, an inventory program could be written to see only the PART and STOCK segments of the database record shown in Figure 7-3. The program need not be aware of the existence of the PURCHASE ORDER segment.

IMS allows a wide variety of data structures. The maximum number of different segment types is 255 in a single database. A maximum of 15 segment levels can be defined in a hierarchical data structure. There is no restriction on the number of occurrences of each segment type, except as imposed by physical access method limits.



Introduction to IMS. Your Complete Guide to IBM's Information Management System
An Introduction to IMS: Your Complete Guide to IBMs Information Management System
ISBN: 0131856715
EAN: 2147483647
Year: 2003
Pages: 226

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net