Ims Db 简明教程
IMS DB - Logical Database
IMS数据库有一条规则,即每个段类型只能有一个父段。这就限制了物理数据库的复杂性。许多DL/I应用程序需要一个复杂结构,它允许一个段具有两个父段类型。为了克服这一限制,DL/I允许DBA实现逻辑关系,其中一个段可以具有物理父段和逻辑父段。我们可以在一个物理数据库中创建其他关系。实现逻辑关系之后的新数据结构称为逻辑数据库。
IMS database has a rule that each segment type can have only one parent. This limits the complexity of the physical database. Many DL/I applications require a complex structure that allows a segment to have two parent segment types. To overcome this limitation, DL/I allows the DBA to implement logical relationships in which a segment can have both physical and logical parents. We can create additional relationships within one physical database. The new data structure after implementing the logical relationship is known as the Logical Database.
Logical Relationship
逻辑关系具有以下属性 −
A logical relationship has the following properties −
-
A logical relationship is a path between two segments which are related logically and not physically.
-
Usually a logical relationship is established between separate databases. But it is possible to have a relationship between the segments of one particular database.
下图显示了两个不同的数据库。一个是学生数据库,另一个是图书数据库。我们在学生数据库中的“已借阅书籍”段和图书数据库中的“书籍”段之间创建逻辑关系。
The following image shows two different databases. One is a Student database, and the other is a Library database. We create a logical relationship between the Books Issued segment from the Student database and the Books segment from the Library database.

创建逻辑关系后,逻辑数据库如下所示 −
This is how the logical database looks when you create a logical relationship −

Logical Child Segment
逻辑子段是逻辑关系的基础。它是一个物理数据段,但对于DL/I来说,它看起来好像有两个父段。上面示例中的“书籍”段有两个父段。“已借阅书籍”段是逻辑父段,而“图书”段是物理父段。一个逻辑子段实例只有一个逻辑父段实例,并且一个逻辑父段实例可以具有许多逻辑子段实例。
Logical child segment is the basis of a logical relationship. It is a physical data segment but for DL/I, it appears as if it has two parents. The Books segment in the above example has two parent segments. Issued books segment is the logical parent and Library segment is the physical parent. One logical child segment occurrence has only one logical parent segment occurrence and one logical parent segment occurrence can have many logical child segment occurrences.
Logical Twins
逻辑双胞胎是逻辑子段类型的所有实例,它们都从属于逻辑父段类型的一个实例。DL/I使逻辑子段看起来类似于一个实际的物理子段。这也称为虚拟逻辑子段。
Logical twins are the occurrences of a logical child segment type that are all subordinate to a single occurrence of the logical parent segment type. DL/I makes the logical child segment appear similar to an actual physical child segment. This is also known as a virtual logical child segment.
Types of Logical Relationships
DBA在段之间创建逻辑关系。为了实现逻辑关系,DBA必须在所涉及的物理数据库的DBDGEN中指定它。有三种类型的逻辑关系 −
A DBA creates logical relationships between segments. To implement a logical relationship, the DBA has to specify it in the DBDGENs for the involved physical databases. There are three types of logical relationships −
-
Unidirectional
-
Bidirectional Virtual
-
Bidirectional Physical
Unidirectional
逻辑连接从逻辑子段到逻辑父段,它不能反过来。
The logical connection goes from the logical child to the logical parent and it cannot go the other way around.
Programming Considerations
使用逻辑数据库的编程注意事项如下 −
The programming considerations for using a logical database are as follows −
-
DL/I calls to access the database remains same with the logical database too.
-
Program specification block indicates the structure which we use in our calls. In some cases, we cannot identify that we are using a logical database.
-
Logical relationships add a new dimension to database programming.
-
You must be careful while working with logical databases, as two databases are integrated together. If you modify one database, the same modifications must be reflected in the other database.
-
Program specifications should indicate what processing is allowed on a database. If a processing rule is violated, you get a non-blank status code.
Concatenated Segment
一个逻辑子段总是以目标父级的完整串联键开头。这被称为目标父级串联键 (DPCK)。对于逻辑子级的段 I/O 区域,你始终需要在开头编码 DPCK。在一个逻辑数据库中,串联段使得在不同物理数据库中定义的段之间形成连接。一个串联段包括以下两部分:
A logical child segment always begins with the complete concatenated key of the destination parent. This is known as the Destination Parent Concatenated Key (DPCK). You need to always code the DPCK at the start of your segment I/O area for a logical child. In a logical database, the concatenated segment makes the connection between segments that are defined in different physical databases. A concatenated segment consists of the following two parts −
-
Logical child segment
-
Destination parent segment
一个逻辑子级段包括以下两部分:
A logical child segment consists of the following two parts −
-
Destination Parent Concatenated Key (DPCK)
-
Logical child user data

在更新期间处理串联段时,有可能通过一个调用添加或修改逻辑子级和目标父级中的数据。这还取决于 DBA 为数据库指定的规则。对于一个插入,将 DPCK 放置在正确的位置。对于一个替换或删除,不要更改串联段的任何部分中的 DPCK 或序列字段数据。
When we work with concatenated segments during update, it may be possible to add or change the data in both the logical child and the destination parent with a single call. This also depends on the rules the DBA specified for the database. For an insert, provide the DPCK in the right position. For a replace or delete, do not change the DPCK or the sequence field data in either part of the concatenated segment.