Processing segments in logical relationships

Sometimes an application program needs to process a hierarchy that is made up of segments that already exist in two or more separate database hierarchies. Logical relationships make it possible to establish hierarchic relationships between these segments. When you use logical relationships, the result is a new hierarchy—one that does not exist in physical storage but that can be processed by application programs as though it does exist. This type of hierarchy is called a logical structure.

One advantage of using logical relationships is that programs can access the data as though it exists in more than one hierarchy, even though it is only stored in one place. When two application programs need to access the same segment through different paths, an alternative to using logical relationships is to store the segment in both hierarchies. The problem with this approach is that you must update the data in two places to keep it current.

Processing segments in logical relationships is not very different from processing other segments. The following examples are taken from a scenario for an inventory application program that processes data in a purchasing database, but which also needs access to a segment in a patient database.

For example, the hierarchy that an inventory application program needs to process contains four segment types:

The TREATMNT segment in the medical database contains the same information that the inventory application program needs to process in the DISBURSE segment. Rather than store this information in both hierarchies, you can store the information in the TREATMNT segment, and define a logical relationship between the DISBURSE segment in the item hierarchy and the TREATMNT segment in the patient hierarchy. Doing this makes it possible to process the TREATMNT segment through the item hierarchy as though it is a child of SHIPMENT. DISBURSE then has two parents: SHIPMENT is DISBURSE's physical parent, and TREATMNT is DISBURSE's logical parent.

Three segments are involved in this logical relationship: DISBURSE, SHIPMENT, and TREATMNT. The following figure shows the item hierarchy on the right. The DISBURSE segment points to the TREATMNT segment in the patient hierarchy shown on the left. (The patient hierarchy is part of the medical database.)

Figure 1. Patient and item hierarchies
begin figure description - This figure is described in the surrounding text. end figure description.

Three types of segments are found in a logical relationship:

Because a logical child segment points to its logical parent, two paths exist through which a program can access the logical parent segment:

When a logical parent segment is accessed through the logical child, the logical child is concatenated with both the data from its logical parent segment and any data the user has chosen to associate with this pairing (intersection data) in a single segment I/O area, like this:

Figure 2. Concatenated segment
begin figure description - This figure is described in the surrounding text. end figure description.

LL is the length field of the logical parent if this segment is a variable-length segment.