Coding a batch program in COBOL
The following code example shows how to write an IMS program to access the IMS database in COBOL.
The numbers to the right of the program refer to the notes that follow the program. This kind of program can run as a batch program or as a batch-oriented BMP.
Sample COBOL program
Identification Division.
Program-ID. BATCOBOL.
Environment Division.
Data Division.
Working-Storage Section.
01 Func-Codes.
05 Func-GU Picture XXXX Value 'GU '.
05 Func-GHU Picture XXXX Value 'GHU '.
05 Func-GN Picture XXXX Value 'GHN '.
05 Func-GHN Picture XXXX Value 'GHN '.
05 Func-GNP Picture XXXX Value 'GNP '.
05 Func-GHNP Picture XXXX Value 'GHNP'.
05 Func-REPL Picture XXXX Value 'REPL'.
05 Func-ISRT Picture XXXX Value 'ISRT'.
05 Func-DLET Picture XXXX Value 'DLET'.
05 Parmcount Picture S9(5) Value +4 Comp-5.
01 Unqual-SSA.
05 Seg-Name Picture X(08) Value ' '.
05 Filler Picture X Value ' '.
01 Qual-SSA-Mast.
05 Seg-Name-M Picture X(08) Value 'ROOTMast'.
05 Begin-Paren-M Picture X Value '('.
05 Key-Name-M Picture X(08) Value 'KeyMast '.
05 Kel-Oper-M Picture X(05) Value ' ='.
05 Key-Value-M Picture X(06) Value 'VVVVVV'.
05 End-Paren-M Picture X Value ')'.
01 Qual-SSA-Det.
05 Seg-Name-D Picture X(08) Value 'ROOTDET '.
05 Begin-Paren-D Picture X Value '('.
05 Key-Name-D Picture X(08) Value 'KEYDET '.
05 Rel-Oper-D Picture X(05) Value ' ='.
05 Key-Value-D Picture X(06) Value 'VVVVVV'.
05 End-Paren-D Picture X Value ')'.
01 Det-Seg-In.
05 Data1 Picture X.
05 Data2 Picture X.
01 Mast-Seg-In.
05 Data1 Picture X.
05 Data2 Picture X.
linkage section.
01 IO-PCB.
05 Filler Picture X(10).
05 IO-Status-Code Picture XX.
05 Filler Picture X(20).
01 DB-PCB-Mast.
05 Mast-Dbd-Name Picture X(8).
05 Mast-Seg-Level Picture XX.
05 Mast-Status-Code Picture XX.
05 Mast-Proc-Opt Picture XXXX.
05 Filler Picture S9(5) Comp-5.
05 Mast-Seg-Name Picture X(8).
05 Mast-Len-KFB Picture S9(5) Comp-5.
05 Mast-Nu-Senseg Picture S9(5) Comp-5.
05 Mast-Key-FB Picture X(256).
01 DB-PCB-Detail.
05 Det-Dbd-Name Picture X(8).
05 Det-Seg-Level Picture XX.
05 Det-Status-Code Picture XX.
05 Det-Proc-Opt Picture XXXX.
05 Filler Picture S9(5) Comp-5.
05 Det-Seg-Name Picture X(8).
05 Det-Len-KFB Picture S9(5) Comp-5.
05 Det-Nu-Senseg Picture S9(5) Comp-5.
05 Det-Key-FB Picture X(256).
Procedure Division using IO-PCB DB-PCB-Mast DB-PCB-Detail.
Call 'CBLTDLI' using Func-GU DB-PCB-Detail
Det-seg-in Qual-SSA-Det.
.
.
Call 'CBLTDLI' using Parmcount Func-ghu DB-PCB-Mast
Mast-seg-in Qual-SSA-Mast.
.
.
Call 'CBLTDLI' using Func-GHN DB-PCB-Mast
Mast-seg-in.
.
.
Call 'CBLTDLI' using Func-REPL DB-PCB-Mast
Mast-seg-in.
.
.
Goback.
- You define each of the DL/I call functions the program uses with a 77-level or 01-level working storage entry. Each picture clause is defined as four alphanumeric characters and has a value assigned for each function. If you want to include the optional parmcount field, you can initialize count values for each type of call. You can also use a COBOL COPY statement to include these standard descriptions in the program.
- A 9-byte area is set up for an unqualified SSA. Before the program issues a call that requires an unqualified SSA, it moves the segment name to this area. If a call requires two or more SSAs, you may need to define additional areas.
- A 01-level working storage entry defines each qualified SSA that the application program uses. Qualified SSAs must be defined separately, because the values of the fields are different.
- A 01-level working storage entry defines I/O areas that are used for passing segments to and from the database. You can further define I/O areas with sub-entries under the 01-level. You can use separate I/O areas for each segment type, or you can define one I/O area that you use for all segments.
- A 01-level linkage section entry defines a mask for each of the PCBs that the program requires. The DB PCBs represent both input and output databases. After issuing each DL/I call, the program checks the status code through this linkage. You define each field in the DB PCB so that you can reference it in the program.
- This is the standard procedure division statement of a batch program. After IMS has loaded the PSB for the program, IMS passes control to the application program. The PSB contains all the PCBs that are defined
in the PSB. The coding of
USING
on the procedure division statement references each of the PCBs by the names that the program has used to define the PCB masks in the linkage section. The PCBs must be listed in the order in which they are defined in the PSB.The previous code example assumes that an I/O PCB was passed to the application program. When the program is a batch program, CMPAT=YES must be specified on the PSBGEN statement of PSBGEN so that the I/O PCB is included. Because the I/O PCB is required for a batch program to make system service calls, CMPAT=YES should always be specified for batch programs.
The entry DLITCBL statement is only used in the main program. Do not use it in called programs.
- This call retrieves data from the database by using a qualified SSA. Before issuing the call, the program must initialize the key or data value of the SSA so that it specifies the particular segment to be retrieved. The program should test the status code in the DB PCB that was referenced in the call immediately after issuing the call. You can include the parmcount parameter in DL/I calls in COBOL programs, except in the call to the sample status-code error routine. It is never required in COBOL.
- This is another retrieval call that contains a qualified SSA.
- This is an unqualified retrieval call.
- The
REPL
call replaces the segment that was retrieved in the most recent Get Hold call. The segment is replaced with the contents of the I/O area that is referenced in the call (MAST-SEG-IN). - The program issues the GOBACK statement when it has finished processing.
Related reading: For information on how to use these procedures, see IMS Version 15.4 System Definition.