Creating logical relationships
Logical relationships resolve conflicts in the way application programs need to view segments in the database.
With logical relationships, application programs can access:
- Segment types in an order other than the one defined by the hierarchy
- A data structure that contains segments from more than one physical database.
An alternative to using logical relationships to resolve the different needs of applications is to create separate databases or carry duplicate data in a single database. However, in both cases this creates duplicate data. Avoid duplicate data because:
- Extra maintenance is required when duplicate data exists because both sets of data must be kept up to date. In addition, updates must be done simultaneously to maintain data consistency.
- Extra space is required on DASD to hold duplicate data.
By establishing a path between two segment types, logical relationships eliminate the need to store duplicate data.
To establish a logical relationship, three segment types are always defined:
- A physical parent
- A logical parent
- A logical child
The following database types support logical relationships:
- HISAM
- HDAM
- PHDAM
- HIDAM
- PHIDAM
Two databases, one for orders that a customer has placed and one for items that can be ordered, are called ORDER and ITEM. The ORDER database contains information about customers, orders, and delivery. The ITEM database contains information about inventory.
If an application program needs data from both databases, this can be done by defining a logical relationship between the two databases. As shown in the following figure, a path can be established between the ORDER and ITEM databases using a segment type, called a logical child segment, that points into the ITEM database. The following figure shows a simple implementation of a logical relationship. In this case, ORDER is the physical parent of ORDITEM. ORDITEM is the physical child of ORDER and the logical child of ITEM.
In a logical relationship, there is a logical parent segment type and it is the segment type pointed to by the logical child. In this example, ITEM is the logical parent of ORDITEM. ORDITEM establishes the path or connection between the two segment types. If an application program now enters the ORDER database, it can access data in the ITEM database by following the pointer in the logical child segment from the ORDER to the ITEM database.

The physical parent and logical parent are the two segment types between which the path is established. The logical child is the segment type that establishes the path. The path established by the logical child is created using pointers.