IMS PL/1 Programming
IMS PL/1 Programming
IMS programming interface IMS calls PCB Masks Input/Output areas Segment search arguments GET calls Status codes Program execution
21 22 23 25 26 30 32 35
Retrieve calls
The Entry statement is the first entry in the PROCEDURE DIVISION and is the old method of specifying the entry point. The sequence of PCB names on the entry statement must be the same as their sequence in the PSB (Program Specification Block).
program
Entry
DL/1
PCB1 PCB2
PL/1: Entry to a PL/1 Program The first procedure of a program is as follows: ANYPROG: PROCEDURE(PCB-ptr1,...,PCB-ptrn)OPTIONS(MAIN); As with COBOL, the sequence of PCB pointers in the PROCEDURE statement must be the same as the sequence of the PCB names in the PSB.
(IPB1/4;2005.03)
Page 21
Retrieve calls
IMS calls
When a program accesses an ordinary file, it will use statements such as READ and WRITE. When a program needs to access a segment in a DL/1 database, it will use a CALL statement to ask IMS to perform the required action: CALL 'CBLTDLI' USING function PCB IOAREA SSA1 : SSAn. FUNCTION PCB IOAREA SSA1 to SSAn 4 byte DL/1 function Name of PCB mask A work area long enough to hold the segments being retrieved Segment Search Arguments values for keys of segments what do you want to do? which database? where will the data be placed? SSAs indicate ... ... which segments ... ... we want
The functions are defined as 4-byte WORKING-STORAGE areas and are normally stored in a copy book. The contents would include the following:
01 CLAIMS-WORKING-CONSTANTS. 02 IMS-ACCESS-CONSTANTS. 03 DB-ACCESS-CONSTANTS. 04 GU-FUNC 04 GN-FUNC 04 GNP-FUNC 04 GHU-FUNC 04 GHN-FUNC 04 GHNP-FUNC 04 ISRT-FUNC 04 REPL-FUNC 04 DLET-FUNC
PIC X(4) VALUE 'GU '. PIC X(4) VALUE 'GN '. PIC X(4) VALUE 'GNP '. PIC X(4) VALUE 'GHU '. PIC X(4) VALUE 'GHN '. PIC X(4) VALUE 'GHNP'. PIC X(4) VALUE 'ISRT'. PIC X(4) VALUE 'REPL'. PIC X(4) VALUE 'DLET'.
(IPB1/4;2005.03)
Page 22
Retrieve calls
PCB Masks
The PSB used by a program will contain one or more PCBs. The PSB is stored externally to the application program, so the program needs to gain access to the PSB so that it can obtain certain information about the database which is being accessed. The program communicates with PCB details via a PCB Mask.
PCB mask
program
IOAREA
Entry
PCB mask
DL/1
PCB1 PCB2
IIB-25
8 2 2 4 4 8 4 4
Char
n Page 23
Retrieve calls
X(8). XX. XX. XXXX. S9(5) COMP. X(8). S9(5) COMP. S9(5) COMP. X(18).
CUSTOMER 110179368
23457
If the key of PAYMENT is 8 bytes long, the key feedback area must have a length of 18 bytes. 1+9+8
PAYMENT
PL/1 The PCBs are passed as pointers, so only one mask is needed. Set PTR to the correct PCB address before issuing the call to DL/1.
DCL 1 2 2 2 2 2 2 2 2 2 PCBNAME DBD_NAME SEG_LEVEL STATUS_CODE PROC_OPTIONS RESERVED SEG_NAME LENGTH_FB NO_SENSEGS KEY_FBAREA BASED(PTR), CHAR(8), CHAR(2), CHAR(2), CHAR(4), FIXED BIN(31), CHAR(8), FIXED BIN(31), FIXED BIN(31), CHAR(18);
(IPB1/4;2005.03)
Page 24
Retrieve calls
Input/Output Areas
Each program must provide an area into which DL/1 can place the data. The size and format of the I/O Areas is often supplied by the DBA.
Usually, each segment has its own I/O Area. The structure is the same as for normal record I/O Areas.
program
IOAREA
Entry
DL/1
PCB1 PCB2
In the following example, we want to retrieve a segment from the database referenced by PCB1. The call is a Get Unique which is similar to a random read. Details of the segment we want are placed in a Segment Search Argument, part of which contains a value of P012001234. When IMS locates the required segment it copies it to our specified I/O area (IO-POL in this case). We will examine the structure of the SSAs in the next few pages.
MOVE 'P012001234' TO SSA-POL-VALUE CALL 'CBLTDLI' USING GU-FUNC PCB1 IO-POL SSA-POL
At this point of the program, we should check the status code telling us if the call was successful or not. The status code is one of the fields of the PCB.
(IPB1/4;2005.03)
Page 25
Retrieve calls
program
IOAREA
Entry
DL/1
PCB1
WORKING-STORAGE SECTION. 01 01 GET-UNIQUE CUSTOMER-INFO-IO-AREA. 02 CUSTOMER-NO 02 CUSTOMER-NAME 02 CUSTOMER-ADDR 02 CUSTOMER-TOWN 02 CUSTOMER-POSTCODE CUSTOMER-SSA-UNQ 02 FILLER 02 FILLER PIC X(4) VALUE 'GU '.
PCB-MASK contents following a successful call: DBD-NAME CUSTDB SEG-LEVEL 1 STATUS-CODE bb PROC-OPTION GO RESERVE-DLI SEG-NAME-FB CUSTINFO LENGTH-KEY-FB 5 NUMB-OF-SEN-SEG 4 KEY-FB-AREA 01234
01
PROCEDURE DIVISION. ENTRY-POINT SECTION. ENTRY 'DLITCBL' USING PCB-MASK CALL 'CBLTDLI' USING GET-UNIQUE PCB-MASK CUSTOMER-INFO-IO-AREA CUSTOMER-SSA-UNQ
(IPB1/4;2005.03)
Page 26
Retrieve calls If we want to retrieve a segment with a specific key value then we supply a fully qualified SSA.
b 1
IPC-10
The name of the segment as defined in the PSB. Additional go-faster options; see later; optional If present, it indicates that the SSA is qualified. This is the name of a field which has been defined within this segment in the DBD. The name used in the SSA must exactly match the name in the DBD. It can be a Key Field or a Search Field. This is a relational operator which defines how the contents of the named field will be compared with the given value. The operators available are: =b b= EQ equal to b indicates a blank >= => GE greater than <= =< LE less than or equal to b> >b GT greater than b< <b LT less than = NE not equal to The value which will be compared with the contents of the named field. The value must have the same format as the named field. This signifies the end of the SSA. SSAs are treated as character strings, so do not omit the 'end-op'.
Oakwood Computing Ltd
A Computer Education Techniques, Inc. Instructor-led course.
OP
(IPB1/4;2005.03)
Page 27
Retrieve calls
COBOL 01 CUST-SSA. 05 SEGNAME 05 COMMAND-CD 05 BEGIN-OP 05 KEYNAME 05 COMP-OP 05 KEYVALUE 05 END-OP
VALUE ')'.
CUSTTYPE D
CUSTOMER 110179368
23457
PAYMENT
Examples of SSAs 1. Qualified at each level: CUSTTYPE*---(TYPEbbbbb=D) CUSTOMER*---(CACNObbbb=110179368) METERbbb*---(MTRNObbbb=71628) 2. Missing level: CUSTTYPE(TYPEbbbbb=D) METERbbb(MTRNObbbb=12249) 3. Qualified and unqualified: CUSTTYPE*---(TYPEbbbbb=I) CUSTOMERb CUSTTYPEb CUSTOMER*---(CACNObbbb=368179110)
(IPB1/4;2005.03)
Page 28
Retrieve calls
WORKING-STORAGE SECTION. 01 GET-UNIQUE 01 SHIP-ADDRESS-I-O-AREA. 02 SHIP-NUMBER 02 SHIP-ADDR 02 SHIP-TOWN 02 SHIP-POSTCODE CUST-SSA-Q. 02 FILLER 02 FILLER 02 FILLER 02 FILLER 02 FILLER 02 CUST-KEY 02 FILLER SHIP-SSA-Q. 02 FILLER 02 FILLER 02 FILLER 02 FILLER 02 FILLER 02 SHIP-TO-KEY 02 FILLER
PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC
X(5). X(15). X(15). X(8). X(8) VALUE X(4) VALUE X(1) VALUE X(8) VALUE X(2) VALUE X(5). X(1) VALUE X(8) VALUE X(4) VALUE X(1) VALUE X(8) VALUE X(2) VALUE X(5). X(1) VALUE
This sample coding is for a qualified Get Unique using two SSAs.
01
'CUSTINFO' '*---'. '('. 'CUSTNO'. '= '. ')'. 'SHIPADDR' '*---'. '('. 'CSTSHPNO'. '= '. ')'.
01
LINKAGE SECTION. 01 PCB-MASK. 02 DBD-NAME 02 SEG-LEVEL 02 STATUS-CODE 02 PROC-OPTION 02 RESERVE-DLI 02 SEG-NAME-FB 02 LENGTH-KEY-FB 02 NUMB-OF-SEN-SEG 02 KEY-FB-AREA
X(8). X(2). X(2). X(4). S9(5) COMP. X(8). S9(5) COMP. S9(5) COMP. X(10).
PROCEDURE DIVISION. ENTRY-POINT SECTION. ENTRY 'DLITCBL' USING PCB-MASK MOVE IN-CUST-NO TO CUST-KEY MOVE IN-SHIP-NO TO SHIP-TO-KEY CALL 'CBLTDLI' USING
PCB-MASK contents following a successful call. DBD-NAME CUSTDB SEG-LEVEL 2 STATUS-CODE bb PROC-OPTION GO RESERVE-DLI SEG-NAME-FB SHIPADDR LENGTH-KEY-FB 10 NUMB-OF-SEN-SEG 4 KEY-FB-AREA 0123454321
PCB-MASK contents following a failed call. DBD-NAME CUSTDB SEG-LEVEL 1 STATUS-CODE GE PROC-OPTION GO RESERVE-DLI SEG-NAME-FB CUSTINFO LENGTH-KEY-FB 5 NUMB-OF-SEN-SEG 4 KEY-FB-AREA 01234
Page 29
Retrieve calls
Retrieve Functions
IMS has several functions which will retrieve a segment: GU Get Unique, similar to a random read. Any unqualified GU will start at the beginning of the data base whether or not a previous position has been established. Get Next, similar to a sequential read. If no position has been established and an unqualified call has been issued, processing will begin from the start of the data base. Successive Get Next calls will retrieve segments in the hierarchical order.
GN
2 3
1 5 4
8 9
7 11 10
13 12
IIB-40
Get Next within Parent; sequential read of dependent segment. A GNP call is similar to a GN except that only lower level dependent segments of an established parent are returned. Parentage is automatically set when a GNP is issued following a successful GN or GU.
GH calls Get Hold: as above, but IMS will lock the segment. These are needed before you can delete or update a segment GHU GHN GHNP
(IPB1/4;2005.03)
Page 30
Retrieve calls
2 3
1 5 4
8 9
7 11 10
13 12
IIB-40
(IPB1/4;2005.03)
Page 31
Retrieve calls
Status Codes
When a program issues a database call, IMS returns a value which indicates whether the call was successful or not. This value is called a status code. The program should check the value of the status code and take appropriate action if an error has occurred.
2 3
1 5 4
8 9
7 11 10
13 12
IIB-40
Crossed hierarchical boundary End of data base Segment not found Different segment type at same level returned No parentage established Segment already exists (update) Segment already exists (load) Segment keys are out of sequence Segment's parent has not been loaded Different sequence of sibling segments from the DBD. Violated delete rule Violated insert rule Violated replace rule
Nx N as the first character indicates that an error has occurred during index maintenance, the 2nd character indicates the 2nd character of a normal status code
(IPB1/4;2005.03)
Page 32
Retrieve calls Examples of Call Statements and the corresponding status codes
CUSTTYPE D
CUSTOMER 110179368
23457
PAYMENT
Call No. Function Segment Search Argument Returned 1 2 3 GU GN GU CUSTTYPE(TYPEbbbbb=D) CUSTOMER(CACNObbbb=110179368) CUSTTYPE(TYPEbbbbb=D) CUSTOMER(CACNObbbb=110179368) METERbbb(MTRNObbbb=56789) CUSTTYPE(TYPEbbbbb=D) CUSTTYPE(TYPEbbbbb=D) METERbbb(MTRNObbbb=45678) CUSTOMER(CACNObbbb=345678912) CUSTOMER(NUMBERbbb=123456789) CUSTOMER Sets parentage
Status Code bb bb
GE AD
4 5
UG GU
AC AK bb bb bb GE GP AJ
6 7
8 9
GNP GU
(IPB1/4;2005.03)
Page 33
Retrieve calls
WORKING-STORAGE SECTION. 01 GET-NEXT PIC X(4) VALUE 'GN '. 01 EOJ-SW PIC X VALUE 'N'. 01 SEG-I-O-AREA PIC X(63). 01 CUST-INFO-I-O-AREA REDEFINES SEG-I-O-AREA. 02 CUSTOMER-NO PIC X(5). 02 CUSTOMER-NAME PIC X(20). 02 CUSTOMER-ADDR PIC X(15). 02 CUSTOMER-TOWN PIC X(15). 02 CUSTOMER-POSTCODE PIC X(8). 01 SHIP-ADDRESS-I-O-AREA REDEFINES SEG-I-O-AREA. 02 SHIP-NUMBER PIC X(5). 02 SHIP-ADDR PIC X(15). 02 SHIP-TOWN PIC X(15). 02 SHIP-POSTCODE PIC X(8). 01 BILLING-I-O-AREA REFEFINES SEG-I-O-AREA 02 BILLING-DATE PIC X(6). 02 BILLING-INVOICE-NUMBER PIC X(8). 02 BILLING-AMOUNT PIC S9(6)V99. 01 CASH-I-O-AREA REDEFINES SEG-I-O-AREA. 02 CASH-DATE PIC X(6). 02 CASH-INVOICE-NUMBER PIC X(8). 02 CASH-AMOUNT PIC S9(6)V99. LINKAGE SECTION. 01 PCB-MASK. 02 DBD-NAME PIC X(8). 02 SEG-LEVEL PIC X(2). 02 STATUS-CODE PIC X(2). 02 PROC-OPTION PIC X(4). 02 RESERVE-DLI PIC S9(5) COMP. 02 SEG-NAME-FB PIC X(8). 02 LENGTH-KEY-FB PIC S9(5) COMP. 02 NUMB-OF-SEN-SEG PIC S9(5) COMP. 02 KEY-FB-AREA PIC X(10). PROCEDURE DIVISION. ENTRY-POINT SECTION. ENTRY 'DLITCBL' USING PCB-MASK. This program sample uses PERFORM GET-NEXT-ROUTINE UNTIL EOJ-SW = 'Y' an unqualified GET NEXT PERFORM END-OF-JOB-PROCESSING call to read segments into a GOBACK. GET-NEXT-ROUTINE SECTION. general area. The program CALL 'CBLTDLI' USING GET-NEXT must determine the type of PCB-MASK SEG-I-O-AREA. segment read in and take EVALUATE STATUS-CODE WHEN 'GB' MOVE 'Y' TO EOJ-SW appropriate action. WHEN ' ' WHEN 'GA' WHEN 'GK' EVALUATE SEG-NAME-FB WHEN 'CUSTINFO' PERFORM PROCESS-CUST-INFO WHEN 'SHIPADDR' PERFORM PROCESS-SHIP-TO-ADDRESS WHEN 'BILLING' PERFORM PROCESS-BILLING WHEN OTHER PERFORM PROCESS-CASH END-EVALUATE WHEN OTHER PERFORM ERROR-END-OF-JOB END-EVALUATE EXIT.
(IPB1/4;2005.03)
Page 34
Retrieve calls
Program Execution
A batch program which uses IMS databases must be invoked from DFSRRC00, which is the batch initialization module for MVS.
When the program is link-edited, the language interface is linkage edited with the application program. This contains the entry points PLITDLI, CBLTDLI, ASMTDLI.
At execution time, DFSRRC00 must be told the target program name and the name of the PSB which will be used. Job control for execution //STEP EXEC PGM=DFSRRC00,PARM='DLI,progname,psb-name'
IIB-60
(IPB1/4;2005.03)
Page 35
Retrieve calls
Program Structure
So far, we have examined all of the basic components of an IMS (DL/1) program. We can now bring them all together and see how they are used in an actual program. COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. XXXXXXXX. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. data descriptions for call functions I/O area(s) SSAs LINKAGE SECTION. PCB mask(s) PROCEDURE DIVISION. ENTRY 'DLITCBL' USING PCB mask(s). . . CALL 'CBLTDLI' USING ............... check status code . . GOBACK.
PL/1
EXPROG:PROCEDURE(PCB-pointer(S)OPTIONS(MAIN); DCL PLITDLI ENTRY; declare PCB mask declare call functions declare I/O area(s) declare SSAs . . set PCB pointers to appropriate address CALL PLITDLI (..................); check status codes . . RETURN;
(IPB1/4;2005.03)
Page 36