Logical Relationships Between Segments
Logical relationships provide a way of extending the basic hierarchical relationships.
What Logical Relationships Do
Logical relationshipsprovide a way of extending the basic hierarchical relationships. They have no effect on how segments are physically stored, but they do let you define multiple access paths to the same physical data. The segments defined in a logical relationship can be on the same hierarchical path or on different hierarchical paths.
Logical Parent and Logical Child
In a logical relationship, the parent segment is referred to as the
logical parent, and the child segment is referred to as the
In a given logical relationship, a child segment can have only one physical parent and only one logical parent. Note that a parent segment can be both physical and logical parent to the same child segment. Also, the same child segment can have more than one logical parent, but in different logical relationships.
If two or more logical child segment occurrences have the same logical parent occurrence, they are referred to as
logical twins. As with physical twins, they are twins only in the sense that they have the same parent occurrence.
Hierarchical (physical) relationships always occur within the same database. Logical relationships can occur within the same database or can involve segments from different databases.
DBD Source Statements for Two Databases
The example below shows sample DBD source statements for defining two databases (PHYSDB1 and PHYSDB2). Note that the DBD definitions define both hierarchical and logical relationships.
Each hierarchical relationship involves only segments that are in the same database. A logical relationship, though, can involve segments from its own database definition and segments from another database definition.
DBD NAME=PHYSDBD1,ACCESS=HDAM DATASET DD1=HDAM1,DEVICE=3350,BLOCK=2048,SCAN=3 SEGM NAME=SEG1,PTR=TWINBWD,RULES=LLV FIELD NAME=(FIELD1,SEQ,U),BYTES=60,START=1 FIELD NAME=FIELD2,BYTES=15,START=61 FIELD NAME=FIELD3,BYTES=75,START=76 LCHILD NAME=(SEG6,PHYSDB2),PAIR=SEG2,PTR=DBLE SEGM NAME=SEG2,PARENT=SEG1,PTR=PAIRED SOURCE=(SEG6,DATA,PHYSDB2) FIELD NAME=(FIELD4,SEQ,U),BYTES=21,START=1 FIELD NAME=FIELD5,BYTES=20,START=22 SEGM NAME=SEG3,BYTES=200,PARENT=SEG1 FIELD NAME=(FIELD6,SEQ,U),BYTES=99,START=1 FIELD NAME=FIELD7,BYTES=101,START=100 SEGM NAME=SEG4,BYTES=100,PARENT=SEG1 FIELD NAME=(FIELD8,SEQ,U),BYTES=15,START=1 FIELD NAME=FIELD9,BYTES=15,START=51 DBDGEN FINISH END DBD NAME=PHYSDBD2,ACCESS=HDAM, RMNAME=(DLZHDC20,7,700,250) DATASET DD1=HDAM2,DEVICE=3350,BLOCK=2048,SCAN=3 SEGM NAME=SEG5,BYTES=31,PTR=TWINBWD,RULES=(VLV) FIELD NAME=(FIELD9,SEQ,U),BYTES=21,START,TYPE=P FIELD NAME=FIELD10,BYTES=10,START=22 SEGM NAME=SEG6, PARENT=((SEG5,DBLE),(SEG1,P,PHYSDB1)), BYTES=80,PTR=(LPARNT,TWINBWD),RULES=VVV FIELD NAME=(FIELD11,SEQ,U),START=1,BYTES=60 FIELD NAME=FIELD12,BYTES=20,START=61 SEGM NAME=SEG7,BYTES=20,PTR=T, PARENT=(SEG6,SNGL) FIELD NAME=FIELD13,BYTES=9,START=1 FIELD NAME=FIELD14,BYTES=11,START=10 SEGM NAME=SEG8,BYTES=75,PTR=T, PARENT=(SEG6,SNGL) FIELD NAME=FIELD16,BYTES=50,START=1 FIELD NAME=FIELD17,BYTES=25,START=51 DBDGEN FINISH END
Figure 9. DBD source statements for two databases
Three Types of Logical Relationships
DL/I supports three types of logical relationships:
- Bidirectional virtual
- Bidirectional physical
Access Data in One Direction
In a unidirectional relationship, access can go in only one direction: from a logical child segment to its logical parent segment. A logical child segment cannot be accessed from its logical parent.
The illustration below illustrates the unidirectional logical structure. The structure shown involves segments from both of the physical hierarchies (PHYSDB1 and PHYSDB2) defined in earlier in this section. The logical child is SEG6 (in PHYSDB2), the physical parent is SEG5 (also in PHYSDB2), and the logical parent is SEG1 (in PHYSDB1).
Figure 10. Unidirectional structure
Defining a Unidirectional Structure
You define a unidirectional structure in the logical child's SEGM statement. The SEGM statement names the logical child segment and identifies both the physical parent and the logical parent.
The PARENT parameter on the logical child's SEGM statement takes the following form:
- ppsegnameIdentifies the name of a physical parent segment and must match a name specified for the NAME parameter in a preceding SEGM statement.
- lpsegnameIdentifies the name of a logical parent segment and must match the name specified for the NAME parameter on the logical parent's SEGM statement. Note that this SEGM statement can be in the same DBD or a different DBD (seeDbnamebelow).
Specifies whether the concatenated key of the logical parent is stored with the logical child (PHYSICAL) or is built at run time (VIRTUAL). For more details, see IPSB Compiler.
- dbnameDbnameis the name of the DBD that contains the logical parent's SEGM statement.
Bidirectional Virtual Relationship
Access Data in Two Directions
In a bidirectional virtual relationship, access can go in both directions: from a logical child segment to its logical parent segment, and from the logical parent segment to its logical child segment.
A bidirectional virtual relationship requires that you define a
virtual logical child segment, as well as a
real logical child segment. The virtual logical child is a pointer to the real logical child. (Compare to the bidirectional physical relationship, described below, in which the virtual logical child is a physical duplicate of the real logical child.)
Unidirectional relationships involve three segments; bidirectional relationships always involve four segments.
Bidirectional Virtual Structure
The example below shows the bidirectional virtual relationship defined by the DBD source statements shown in Figure 9 earlier in this section. In this relationship, SEG6 is the real logical child, SEG5 is the physical parent, SEG1 is the logical parent, and SEG2 is the virtual logical child. Note that SEG5 and SEG6 are in DBD PHYSDB2, and SEG1 and SEG2 are in DBD PHYSDB1.
Figure 12. Bidirectional virtual structure
Defining the Virtual Logical Child
The physical parent, the physical child, the logical parent, and the real logical child are defined the same as for a unidirectional relationship (see Unidirectional Relationship). You define the virtual logical child in two places:
- In the logical parent's LCHILD statement. This statement follows the logical parent's SEGM and FIELD statements. It supplies the name of the real logical child segment and identifies the DBD in which it is defined. It also supplies the name of the segment in the logical parent's DBD that is to serve as the virtual logical child.
- In the virtual logical child's SEGM statement. The virtual logical child must be defined in the same DBD as the logical parent.
SEGM Statement for the Virtual Logical Child
The virtual logical child's SEGM statement must include the SOURCE parameter, which sets up a pointer to the real logical child and takes the following form:
- segnameIdentifies the name of the real logical child segment, as specified for the NAME parameter in the real logical child's SEGM statement.
- dbnameDbnameis the name of the DBD that contains the real logical child's SEGM statement.
Bidirectional Physical Relationship
What is a Bidirectional Physical Relationship
Bidirectional physical relationships provide access in both directions between a logical parent segment and a logical child segment. In this respect, they are the same as bidirectional virtual relationships. The difference between the two types of relationships is that bidirectional physical employs a physical duplicate of the real logical child, while bidirectional virtual employs a pointer to the real logical child, with no duplication of data.
Using Physical or Logical Virtual Bidirectional Relationships
The decision to use one type of bidirectional relationship instead of another depends on whether you want to optimize performance or space usage. Bidirectional physical relationships provide faster access times, but incur more space overhead because of the duplicate logical child data. They also require more maintenance overhead since updates made to one logical child must be duplicated in the other. Bidirectional virtual relationships conserve on space, but provide slower access times.
Bidirectional Physical Structure
The illustration below shows the bidirectional physical relationship defined by the DBD source statements in Figure 7. In this relationship, SEG6 is a physical child for SEG5 and a logical child for SEG1, SEG4 is a physical child for SEG1 and a logical child for SEG5. Note that SEG6 and SEG5 are in DBD PHYSDB2, and SEG4 and SEG1 are in DBD PHYSDB1.
Figure 12. Bidirectional physical structure
Defining a Bidirectional Physical Relationship
To create a bidirectional physical relationship, you must define a child segment as both physical child and logical child for each parent, in each parent's physical hierarchy. In effect, you define the same unidirectional structure for each parent. The two logical child segments contain duplicate data and together are referred to as physically paired logical child segments. Note that the logical child SEGM statements cannot include the SOURCE parameter.