Logical Databases

 
idms
 
What is a Logical Database
A
logical database
is a DBD definition that references structures already defined in one or more physical databases (physical DBDs). Such a definition is known as a
logical DBD
.
To an application, a logical DBD always appears as a single hierarchical physical DBD. However, a logical DBD is derived from the relationships (especially the logical relationships) defined in the associated physical DBDs.
Logical Databases Provide Flexibility
Logical databases provide flexibility for applications by allowing them to view the same physical data in many different ways. It is important to remember that each logical DBD is still hierarchical in nature for all of the DL/I calls that use it.
2
2
Defining a Logical Database
Specify LOGICAL for ACCESS Parameter
To define a logical DBD, you must specify LOGICAL for the ACCESS parameter in the DBD statement. The bulk of a logical DBD consists of SEGM statements that reference segments defined in one or more physical DBDs. (Segment fields can be defined only on the physical DBD level.)
SEGM Statement
The SEGM statement specifies a NAME for the segment and must contain a SOURCE clause to identify the segment as defined in a physical DBD. Similar to physical DBDs, the PARENT parameter specifies the parent segment within the logical structure. For example, the statement below declares that segment SEG7 is based on the segment of the same name in the PHYSDB2 physical DBD, and is a child of the LSEGB segment in this logical database:
Syntax
SEGM NAME=SEG7,SOURCE=((SEG7,PHYSDB2)),PARENT=LSEGB
Intersection and Concatenated Segments
Pointer and Target Segments
As mentioned above, logical databases are defined by referencing segments already defined in one or more physical DBDs. In particular, logical databases rely on the logical relationships defined in the physical DBDs. Logical relationships allow you to link a segment (logical child) in one physical DBD with a segment (logical parent) in another (or the same) physical DBD. In such a relationship, the logical child segment is referred to as the pointer segment, and the logical parent is referred to as the target segment.
Intersection and Concatenated Segments
In practice, the link between pointer and target segments is established via a pointer field in the pointer (logical child) segment. If the pointer segment contains data fields in addition to the pointer field, such fields are said to carry
intersection data
and the segment itself is referred to as an
intersection segment
. The intersection data is unique to the relationship between a pointer segment occurrence and its associated target segment occurrence. An application can retrieve and modify the data portions of the pointer and target segments separately, or it can retrieve and modify the pointer and target segments as one
concatenated segment
.
Defining a Concatenated Segment
The definition of individual pointer (logical child) and target (logical parent) segments occurs at the physical DBD level. The definition of concatenated segments occurs at the logical DBD level and is specified via the SOURCE parameter in the SEGM statement. The SOURCE parameter determines the contents of a concatenated segment, which can be:
  • The concatenated key of the destination parent, the pointer segment's intersection data, and the destination parent's data
  • The concatenated key of the destination parent and the pointer segment's intersection data
  • The destination parent's data only
The Destination Parent
The
destination parent
can be either the physical or logical parent of the pointer (logical child) segment. The choice depends on the direction in which you want the access to proceed: from logical parent to physical parent via the logical child, or from physical parent to logical parent via the logical child.
Syntax
The SOURCE parameter in the logical DBD SEGM statement takes the following form:
IDMSDB--Intersection and Concatenated Segments
Parameters
  • psegname
    Identifies the name of the pointer (logical child) segment as defined in the physical DBD
    dbname1
    . This segment can be either a virtual logical child or a real logical child. (See "Bidirectional Virtual Relationship" and "Bidirectional Physical Relationship" earlier in this section.)
  • KEY/DATA
    KEY/DATA
    specifies whether an application will have access to only the key (sequence field) of the named segment, or will have access to the segment's data portion as well as the key. KEY is the default.
  • dsegname
    Dsegname
    is the name of the destination parent as defined in the physical DBD
    dbname2
    . The destination parent can be either the physical or logical parent for the pointer (logical child) segment named in
    psegname
    .
Sample Logical Database
DBD Definition for a Logical Database
The sample below shows the DBD source statements for a logical database. The DBD definitions for the underlying physical databases are those shown in Figure 9. In the logical DBD shown below, LSEGB is the concatenated segment that combines the SEG6 and SEG1 segments from PHYSDB1 and PHYSDB2, respectively.
 DBD      NAME=LOGDB,ACCESS=LOGICAL  DATASET  LOGICAL  SEGM     NAME=LSEGA,SOURCE=((SEG5,PHYSDB2))  SEGM     NAME=LSEGB,PARENT=LSEGA,                SOURCE=((SEG6,DATA,PHYSDB2),(SEG1,DATA,PHYSDB1))  SEGM     NAME=SEG3,PARENT=(LSEGB,((SEG3,PHYSDB1)))  SEGM     NAME=SEG4,PARENT=LSEGB,SOURCE=((SEG4,PHYSDB1))  SEGM     NAME=SEG7,SOURCE=((SEG7,PHYSDB2)),PARENT=LSEGB  SEGM     NAME=SEG8,SOURCE=((SEG8,PHYSDB2)),PARENT=LSEGB  DBDGEN  FINISH  END
Logical Database Structure
The illustration below shows the logical database produced by the logical DBD definition in the source statements shown above. Compare the resulting logical structure with the hierarchical structures for the underlying physical databases.
IDMSDB--Sample Logical Database
Figure 17. Logical database structure