Ims Db 简明教程
IMS DB - Overview
A Brief Overview
数据库是关联数据项的集合。这些数据项以提供快速且轻松访问的方式进行组织和存储。IMS 数据库是分层数据库,数据存储在不同级别,每个实体都依赖于更高级别的实体。使用 IMS 的应用程序系统上的物理元素如下图所示。
Database is a collection of correlated data items. These data items are organized and stored in a manner to provide fast and easy access. IMS database is a hierarchical database where data is stored at different levels and each entity is dependent on higher level entities. The physical elements on an application system that use IMS are shown in the following figure.
Database Management
数据库管理系统是一组应用程序,用于存储、访问和管理数据库中的数据。IMS 数据库管理系统通过以易于检索的方式组织数据来维护完整性,并允许快速恢复数据。IMS 通过其数据库管理系统的帮助维护大量世界公司数据。
A Database Management system is a set of application programs used for storing, accessing, and managing data in the database. IMS database management system maintains integrity and allows fast recovery of data by organizing it in such a way that it is easy to retrieve. IMS maintains a large amount of world’s corporate data with the help of its database management system.
Transaction Manager
事务管理器的功能是提供数据库和应用程序之间的通信平台。IMS 充当事务管理器。事务管理器与最终用户打交道,以从数据库存储和检索数据。IMS 可以使用 IMS DB 或 DB2 作为后端数据库来存储数据。
The function of transaction manager is to provide a communication platform between the database and the application programs. IMS acts as a transaction manager. A transaction manager deals with the end-user to store and retrieve data from the database. IMS can use IMS DB or DB2 as its back-end database to store the data.
DL/I – Data Language Interface
DL/I 包含允许访问存储在数据库中的数据的应用程序。IMS DB 使用 DL/I,DL/I 作为程序员在应用程序中访问数据库时使用的接口语言。我们将在接下来的章节中更详细地讨论这一点。
DL/I comprises of application programs that grant access to the data stored in the database. IMS DB uses DL/I which serves as the interface language that programmers use for accessing the database in an application program. We will discuss this in more detail in the upcoming chapters.
IMS DB - Structure
Hierarchical Structure
IMS 数据库是容纳物理文件的数据集合。在分层数据库中,最顶层包含有关实体的一般信息。随着我们在层次结构中从顶层往下移动,我们会获得更多有关实体的信息。
An IMS database is a collection of data accommodating physical files. In a hierarchical database, the topmost level contains the general information about the entity. As we proceed from the top level to the bottom levels in the hierarchy, we get more and more information about the entity.
层次结构中的每一层都包含段。在标准文件中,难以实现层次结构,但 DL/I 支持层次结构。下图描绘了 IMS DB 的结构。
Each level in the hierarchy contains segments. In standard files, it is difficult to implement hierarchies but DL/I supports hierarchies. The following figure depicts the structure of IMS DB.
Segment
重点注意事项:
Points to note −
-
A segment is created by grouping of similar data together.
-
It is the smallest unit of information that DL/I transfers to and from an application program during any input-output operation.
-
A segment can have one or more data fields grouped together.
在以下示例中,段 Student 有四个数据字段。
In the following example, the segment Student has four data fields.
Student |
Roll Number |
Name |
Course |
Mobile NUmber |
Field
注意事项:
Points to note−
-
A field is a single piece of data in a segment. For example, Roll Number, Name, Course, and Mobile Number are single fields in the Student segment.
-
A segment consists of related fields to collect the information of an entity.
-
Fields can be used as a key for ordering the segments.
-
Fields can be used as a qualifier for searching information about a particular segment.
Segment Type
重点注意事项:
Points to note −
-
Segment Type is a category of data in a segment.
-
A DL/I database can have 255 different segment types and 15 levels of hierarchy.
-
In the following figure, there are three segments namely, Library, Books Information, and Student Information.
Segment Occurrence
重点注意事项:
Points to note −
-
A segment occurrence is an individual segment of a particular type containing user data. In the above example, Books Information is one segment type and there can any number of occurrences of it, as it can store the information about any number of books.
-
Within the IMS Database, there is only one occurrence of each segment type, but there can be an unlimited number of occurrences of each segment type.
IMS DB - DL/I Terminology
层次数据库在两个或更多段之间建立关联。以下示例演示了各个段在 IMS 数据库结构中的关联方式。
Hierarchical databases work on the relationships between two or more segments. The following example shows how segments are related to each other in the IMS database structure.
Root Segment
重点注意事项:
Points to note −
-
The segment that lies at the top of the hierarchy is called the root segment.
-
The root segment is the only segment through which all dependent segments are accessed.
-
The root segment is the only segment in the database which is never a child segment.
-
There can be only one root segment in the IMS database structure.
-
For example, 'A' is the root segment in the above example.
Parent Segment
重点注意事项:
Points to note −
-
A parent segment has one or more dependent segments directly below it.
-
For example, 'A', 'B', and 'E' are the parent segments in the above example.
Dependent Segment
重点注意事项:
Points to note −
-
All segments other than the root segment are known as dependent segments.
-
Dependent segments depend on one or more segments to present complete meaning.
-
For example, 'B', 'C1', 'C2', 'D', 'E', 'F1' and 'F2' are dependent segments in our example.
Child Segment
重点注意事项:
Points to note −
-
Any segment having a segment directly above it in the hierarchy is known as a child segment.
-
Each dependent segment in the structure is a child segment.
-
For example, 'B', 'C1', 'C2', 'D', 'E', 'F1' and 'F2' are child segments.
Twin Segments
重点注意事项:
Points to note −
-
Two or more segment occurrences of a particular segment type under a single parent segment are called twin segments.
-
For example, 'C1' and 'C2' are twin segments, so do 'F1' and 'F2' are.
Sibling Segment
重点注意事项:
Points to note −
-
Sibling segments are the segments of different types and the same parent.
-
For example, 'B' and 'E' are sibling segments. Similarly, 'C1', 'C2', and 'D' are sibling segments.
Database Record
重点注意事项:
Points to note −
-
Each occurrence of the root segment, plus all the subordinate segment occurrences make one database record.
-
Every database record has only one root segment but it may have any number of segment occurrences.
-
In standard file processing, a record is a unit of data that an application program uses for certain operations. In DL/I, that unit of data is known as a segment. A single database record has many segment occurrences.
Database Path
重点注意事项:
Points to note −
-
A path is the series of segments that starts from the root segment of a database record to any specific segment occurrence.
-
A path in the hierarchy structure need not be complete to the lowest level. It depends on how much information we require about an entity.
-
A path must be continuous and we cannot skip intermediate levels in the structure.
-
In the following figure, the child records in dark grey color show a path which starts from 'A' and goes through 'C2'.
IMS DB - DL/I Processing
IMS DB 在不同级别存储数据。通过从应用程序发出 DL/I 调用来检索和插入数据。我们将在即将到来的章节中详细讨论 DL/I 调用。可以用以下两种方式处理数据:
IMS DB stores data at different levels. Data is retrieved and inserted by issuing DL/I calls from an application program. We will discuss about DL/I calls in detail in the upcoming chapters. Data can be processed in the following two ways −
-
Sequential Processing
-
Random Processing
Sequential Processing
当从数据库中按顺序检索段时,DL/I 遵循一个预定义模式。让我们了解一下 IMS DB 的顺序处理。
When segments are retrieved sequentially from the database, DL/I follows a predefined pattern. Let us understand the sequential processing of IMS DB.
以下是有关顺序处理的要点:
Listed below are the points to note about sequential processing −
-
Predefined pattern for accessing data in DL/I is first down the hierarchy, then left to right.
-
The root segment is retrieved first, then DL/I moves to the first left child and it goes down till the lowest level. At the lowest level, it retrieves all the occurrences of twin segments. Then it goes to the right segment.
-
To understand better, observe the arrows in the above figure that show the flow for accessing the segments. Library is the root segment and the flow starts from there and goes till cars to access a single record. The same process is repeated for all occurrences to get all the data records.
-
While accessing data, the program uses the position in the database which helps to retrieve and insert segments.
Random Processing
随机处理也被称为 IMS DB 中数据的直接处理。让我们举一个例子来了解 IMS DB 中的随机处理:
Random processing is also known as direct processing of data in IMS DB. Let us take an example to understand random processing in IMS DB −
以下是有关随机处理的要点:
Listed below are the points to note about random processing −
-
Segment occurrence that needs to be retrieved randomly requires key fields of all the segments it depends upon. These key fields are supplied by the application program.
-
A concatenated key completely identifies the path from the root segment to the segment which you want to retrieve.
-
Suppose you want to retrieve an occurrence of the Commerce segment, then you need to supply the concatenated key field values of the segments it depends upon, such as Library, Books, and Commerce.
-
Random processing is faster than sequential processing. In real-world scenario, the applications combine both sequential and random processing methods together to achieve best results.
Key Field
重点注意事项:
Points to note −
-
A key field is also known as a sequence field.
-
A key field is present within a segment and it is used to retrieve the segment occurrence.
-
A key field manages the segment occurrence in ascending order.
-
In each segment, only a single field can be used as a key field or sequence field.
Search Field
如前所述,只有一个字段可以用作关键字段。如果您想要搜索非关键字段的其他段字段的内容,则用于检索数据字段被称为搜索字段。
As mentioned, only a single field can be used as a key field. If you want to search for the contents of other segment fields which are not key fields, then the field which is used to retrieve the data is known as a search field.
IMS DB - Control Blocks
IMS 控制块定义 IMS 数据库的结构和程序对它们的访问权限。下图显示了 IMS 控制块的结构。
IMS Control Blocks define the structure of the IMS database and a program’s access to them. The following diagram shows the structure of IMS control blocks.
DL/I 使用以下三种类型的控制块 −
DL/I uses the following three types of Control Blocks −
-
Database Descriptor (DBD)
-
Program Specification Block (PSB)
-
Access Control Block (ACB)
Database Descriptor (DBD)
重点注意事项:
Points to note −
-
DBD describes the complete physical structure of the database once all the segments have been defined.
-
While installing a DL/I database, one DBD must be created as it is required to access the IMS database.
-
Applications can use different views of the DBD. They are called Application Data Structures and they are specified in the Program Specification Block.
-
The Database Administrator creates a DBD by coding DBDGEN control statements.
DBDGEN
DBDGEN 是数据库描述符生成器。创建控制块是数据库管理员的责任。所有负载模块都存储在 IMS 库中。汇编语言宏语句用于创建控制块。下面提供了一个示例代码,演示如何使用 DBDGEN 控制语句创建 DBD −
DBDGEN is a Database Descriptor Generator. Creating control blocks is the responsibility of the Database Administrator. All the load modules are stored in the IMS library. Assembly Language macro statements are used to create control blocks. Given below is a sample code that shows how to create a DBD using DBDGEN control statements −
PRINT NOGEN
DBD NAME=LIBRARY,ACCESS=HIDAM
DATASET DD1=LIB,DEVICE=3380
SEGM NAME=LIBSEG,PARENT=0,BYTES=10
FIELD NAME=(LIBRARY,SEQ,U),BYTES=10,START=1,TYPE=C
SEGM NAME=BOOKSEG,PARENT=LIBSEG,BYTES=5
FIELD NAME=(BOOKS,SEQ,U),BYTES=10,START=1,TYPE=C
SEGM NAME=MAGSEG,PARENT=LIBSEG,BYTES=9
FIELD NAME=(MAGZINES,SEQ),BYTES=8,START=1,TYPE=C
DBDGEN
FINISH
END
让我们了解上述 DBDGEN 中使用的术语 −
Let us understand the terms used in the above DBDGEN −
-
When you execute the above control statements in JCL, it creates a physical structure where LIBRARY is the root segment, and BOOKS and MAGZINES are its child segments.
-
The first DBD macro statement identifies the database. Here, we need to mention the NAME and ACCESS which is used by DL/I to access this database.
-
The second DATASET macro statement identifies the file that contains the database.
-
The segment types are defined using the SEGM macro statement. We need to specify the PARENT of that segment. If it is a Root segment, then mention PARENT=0.
下表显示了 FIELD 宏语句中使用的参数 −
The following table shows parameters used in FIELD macro statement −
S.No |
Parameter & Description |
1 |
Name Name of the field, typically 1 to 8 characters long |
2 |
Bytes Length of the field |
3 |
Start Position of field within segment |
4 |
Type Data type of the field |
5 |
Type C Character data type |
6 |
Type P Packed decimal data type |
7 |
Type Z Zoned decimal data type |
8 |
Type X Hexadecimal data type |
9 |
Type H Half word binary data type |
10 |
Type F Full word binary data type |
Program Specification Block (PSB)
PSB 的基础知识如下所述 −
The fundamentals of PSB are as given below −
-
A database has a single physical structure defined by a DBD but the application programs that process it can have different views of the database. These views are called application data structure and are defined in the PSB.
-
No program can use more than one PSB in a single execution.
-
Application programs have their own PSB and it is common for application programs that have similar database processing requirements to share a PSB.
-
PSB consists of one or more control blocks called Program Communication Blocks (PCBs). The PSB contains one PCB for each DL/I database the application program will access. We will discuss more about PCBs in the upcoming modules.
-
PSBGEN must be performed to create a PSB for the program.
PSBGEN
PSBGEN 被称为程序规范块生成器。以下示例使用 PSBGEN 创建 PSB −
PSBGEN is known as Program Specification Block Generator. The following example creates a PSB using PSBGEN −
PRINT NOGEN
PCB TYPE=DB,DBDNAME=LIBRARY,KEYLEN=10,PROCOPT=LS
SENSEG NAME=LIBSEG
SENSEG NAME=BOOKSEG,PARENT=LIBSEG
SENSEG NAME=MAGSEG,PARENT=LIBSEG
PSBGEN PSBNAME=LIBPSB,LANG=COBOL
END
让我们了解上述 DBDGEN 中使用的术语 −
Let us understand the terms used in the above DBDGEN −
-
The first macro statement is the Program Communication Block (PCB) that describes the database Type, Name, Key-Length, and Processing Option.
-
DBDNAME parameter on the PCB macro specifies the name of the DBD. KEYLEN specifies the length of the longest concatenated key. The program can process in the database. PROCOPT parameter specifies the program’s processing options. For example, LS means only LOAD Operations.
-
SENSEG is known as Segment Level Sensitivity. It defines the program’s access to parts of the database and it is identified at the segment level. The program has access to all the fields within the segments to which it is sensitive. A program can also have field-level sensitivity. In this, we define a segment name and the parent name of the segment.
-
The last macro statement is PCBGEN. PSBGEN is the last statement telling there are no more statements to process. PSBNAME defines the name given to the output PSB module. The LANG parameter specifies the language in which the application program is written, e.g., COBOL.
Access Control Block (ACB)
以下是关于访问控制块需要注意的要点 −
Listed below are the points to note about access control blocks −
-
Access Control Blocks for an application program combines the Database Descriptor and the Program Specification Block into an executable form.
-
ACBGEN is known as Access Control Blocks Generator. It is used to generate ACBs.
-
For online programs, we need to pre-build ACBs. Hence the ACBGEN utility is executed before executing the application program.
-
For batch programs, ACBs can be generated at execution time too.
IMS DB - Programming
包含 DL/I 调用的应用程序不能直接执行。相反,需要一个 JCL 来触发 IMS DL/I 批处理模块。IMS 中的批处理初始化模块是 DFSRRC00。应用程序和 DL/I 模块一起执行。下图显示了包含 DL/I 调用以访问数据库的应用程序的结构。
An application program which includes DL/I calls cannot execute directly. Instead, a JCL is required to trigger the IMS DL/I batch module. The batch initialization module in IMS is DFSRRC00. The application program and the DL/I module execute together. The following diagram shows the structure of an application program which includes DL/I calls to access a database.
应用程序通过以下程序元素与 IMS DL/I 模块进行接口 −
The application program interfaces with IMS DL/I modules via the following program elements −
-
An ENTRY statement specifies that the PCBs are utilized by the program.
-
A PCB-mask co-relates with the information preserved in the pre-constructed PCB which receives return information from the IMS.
-
An Input-Output Area is used for passing data segments to and from the IMS database.
-
Calls to DL/I specify the processing functions such as fetch, insert, delete, replace, etc.
-
Check Status Codes is used to check the SQL return code of the processing option specified to inform whether the operation was successful or not.
-
A Terminate statement is used to end the processing of the application program which includes the DL/I.
Segments Layout
到目前为止,我们了解到 IMS 由在高级编程语言中用于访问数据的段组成。考虑一下我们之前见过的图书馆的以下 IMS 数据库结构,这里我们将在 COBOL 中看到其段的布局 −
As of now, we learnt that the IMS consists of segments which are used in high-level programming languages to access data. Consider the following IMS database structure of a Library which we have seen earlier and here we see the layout of its segments in COBOL −
01 LIBRARY-SEGMENT.
05 BOOK-ID PIC X(5).
05 ISSUE-DATE PIC X(10).
05 RETURN-DATE PIC X(10).
05 STUDENT-ID PIC A(25).
01 BOOK-SEGMENT.
05 BOOK-ID PIC X(5).
05 BOOK-NAME PIC A(30).
05 AUTHOR PIC A(25).
01 STUDENT-SEGMENT.
05 STUDENT-ID PIC X(5).
05 STUDENT-NAME PIC A(25).
05 DIVISION PIC X(10).
Application Program Overview
IMS 应用程序的结构不同于非 IMS 应用程序的结构。IMS 程序不能直接执行,但是它总是作为子程序被调用。IMS 应用程序包含程序规范块,以便查看 IMS 数据库。
The structure of an IMS application program is different from that of a Non-IMS application program. An IMS program cannot be executed directly; rather it is always called as a subroutine. An IMS application program consists of Program Specification Blocks to provide a view of the IMS database.
当我们执行包含 IMS DL/I 模块的应用程序时,将装入该程序相关的应用程序和 PSB。然后,IMS 模块将执行由应用程序触发的 CALL 请求。
The application program and the PSBs linked to that program are loaded when we execute an application program which includes IMS DL/I modules. Then the CALL requests triggered by the application programs are executed by the IMS module.
IMS DB - Cobol Basics
我们在 COBOL 应用程序中包括 DL/I 调用以与 IMS 数据库通信。我们在 COBOL 程序中使用以下 DL/I 语句来访问数据库 −
We include DL/I calls inside COBOL application program to communicate with IMS database. We use the following DL/I statements in COBOL program to access the database −
-
Entry Statement
-
Goback Statement
-
Call Statement
Entry Statement
它用于将控制从 DL/I 传递到 COBOL 程序。以下是输入语句的语法 −
It is used to pass the control from the DL/I to the COBOL program. Here is the syntax of the entry statement −
ENTRY 'DLITCBL' USING pcb-name1
[pcb-name2]
上述语句是在 COBOL 程序的 Procedure Division 中编码的。让我们详细了解一下 COBOL 程序中的 Entry 语句——
The above statement is coded in the Procedure Division of a COBOL program. Let us go into the details of the entry statement in COBOL program −
-
The batch initialization module triggers the application program and is executed under its control.
-
The DL/I loads the required control blocks and modules and the application program, and control is given to the application program.
-
DLITCBL stands for DL/I to COBOL. The entry statement is used to define the entry point in the program.
-
When we call a sub-program in COBOL, its address is also provided. Likewise, when the DL/I gives the control to the application program, it also provides the address of each PCB defined in the program’s PSB.
-
All the PCBs used in the application program must be defined inside the Linkage Section of the COBOL program because PCB resides outside the application program.
-
The PCB definition inside the Linkage Section is called as PCB Mask.
-
The relation between PCB masks and actual PCBs in storage is created by listing the PCBs in the entry statement. The sequence of listing in the entry statement should be same as they appear in the PSBGEN.
Goback Statement
用于将控制传递回 IMS 控制程序。以下是 Goback 语句的语法 −
It is used to pass the control back to the IMS control program. Following is the syntax of the Goback statement −
GOBACK
以下是关于 Goback 语句的基本注意事项 −
Listed below are the fundamental points to note about the Goback statement −
-
GOBACK is coded at the end of the application program. It returns the control to DL/I from the program.
-
We should not use STOP RUN as it returns the control to the operating system. If we use STOP RUN, the DL/I never gets a chance to perform its terminating functions. That is why, in DL/I application programs, Goback statement is used.
-
Before issuing a Goback statement, all the non-DL/I datasets used in the COBOL application program must be closed, otherwise the program will terminate abnormally.
Call Statement
Call 语句用于请求 DL/I 服务,例如对 IMS 数据库执行某些操作。以下是 call 语句的语法 −
Call statement is used to request for DL/I services such as executing certain operations on the IMS database. Here is the syntax of the call statement −
CALL 'CBLTDLI' USING DLI Function Code
PCB Mask
Segment I/O Area
[Segment Search Arguments]
上面的语法显示了您可以与 call 语句一起使用的参数。我们将在下表中讨论每一个参数 −
The syntax above shows parameters which you can use with the call statement. We will discuss each of them in the following table −
S.No. |
Parameter & Description |
1 |
DLI Function Code Identifies the DL/I function to be performed. This argument is the name of the four character fields that describe the I/O operation. |
2 |
PCB Mask The PCB definition inside the Linkage Section is called as PCB Mask. They are used in the entry statement. No SELECT, ASSIGN, OPEN, or CLOSE statements are required. |
3 |
Segment I/O Area Name of an input/output work area. This is an area of the application program into which the DL/I puts a requested segment. |
4 |
Segment Search Arguments These are optional parameters depending on the type of the call issued. They are used to search data segments inside the IMS database. |
以下是关于 Call 语句的注意事项 −
Given below are the points to note about the Call statement −
-
CBLTDLI stands for COBOL to DL/I. It is the name of an interface module that is link edited with your program’s object module.
-
After each DL/I call, the DLI stores a status code in the PCB. The program can use this code to determine whether the call succeeded or failed.
Example
有关 COBOL 的更多信息,您可以参阅我们的 COBOL 教程 here 。以下示例显示了使用 IMS 数据库和 DL/I 调用的 COBOL 程序的结构。我们将在接下来的章节中详细讨论示例中使用的每个参数。
For more understanding of COBOL, you can go through our COBOL tutorial here. The following example shows the structure of a COBOL program that uses IMS database and DL/I calls. We will discuss in detail each of the parameters used in the example in the upcoming chapters.
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 DLI-FUNCTIONS.
05 DLI-GU PIC X(4) VALUE 'GU '.
05 DLI-GHU PIC X(4) VALUE 'GHU '.
05 DLI-GN PIC X(4) VALUE 'GN '.
05 DLI-GHN PIC X(4) VALUE 'GHN '.
05 DLI-GNP PIC X(4) VALUE 'GNP '.
05 DLI-GHNP PIC X(4) VALUE 'GHNP'.
05 DLI-ISRT PIC X(4) VALUE 'ISRT'.
05 DLI-DLET PIC X(4) VALUE 'DLET'.
05 DLI-REPL PIC X(4) VALUE 'REPL'.
05 DLI-CHKP PIC X(4) VALUE 'CHKP'.
05 DLI-XRST PIC X(4) VALUE 'XRST'.
05 DLI-PCB PIC X(4) VALUE 'PCB '.
01 SEGMENT-I-O-AREA PIC X(150).
LINKAGE SECTION.
01 STUDENT-PCB-MASK.
05 STD-DBD-NAME PIC X(8).
05 STD-SEGMENT-LEVEL PIC XX.
05 STD-STATUS-CODE PIC XX.
05 STD-PROC-OPTIONS PIC X(4).
05 FILLER PIC S9(5) COMP.
05 STD-SEGMENT-NAME PIC X(8).
05 STD-KEY-LENGTH PIC S9(5) COMP.
05 STD-NUMB-SENS-SEGS PIC S9(5) COMP.
05 STD-KEY PIC X(11).
PROCEDURE DIVISION.
ENTRY 'DLITCBL' USING STUDENT-PCB-MASK.
A000-READ-PARA.
110-GET-INVENTORY-SEGMENT.
CALL ‘CBLTDLI’ USING DLI-GN
STUDENT-PCB-MASK
SEGMENT-I-O-AREA.
GOBACK.
IMS DB - DL/I Functions
DL/I 函数是 DL/I 调用中使用的第一个参数。此函数指示 IMS DL/I 调用将在 IMS 数据库上执行哪个操作。DL/I 函数的语法如下 -
DL/I function is the first parameter that is used in a DL/I call. This function tells which operation is going to be performed on the IMS database by the IMS DL/I call. The syntax of DL/I function is as follows −
01 DLI-FUNCTIONS.
05 DLI-GU PIC X(4) VALUE 'GU '.
05 DLI-GHU PIC X(4) VALUE 'GHU '.
05 DLI-GN PIC X(4) VALUE 'GN '.
05 DLI-GHN PIC X(4) VALUE 'GHN '.
05 DLI-GNP PIC X(4) VALUE 'GNP '.
05 DLI-GHNP PIC X(4) VALUE 'GHNP'.
05 DLI-ISRT PIC X(4) VALUE 'ISRT'.
05 DLI-DLET PIC X(4) VALUE 'DLET'.
05 DLI-REPL PIC X(4) VALUE 'REPL'.
05 DLI-CHKP PIC X(4) VALUE 'CHKP'.
05 DLI-XRST PIC X(4) VALUE 'XRST'.
05 DLI-PCB PIC X(4) VALUE 'PCB '.
此语法表示以下要点 -
This syntax represents the following key points −
-
For this parameter, we can provide any four-character name as a storage field to store the function code.
-
DL/I function parameter is coded in the working storage section of the COBOL program.
-
For specifying the DL/I function, the programmer needs to code one of the 05 level data names such as DLI-GU in a DL/I call, since COBOL does not allow to code literals on a CALL statement.
-
DL/I functions are divided into three categories: Get, Update, and Other functions. Let us discuss each of them in detail.
Get Functions
获取功能类似于任何编程语言所支持的读取操作。获取功能用于从 IMS DL/I 数据库提取段。以下获取功能用于 IMS DB 中 −
Get functions are similar to the read operation supported by any programming language. Get function is used to fetch segments from an IMS DL/I database. The following Get functions are used in IMS DB −
-
Get Unique
-
Get Next
-
Get Next within Parent
-
Get Hold Unique
-
Get Hold Next
-
Get Hold Next within Parent
让我们考虑以下 IMS 数据库结构以了解 DL/I 函数调用 −
Let us consider the following IMS database structure to understand the DL/I function calls −
Get Unique
“GU”代码用于唯一获取功能。它类似于 COBOL 中的随机读取语句。它用于基于字段值获取特定段出现。可以使用段搜索参数提供字段值。GU 调用的语法如下 −
'GU' code is used for the Get Unique function. It works similar to the random read statement in COBOL. It is used to fetch a particular segment occurrence based on the field values. The field values can be provided using segment search arguments. The syntax of a GU call is as follows −
CALL 'CBLTDLI' USING DLI-GU
PCB Mask
Segment I/O Area
[Segment Search Arguments]
如果你通过在 COBOL 程序中为所有参数提供适当的值来执行上述调用语句,你便可以在数据库中的段 I/O 区域中检索该段。在上述示例中,如果你提供图书馆、杂志和健康这三个字段值,那么你便可以获取健康段的所需出现。
If you execute the above call statement by providing appropriate values for all parameters in the COBOL program, you can retrieve the segment in the segment I/O area from the database. In the above example, if you provide the field values of Library, Magazines, and Health, then you get the desired occurrence of the Health segment.
Get Next
“GN”代码用于获取下一个功能。它类似于 COBOL 中的读取下一个语句。它用于按顺序获取段出现。访问数据段出现的预定义模式是从层次结构往下,然后从左到右。GN 调用的语法如下 −
'GN' code is used for the Get Next function. It works similar to the read next statement in COBOL. It is used to fetch segment occurrences in a sequence. The predefined pattern for accessing data segment occurrences is down the hierarchy, then left to right. The syntax of a GN call is as follows −
CALL 'CBLTDLI' USING DLI-GN
PCB Mask
Segment I/O Area
[Segment Search Arguments]
如果你通过在 COBOL 程序中为所有参数提供适当的值来执行上述调用语句,你便可以在数据库中按顺序在段 I/O 区域中检索段出现。在上述示例中,它首先访问图书馆段,然后访问书籍段,以此类推。我们又一次又一次地执行 GN 调用,直到达到我们想要的段出现。
If you execute the above call statement by providing appropriate values for all parameters in the COBOL program, you can retrieve the segment occurrence in the segment I/O area from the database in a sequential order. In the above example, it starts with accessing the Library segment, then Books segment, and so on. We perform the GN call again and again, until we reach the segment occurrence we want.
Get Next within Parent
“GNP”代码用于在父级内获取下一个。该函数用于按顺序检索建立父级段的从属段出现。GNP 调用的语法如下 −
'GNP' code is used for Get Next within Parent. This function is used to retrieve segment occurrences in sequence subordinate to an established parent segment. The syntax of a GNP call is as follows −
CALL 'CBLTDLI' USING DLI-GNP
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Get Hold Unique
“GHU”代码用于唯一保持获取。保持功能指定我们在检索后将更新该段。唯一保持获取功能对应于唯一获取调用。以下是 GHU 调用的语法 −
'GHU' code is used for Get Hold Unique. Hold function specifies that we are going to update the segment after retrieval. The Get Hold Unique function corresponds to the Get Unique call. Given below is the syntax of a GHU call −
CALL 'CBLTDLI' USING DLI-GHU
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Get Hold Next
“GHN”代码用于保持获取下一个。保持功能指定我们在检索后将更新该段。保持获取下一个功能对应于获取下一个调用。以下是 GHN 调用的语法 −
'GHN' code is used for Get Hold Next. Hold function specifies that we are going to update the segment after retrieval. The Get Hold Next function corresponds to the Get Next call. Given below is the syntax of a GHN call −
CALL 'CBLTDLI' USING DLI-GHN
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Get Hold Next within Parent
“GHNP”代码用于在父级内保持获取下一个。保持功能指定我们在检索后将更新该段。在父级内保持获取下一个功能对应于在父级内获取下一个调用。以下是 GHNP 调用的语法 −
'GHNP' code is used for Get Hold Next within Parent. Hold function specifies that we are going to update the segment after retrieval. The Get Hold Next within Parent function corresponds to the Get Next within Parent call. Given below is the syntax of a GHNP call −
CALL 'CBLTDLI' USING DLI-GHNP
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Update Functions
更新函数类似于其他任何编程语言中的重写或插入操作。更新函数用于更新 IMS DL/I 数据库中的段。在使用更新功能之前,必须使用保持子句成功调用段出现。以下更新函数用于 IMS DB −
Update functions are similar to re-write or insert operations in any other programming language. Update functions are used to update segments in an IMS DL/I database. Before using the update function, there must be a successful call with Hold clause for the segment occurrence. The following Update functions are used in IMS DB −
-
Insert
-
Delete
-
Replace
Insert
“ISRT”代码用于插入功能。ISRT 函数用于向数据库添加一个新段。它用于更改现有数据库或加载新数据库。以下是 ISRT 调用的语法 −
'ISRT' code is used for the Insert function. The ISRT function is used to add a new segment to the database. It is used to change an existing database or load a new database. Given below is the syntax of an ISRT call −
CALL 'CBLTDLI' USING DLI-ISRT
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Delete
“DLET”代码用于删除功能。它用于从 IMS DL/I 数据库中删除一个段。以下是 DLET 调用的语法 −
'DLET' code is used for the Delete function. It is used to remove a segment from an IMS DL/I database. Given below is the syntax of a DLET call −
CALL 'CBLTDLI' USING DLI-DLET
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Replace
“REPL”代码用于在父级内保持获取下一个。替换功能用于替换 IMS DL/I 数据库中的一个段。以下是 REPL 调用的语法 −
'REPL' code is used for Get Hold Next within Parent. The Replace function is used to replace a segment in the IMS DL/I database. Given below is the syntax of an REPL call −
CALL 'CBLTDLI' USING DLI-REPL
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Other Functions
以下其他函数用于 IMS DL/I 调用 −
The following other functions are used in IMS DL/I calls −
-
Checkpoint
-
Restart
-
PCB
Checkpoint
“CHKP”代码用于检查点功能。它用于IMS的恢复功能。下面给出CHKP调用的语法 −
'CHKP' code is used for the Checkpoint function. It is used in the recovery features of IMS. Given below is the syntax of a CHKP call −
CALL 'CBLTDLI' USING DLI-CHKP
PCB Mask
Segment I/O Area
[Segment Search Arguments]
Restart
“XRST”代码用于重启功能。它用于IMS的重启功能。下面给出XRST调用的语法 −
'XRST' code is used for the Restart function. It is used in the restart features of IMS. Given below is the syntax of an XRST call −
CALL 'CBLTDLI' USING DLI-XRST
PCB Mask
Segment I/O Area
[Segment Search Arguments]
PCB
PCB功能在IMS DL/I数据库中用于CICS程序。下面给出PCB调用的语法 −
PCB function is used in CICS programs in the IMS DL/I database. Given below is the syntax of a PCB call −
CALL 'CBLTDLI' USING DLI-PCB
PCB Mask
Segment I/O Area
[Segment Search Arguments]
有关这些功能的更多详细信息,请参见恢复章节。
You can find more details about these functions in the recovery chapter.
IMS DB - PCB Mask
PCB 的全称为 Program Communication Block(程序通信块)。PCB Mask 是在 DL/I 调用中使用的第二个参数。在链接部分中声明。以下是 PCB Mask 的语法:
PCB stands for Program Communication Block. PCB Mask is the second parameter used in the DL/I call. It is declared in the linkage section. Given below is the syntax of a PCB Mask −
01 PCB-NAME.
05 DBD-NAME PIC X(8).
05 SEG-LEVEL PIC XX.
05 STATUS-CODE PIC XX.
05 PROC-OPTIONS PIC X(4).
05 RESERVED-DLI PIC S9(5).
05 SEG-NAME PIC X(8).
05 LENGTH-FB-KEY PIC S9(5).
05 NUMB-SENS-SEGS PIC S9(5).
05 KEY-FB-AREA PIC X(n).
以下为重点注意事项:
Here are the key points to note −
-
For each database, the DL/I maintains an area of storage that is known as the program communication block. It stores the information about the database that are accessed inside the application programs.
-
The ENTRY statement creates a connection between the PCB masks in the Linkage Section and the PCBs within the program’s PSB. The PCB masks used in a DL/I call tells which database to use for operation.
-
You can assume this is similar to specifying a file name in a COBOL READ statement or a record name in a COBOL write statement. No SELECT, ASSIGN, OPEN, or CLOSE statements are required.
-
After each DL/I call, the DL/I stores a status code in the PCB and the program can use that code to determine whether the call succeeded or failed.
PCB Name
重点注意事项:
Points to note −
-
PCB Name is the name of the area which refers to the entire structure of the PCB fields.
-
PCB Name is used in program statements.
-
PCB Name is not a field in the PCB.
DBD Name
重点注意事项:
Points to note −
-
DBD name contains the character data. It is eight bytes long.
-
The first field in the PCB is the name of the database being processed and it provides the DBD name from the library of database descriptions associated with a particular database.
Segment Level
重点注意事项:
Points to note −
-
Segment level is known as Segment Hierarchy Level Indicator. It contains character data and is two bytes long.
-
A segment level field stores the level of the segment that was processed. When a segment is retrieved successfully, the level number of the retrieved segment is stored here.
-
A segment level field never has a value greater than 15 because that is the maximum number of levels permitted in a DL/I database.
Status Code
重点注意事项:
Points to note −
-
Status code field contains two bytes of character data.
-
Status code contains the DL/I status code.
-
Spaces are moved to the status code field when DL/I completes the processing of calls successfully.
-
Non-space values indicate that the call was not successful.
-
Status code GB indicates end-of-file and status code GE indicates that the requested segment is not found.
Proc Options
重点注意事项:
Points to note −
-
Proc options are known as processing options which contain four-character data fields.
-
A Processing Option field indicates what kind of processing the program is authorized to do on the database.
Reserved DL/I
重点注意事项:
Points to note −
-
Reserved DL/I is known as the reserved area of the IMS. It stores four bytes binary data.
-
IMS uses this area for its own internal linkage related to an application program.
Segment Name
重点注意事项:
Points to note −
-
SEG Name is known as segment name feedback area. It contains 8 bytes of character data.
-
The name of the segment is stored in this field after each DL/I call.
Length FB Key
重点注意事项:
Points to note −
-
Length FB key is known as the length of the key feedback area. It stores four bytes of binary data.
-
This field is used to report the length of the concatenated key of the lowest level segment processed during the previous call.
-
It is used with the key feedback area.
Number of Sensitivity Segments
重点注意事项:
Points to note −
-
Number of sensitivity segments store four bytes binary data.
-
It defines to which level an application program is sensitive. It represents a count of number of segments in the logical data structure.
Key Feedback Area
重点注意事项:
Points to note −
-
Key feedback area varies in length from one PCB to another.
-
It contains the longest possible concatenated key that can be used with the program’s view of the database.
-
After a database operation, DL/I returns the concatenated key of the lowest level segment processed in this field, and it returns the length of the key in the key length feedback area.
IMS DB - SSA
SSA 表示段搜索参数。SSA 用于标识被访问的段发生。它是一个可选参数。我们可以根据要求包含任意数量的 SSA。SSA 有两种类型 −
SSA stands for Segment Search Arguments. SSA is used to identify the segment occurrence being accessed. It is an optional parameter. We can include any number of SSAs depending on the requirement. There are two types of SSAs −
-
Unqualified SSA
-
Qualified SSA
Unqualified SSA
不合格 SSA 提供了在调用中所使用段的名称。下面给出了不合格 SSA 的语法 −
An unqualified SSA provides the name of the segment being used inside the call. Given below is the syntax of an unqualified SSA −
01 UNQUALIFIED-SSA.
05 SEGMENT-NAME PIC X(8).
05 FILLER PIC X VALUE SPACE.
不合格 SSA 的要点如下 −
The key points of unqualified SSA are as follows −
-
A basic unqualified SSA is 9 bytes long.
-
The first 8 bytes hold the segment name which is being used for processing.
-
The last byte always contains space.
-
DL/I uses the last byte to determine the type of SSA.
-
To access a particular segment, move the name of the segment in the SEGMENT-NAME field.
以下图像显示了不合格和合格的 SSA 的结构 −
The following images show the structures of unqualified and qualified SSAs −
Qualified SSA
合格的 SSA 为区段提供了特定数据库区段发生的区段类型。以下是合格 SSA 的语法 −
A Qualified SSA provides the segment type with the specific database occurrence of a segment. Given below is the syntax of a Qualified SSA −
01 QUALIFIED-SSA.
05 SEGMENT-NAME PIC X(8).
05 FILLER PIC X(01) VALUE '('.
05 FIELD-NAME PIC X(8).
05 REL-OPR PIC X(2).
05 SEARCH-VALUE PIC X(n).
05 FILLER PIC X(n+1) VALUE ')'.
合格的SSA的主要内容如下−
The key points of qualified SSA are as follows −
-
The first 8 bytes of a qualified SSA holds the segment name being used for processing.
-
The ninth byte is a left parenthesis '('.
-
The next 8 bytes starting from the tenth position specifies the field name which we want to search.
-
After the field name, in the 18th and 19th positions, we specify two-character relational operator code.
-
Then we specify the field value and in the last byte, there is a right parenthesis ')'.
下表显示了合格的SSA中使用的关系运算符。
The following table shows the relational operators used in a Qualified SSA.
Relational Operator |
Symbol |
Description |
EQ |
= |
Equal |
NE |
~= ˜ |
Not equal |
GT |
> |
Greater than |
GE |
>= |
Greater than or equal |
LT |
<< |
Less than |
LE |
⇐ |
Less than or equal |
Command Codes
命令代码用于增强DL/I调用的功能。命令代码减少了DL/I调用的数量,使程序变得简单。此外,它提高了性能,这是因为减少了调用的数量。下图显示了在不合格和合格的SSA中如何使用命令代码−
Command codes are used to enhance the functionality of DL/I calls. Command codes reduce the number of DL/I calls, making the programs simple. Also, it improves the performance as the number of calls is reduced. The following image shows how command codes are used in unqualified and qualified SSAs −
命令代码的主要要点如下−
The key points of command codes are as follows −
-
To use command codes, specify an asterisk in the 9th position of the SSA as shown in the above image.
-
Command code is coded at the tenth position.
-
From 10th position onwards, DL/I considers all characters to be command codes until it encounters a space for an unqualified SSA and a left parenthesis for a qualified SSA.
下表显示了SSA中使用的命令代码列表−
The following table shows the list of command codes used in SSA −
Command Code |
Description |
C |
Concatenated Key |
D |
Path Call |
F |
First Occurrence |
L |
Last Occurrence |
N |
Path Call Ignore |
P |
Set Parentage |
Q |
Enqueue Segment |
U |
Maintain Position at this level |
V |
Maintain Position at this and all above levels |
- |
Null Command Code |
Multiple Qualifications
多重限定的基本要点如下 −
The fundamental points of multiple qualifications are as follows −
-
Multiple qualifications are required when we need to use two or more qualifications or fields for comparison.
-
We use Boolean operators like AND and OR to connect two or more qualifications.
-
Multiple qualifications can be used when we want to process a segment based on a range of possible values for a single field.
以下是多重限定的语法 −
Given below is the syntax of Multiple Qualifications −
01 QUALIFIED-SSA.
05 SEGMENT-NAME PIC X(8).
05 FILLER PIC X(01) VALUE '('.
05 FIELD-NAME1 PIC X(8).
05 REL-OPR PIC X(2).
05 SEARCH-VALUE1 PIC X(m).
05 MUL-QUAL PIC X VALUE '&'.
05 FIELD-NAME2 PIC X(8).
05 REL-OPR PIC X(2).
05 SEARCH-VALUE2 PIC X(n).
05 FILLER PIC X(n+1) VALUE ')'.
MUL-QUAL 是 MULtiple QUALIification 的简称,其中我们可以提供布尔运算符,如 AND 或 OR。
MUL-QUAL is a short term for MULtiple QUALIification in which we can provide boolean operators like AND or OR.
IMS DB - Data Retrieval
IMS DL/I 调用中使用的各种数据检索方法如下 −
The various data retrieval methods used in IMS DL/I calls are as follows −
-
GU Call
-
GN Call
-
Using Command Codes
-
Multiple Processing
让我们考虑以下 IMS 数据库结构,以了解数据检索函数调用 −
Let us consider the following IMS database structure to understand the data retrieval function calls −
GU Call
GU 调用的基本原理如下 −
The fundamentals of GU call are as follows −
-
GU call is known as Get Unique call. It is used for random processing.
-
If an application does not update the database regularly or if the number of database updates is less, then we use random processing.
-
GU call is used to place the pointer at a particular position for further sequential retrieval.
-
GU calls are independent of the pointer position established by the previous calls.
-
GU call processing is based on the unique key fields supplied in the call statement.
-
If we supply a key field that is not unique, then DL/I returns the first segment occurrence of the key field.
CALL 'CBLTDLI' USING DLI-GU
PCB-NAME
IO-AREA
LIBRARY-SSA
BOOKS-SSA
ENGINEERING-SSA
IT-SSA
上面的示例显示,我们通过提供一组完整的限定 SSA 来发出 GU 调用。它包括了从根级别到我们要检索的分段出现的全部键字段。
The above example shows we issue a GU call by providing a complete set of qualified SSAs. It includes all the key fields starting from the root level to the segment occurrence that we want to retrieve.
GU Call Considerations
如果我们没有在调用中提供一组完整的限定 SSA,那么 DL/I 将按以下方式工作:
If we do not provide the complete set of qualified SSAs in the call, then DL/I works in the following way −
-
When we use an unqualified SSA in a GU call, DL/I accesses the first segment occurrence in the database that meets the criteria you specify.
-
When we issue a GU call without any SSAs, DL/I returns the first occurrence of the root segment in the database.
-
If some SSAs at intermediate levels are not mentioned in the call, then DL/I uses either the established position or the default value of an unqualified SSA for the segment.
GN Call
GN调用的基本原理如下:
The fundamentals of GN call are as follows −
-
GN call is known as Get Next call. It is used for basic sequential processing.
-
The initial position of the pointer in the database is before the root segment of the first database record.
-
The database pointer position is before the next segment occurrence in the sequence, after a successful GN call.
-
The GN call starts through the database from the position established by the previous call.
-
If a GN call is unqualified, it returns the next segment occurrence in the database regardless of its type, in hierarchical sequence.
-
If a GN call includes SSAs, then DL/I retrieves only segments that meet the requirements of all specified SSAs.
CALL 'CBLTDLI' USING DLI-GN
PCB-NAME
IO-AREA
BOOKS-SSA
上面的示例显示我们发出一个 GN 调用,提供开始读取记录的顺序位置。它获取 BOOKS 段的第一个出现。
The above example shows we issue a GN call providing the starting position to read the records sequentially. It fetches the first occurrence of the BOOKS segment.
Status Codes
下表显示 GN 调用后的相关状态码 −
The following table shows the relevant status codes after a GN call −
S.No |
Status Code & Description |
1 |
Spaces Successful call |
2 |
GE DL/I could not find a segment that met the criteria specified in the call. |
3 |
GA An unqualified GN call moves up one level in the database hierarchy to fetch the segment. |
4 |
GB End of database is reached and segment not found. |
GK An unqualified GN call tries to fetch a segment of a particular type other than the one just retrieved but stays in the same hierarchical level. |
Command Codes
命令码与调用一起用于获取段出现。下面将讨论与调用一起使用的各种命令码。
Command codes are used with calls to fetch a segment occurrence. The various command codes used with calls are discussed below.
F Command Code
重点注意事项:
Points to note −
-
When an F command code is specified in a call, the call processes the first occurrence of the segment.
-
F command codes can be used when we want to process sequentially and it can be used with GN calls and GNP calls.
-
If we specify an F command code with a GU call, it does not have any significance, as GU calls fetch the first segment occurrence by default.
L Command Code
重点注意事项:
Points to note −
-
When an L command code is specified in a call, the call processes the last occurrence of the segment.
-
L command codes can be used when we want to process sequentially and it can be used with GN calls and GNP calls.
D Command Code
重点注意事项:
Points to note −
-
D command code is used to fetch more than one segment occurrences using just a single call.
-
Normally DL/I operates on the lowest level segment specified in an SSA, but in many cases, we want data from other levels as well. In those cases, we can use the D command code.
-
D command code makes easy retrieval of the entire path of segments.
C Command Code
重点注意事项:
Points to note −
-
C command code is used to concatenate keys.
-
Using relational operators is a bit complex, as we need to specify a field name, a relational operator, and a search value. Instead, we can use a C command code to provide a concatenated key.
以下示例演示了 C 命令码的使用 −
The following example shows the use of C command code −
01 LOCATION-SSA.
05 FILLER PIC X(11) VALUE ‘INLOCSEG*C(‘.
05 LIBRARY-SSA PIC X(5).
05 BOOKS-SSA PIC X(4).
05 ENGINEERING-SSA PIC X(6).
05 IT-SSA PIC X(3)
05 FILLER PIC X VALUE ‘)’.
CALL 'CBLTDLI' USING DLI-GU
PCB-NAME
IO-AREA
LOCATION-SSA
P Command Code
重点注意事项:
Points to note −
-
When we issue a GU or GN call, the DL/I establishes its parentage at the lowest level segment that is retrieved.
-
If we include a P command code, then the DL/I establishes its parentage at a higher level segment in the hierarchical path.
U Command Code
重点注意事项:
Points to note −
-
When a U command code is specified in an unqualified SSA in a GN call, the DL/I restricts the search for the segment.
-
U command code is ignored if it is used with a qualified SSA.
Multiple Processing
一个程序可以在 IMS 数据库中具有多个位置,这被称为多重处理。多重处理可以通过两种方式完成:
A program can have multiple positions in the IMS database which is known as multiple processing. Multiple processing can be done in two ways −
-
Multiple PCBs
-
Multiple Positioning
Multiple PCBs
可以为单个数据库定义多个 PCB。如果存在多个 PCB,那么应用程序可以对其有不同的视图。此实现多重处理的方法由于额外 PCB 带来的开销而效率低下。
Multiple PCBs can be defined for a single database. If there are multiple PCBs, then an application program can have different views of it. This method for implementing multiple processing is inefficient because of the overheads imposed by the extra PCBs.
Multiple Positioning
一个程序可以使用单个 PCB 在数据库中维护多个位置。这是通过为每个分层路径维护一个不同的位置来实现的。多重定位用于同时以顺序方式访问两个或更多类型的段。
A program can maintain multiple positions in a database using a single PCB. This is achieved by maintaining a distinct position for each hierarchical path. Multiple positioning is used to access segments of two or more types sequentially at the same time.
IMS DB - Data Manipulation
IMS DL/I 调用中使用的不同数据操作方法如下:
The different data manipulation methods used in IMS DL/I calls are as follows −
-
ISRT Call
-
Get Hold Calls
-
REPL Call
-
DLET Call
让我们考虑以下 IMS 数据库结构以了解数据操作函数调用:
Let us consider the following IMS database structure to understand the data manipulation function calls −
ISRT Call
重点注意事项:
Points to note −
-
ISRT call is known as Insert call which is used to add segment occurrences to a database.
-
ISRT calls are used for loading a new database.
-
We issue an ISRT call when a segment description field is loaded with data.
-
An unqualified or qualified SSA must be specified in the call so that the DL/I knows where to place a segment occurrence.
-
We can use a combination of both unqualified and qualified SSA in the call. A qualified SSA can be specified for all the above levels. Let us consider the following example −
CALL 'CBLTDLI' USING DLI-ISRT
PCB-NAME
IO-AREA
LIBRARY-SSA
BOOKS-SSA
UNQUALIFIED-ENGINEERING-SSA
上面的示例表明我们正通过提供限定和未限定 SSA 的组合来发出 ISRT 调用。
The above example shows we are issuing an ISRT call by providing a combination of qualified and unqualified SSAs.
当我们正在插入的新段具有唯一键字段时,它将被添加到适当的位置。如果键字段不是唯一的,那么将按照数据库管理员定义的规则添加它。
When a new segment that we are inserting has a unique key field, then it is added at the proper position. If the key field is not unique, then it is added by the rules defined by a database administrator.
当我们发出一个 ISRT 调用而没有指定关键字段时,插入规则会告诉我们如何将段相对于现有的孪生段放置。下面给出插入规则——
When we issue an ISRT call without specifying a key field, then the insert rule tells where to place the segments relative to existing twin segments. Given below are the insert rules −
-
First − If the rule is first, the new segment is added before any existing twins.
-
Last − If the rule is last, the new segment is added after all existing twins.
-
Here − If the rule is here, it is added at the current position relative to existing twins, which may be first, last, or anywhere.
Status Codes
下表显示了 ISRT 调用后的相关状态代码——
The following table shows the relevant status codes after an ISRT call −
S.No |
Status Code & Description |
1 |
Spaces Successful call |
2 |
GE Multiple SSAs are used and the DL/I cannot satisfy the call with the specified path. |
3 |
II Try to add a segment occurrence that is already present in the database. |
4 |
LB / LC LD / LE We get these status codes while load processing. In most cases, they indicate that you are not inserting the segments in an exact hierarchical sequence. |
Get Hold Call
重点注意事项:
Points to note −
-
There are three types of Get Hold call which we specify in a DL/I call: Get Hold Unique (GHU) Get Hold Next (GHN) Get Hold Next within Parent (GHNP)
-
Hold function specifies that we are going to update the segment after retrieval. So before an REPL or DLET call, a successful hold call must be issued telling the DL/I an intent to update the database.
REPL Call
重点注意事项:
Points to note −
-
After a successful get hold call, we issue an REPL call to update a segment occurrence.
-
We cannot change the length of a segment using an REPL call.
-
We cannot change the value of a key field using an REPL call.
-
We cannot use a qualified SSA with an REPL call. If we specify a qualified SSA, then the call fails.
CALL 'CBLTDLI' USING DLI-GHU
PCB-NAME
IO-AREA
LIBRARY-SSA
BOOKS-SSA
ENGINEERING-SSA
IT-SSA.
*Move the values which you want to update in IT segment occurrence*
CALL ‘CBLTDLI’ USING DLI-REPL
PCB-NAME
IO-AREA.
上面的示例使用 REPL 调用更新 IT 段出现。首先,我们发出一个 GHU 调用来获取要更新的段出现。然后,我们发出一个 REPL 调用来更新该段的值。
The above example updates the IT segment occurrence using an REPL call. First, we issue a GHU call to get the segment occurrence we want to update. Then, we issue an REPL call to update the values of that segment.
DLET Call
重点注意事项:
Points to note −
-
DLET call works much in the same way as an REPL call does.
-
After a successful get hold call, we issue a DLET call to delete a segment occurrence.
-
We cannot use a qualified SSA with a DLET call. If we specify a qualified SSA, then the call fails.
CALL 'CBLTDLI' USING DLI-GHU
PCB-NAME
IO-AREA
LIBRARY-SSA
BOOKS-SSA
ENGINEERING-SSA
IT-SSA.
CALL ‘CBLTDLI’ USING DLI-DLET
PCB-NAME
IO-AREA.
上面的示例使用 DLET 调用删除 IT 段出现。首先,我们发出一个 GHU 调用来获取要删除的段出现。然后,我们发出一个 DLET 调用来更新该段的值。
The above example deletes the IT segment occurrence using a DLET call. First, we issue a GHU call to get the segment occurrence we want to delete. Then, we issue a DLET call to update the values of that segment.
Status Codes
以下表格显示 REPL 或 DLET 调用之后的相关状态代码 −
The following table shows the relevant status codes after an REPL or a DLET call −
S.No |
Status Code & Description |
1 |
Spaces Successful call |
2 |
AJ Qualified SSA used on REPL or DLET call. |
3 |
DJ Program issues a replace call without an immediately preceding get hold call. |
4 |
DA Program makes a change to the segment’s key field before issuing the REPL or DLET call |
IMS DB - Secondary Indexing
当我们想访问数据库而不使用完整的串联键,或者当我们不想使用顺序主键字段时,将使用辅助索引。
Secondary Indexing is used when we want to access a database without using the complete concatenated key or when we do not want to use the sequence primary fields.
Index Pointer Segment
DL/I 在单独的数据库中存储指向索引数据库段的指针。索引指针段是辅助索引中唯一一种类型。它由以下两个部分组成 -
DL/I stores the pointer to segments of the indexed database in a separate database. Index pointer segment is the only type of secondary index. It consists of two parts −
-
Prefix Element
.
-
Data Element
Prefix Element
索引指针段的前缀部分包含指向索引目标段的指针。索引目标段是可使用辅助索引访问的段。
The prefix part of the index pointer segment contains a pointer to the Index Target Segment. Index target segment is the segment that is accessible using the secondary index.
Data Element
数据元素包含构建索引的索引数据库中段的关键值。这也称为索引源段。
The data element contains the key value from the segment in the indexed database over which the index is built. This is also known as the index source segment.
以下是有关辅助索引的重点注意事项 -
Here are the key points to note about Secondary Indexing −
-
The index source segment and the target source segment need not be the same.
-
When we set up a secondary index, it is automatically maintained by the DL/I.
-
The DBA defines many secondary indexes as per the multiple access paths. These secondary indexes are stored in a separate index database.
-
We should not create more secondary indexes, as they impose additional processing overhead on the DL/I.
Secondary Keys
重点注意事项:
Points to note −
-
The field in the index source segment over which the secondary index is built is called as the secondary key.
-
Any field can be used as a secondary key. It need not be the segments sequence field.
-
Secondary keys can be any combination of single fields within the index source segment.
-
Secondary key values do not have to be unique.
Secondary Data Structures
重点注意事项:
Points to note −
-
When we build a secondary index, the apparent hierarchical structure of the database is also changed.
-
The index target segment becomes the apparent root segment. As shown in the following image, the Engineering segment becomes the root segment, even if it is not a root segment.
-
The rearrangement of the database structure caused by the secondary index is known as the secondary data structure.
-
Secondary data structures do not make any changes to the main physical database structure present on the disk. It is just a way to alter the database structure in front of the application program.
Independent AND Operator
重点注意事项:
Points to note −
-
When an AND (* or &) operator is used with secondary indexes, it is known as a dependent AND operator.
-
An independent AND (#) allows us to specify qualifications that would be impossible with a dependent AND.
-
This operator can be used only for secondary indexes where the index source segment is dependent on the index target segment.
-
We can code an SSA with an independent AND to specify that an occurrence of the target segment be processed based on the fields in two or more dependent source segments.
01 ITEM-SELECTION-SSA.
05 FILLER PIC X(8).
05 FILLER PIC X(1) VALUE '('.
05 FILLER PIC X(10).
05 SSA-KEY-1 PIC X(8).
05 FILLER PIC X VALUE '#'.
05 FILLER PIC X(10).
05 SSA-KEY-2 PIC X(8).
05 FILLER PIC X VALUE ')'.
Sparse Sequencing
重点注意事项:
Points to note −
-
Sparse sequencing is also known as Sparse Indexing. We can remove some of the index source segments from the index using sparse sequencing with secondary index database.
-
Sparse sequencing is used to improve the performance. When some occurrences of the index source segment are not used, we can remove that.
-
DL/I uses a suppression value or a suppression routine or both to determine whether a segment should be indexed.
-
If the value of a sequence field in the index source segment matches a suppression value, then no index relationship is established.
-
The suppression routine is a user-written program that evaluates the segment and determines whether or not it should be indexed.
-
When sparse indexing is used, its functions are handled by the DL/I. We do not need to make special provisions for it in the application program.
DBDGEN Requirements
如前面模块中所讨论的,DBDGEN 用于创建 DBD。当我们创建辅助索引时,涉及两个数据库。DBA 需要使用两个 DBDGEN 创建两个 DBD,用于在已编制索引的数据库和辅助索引数据库之间建立关系。
As discussed in earlier modules, DBDGEN is used to create a DBD. When we create secondary indexes, two databases are involved. A DBA needs to create two DBDs using two DBDGENs for creating a relationship between an indexed database and a secondary indexed database.
PSBGEN Requirements
为数据库创建辅助索引后,DBA 需要创建 PSB。面向程序的 PSBGEN 指定 PROCSEQ 参数中数据库的正确处理顺序的 PSB 宏。对于 PROCSEQ 参数,DBA 编码辅助索引数据库的 DBD 名称。
After creating the secondary index for a database, the DBA needs to create the PSBs. PSBGEN for the program specifies the proper processing sequence for the database on the PROCSEQ parameter of the PSB macro. For the PROCSEQ parameter, the DBA codes the DBD name for the secondary index database.
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.
IMS DB - Recovery
数据库管理员需要针对系统故障制定数据库恢复计划。故障可能有多种类型,例如应用程序崩溃、硬件错误、电源故障等。
The database administrator needs to plan for the database recovery in case of system failures. Failures can be of many types such as application crashes, hardware errors, power failures, etc.
Simple Approach
一些简单的数据库恢复方法如下 −
Some simple approaches to database recovery are as follows −
-
Make periodical backup copies of important datasets so that all transactions posted against the datasets are retained.
-
If a dataset is damaged due to a system failure, that problem is corrected by restoring the backup copy. Then the accumulated transactions are re-posted to the backup copy to bring them up-to-date.
Disadvantages of Simple Approach
简单的数据库恢复方法的缺点如下 −
The disadvantages of simple approach to database recovery are as follows −
-
Re-posting the accumulated transactions consumes a lot of time.
-
All other applications need to wait for execution until the recovery is finished.
-
Database recovery is lengthier than file recovery, if logical and secondary index relationships are involved.
Abnormal Termination Routines
DL/I 程序的崩溃方式与标准程序的崩溃方式不同,因为标准程序是由操作系统直接执行的,而 DL/I 程序则不是。通过使用异常终止例程,系统会进行干预,以便在异常终止 (ABEND) 后可以进行恢复。异常终止例程执行以下操作 −
A DL/I program crashes in a way that is different from the way a standard program crashes because a standard program is executed directly by the operating system, while a DL/I program is not. By employing an abnormal termination routine, the system interferes so that recovery can be done after the ABnormal END (ABEND). The abnormal termination routine performs the following actions −
-
Closes all datasets
-
Cancels all pending jobs in the queue
-
Creates a storage dump to find out the root cause of ABEND
该例程的局限性在于,它无法确保正在使用的数据是否准确。
The limitation of this routine is that it does not ensure if the data in use is accurate or not.
DL/I Log
当应用程序 ABEND 时,有必要还原应用程序所做的更改、更正错误并重新运行应用程序。为此,必须拥有 DL/I 日志。以下是有关 DL/I 日志记录的关键点 −
When an application program ABENDs, it is necessary to revert the changes done by the application program, correct the error, and re-run the application program. To do this, it is required to have the DL/I log. Here are the key points about DL/I logging −
-
A DL/I records all the changes made by an application program in a file which is known as the log file.
-
When the application program changes a segment, its before image and after images are created by the DL/I.
-
These segment images can be used to restore the segments, in case the application program crashes.
-
DL/I uses a technique called write-ahead logging to record database changes. With write-ahead logging, a database change is written to the log dataset before it is written to the actual dataset.
-
As the log is always ahead of the database, the recovery utilities can determine the status of any database change.
-
When the program executes a call to change a database segment, the DL/I takes care of its logging part.
Recovery – Forward and Backward
数据库恢复的两种方法是 -
The two approaches of database recovery are −
-
Forward Recovery − DL/I uses the log file to store the change data. The accumulated transactions are re-posted using this log file.
-
Backward Recovery − Backward recovery is also known as backout recovery. The log records for the program are read backwards and their effects are reversed in the database. When the backout is complete, the databases are in the same state as they were in before the failure, assuming that no another application program altered the database in the meantime.
Checkpoint
检查点是应用程序程序执行的数据库更改被认为是完整且准确的阶段。下面列出了有关检查点需要注意的事项 -
A checkpoint is a stage where the database changes done by the application program are considered complete and accurate. Listed below are the points to note about a checkpoint −
-
Database changes made before the most recent checkpoint are not reversed by backward recovery.
-
Database changes logged after the most recent checkpoint are not applied to an image copy of the database during forward recovery.
-
Using checkpoint method, the database is restored to its condition at the most recent checkpoint when the recovery process completes.
-
The default for batch programs is that the checkpoint is the beginning of the program.
-
A checkpoint can be established using a checkpoint call (CHKP).
-
A checkpoint call causes a checkpoint record to be written on the DL/I log.
以下是 CHKP 调用的语法 -
Shown below is the syntax of a CHKP call −
CALL 'CBLTDLI' USING DLI-CHKP
PCB-NAME
CHECKPOINT-ID
有两种检查点方法 -
There are two checkpoint methods −
-
Basic Checkpointing − It allows the programmer to issue checkpoint calls that the DL/I recovery utilities use during recovery processing.
-
Symbolic Checkpointing − It is an advanced form of checkpointing that is used in combination with the extended restart facility. Symbolic checkpointing and extended restart together let the application programmer code the programs so that they can resume processing at the point just after the checkpoint.