Ims Db 简明教程
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.