Table of Contents
Database System Definition and Types Introduction to IMS IMS terminologies, organization, access methods Control Blocks (DBD and PCB) DBD - Definition, Functions and Macros PSB - Definition, Functions and Macros How to run application program using DL/I SSAs Qualified and Unqualified Command Codes DL/I Calls Status Codes
2
IMS Fundamentals
IMS Fundamentals
IMS Fundamentals
Types of DBMS
1. Hierarchical A hierarchical database is a kind of database management system that links records together in a tree data structure such that each record type has only one owner, e.g. an order is owned by only one customer. Hierarchical structures were widely used in the first mainframe database management systems. However, due to their restrictions, they often cannot be used to relate structures that exist in the real world.
IMS Fundamentals
The network model is a database model conceived as a more flexible alternative to the hierarchical model. Where the hierarchical model structures data as a tree of records, with each record having one parent record and many children, the network model allows each record to have multiple parent and child records, forming a lattice structure.
IMS Fundamentals
A relational database is organized into tables, in which data is defined so that it can be reorganized and accessed in a number of different ways without having to reorganize the database tables.
IMS Fundamentals
What is IMS?
IMS (Information Management System) is IBM's hierarchical database product
Hierarchical Data base management system that supports the application program while processing data bases in batch or on-line environments. IMS maintains an Inverted Tree Structure starting with the Root Segment by ensuring that no segment has more than one parent. The Hierarchy can go up to fifteen levels down. The Hierarchy can represent up to 255 segment types
IMS Fundamentals
IMS/DB2 program ?
DB2 program ?
IMS Fundamentals
Why IMS?
Advantages:
Large Volumes of Data can be handled Faster Access of Data Can be combined with DB2 for making data retrieval efficient (DB2 for querying and IMS for processing) Checkpoint restart feature available. Limitations: Not many tools for IMS compared to DB2 (File aid ~ file structure on pc) Rigid design of IMS doesnt make it programmer friendly
IMS Fundamentals
10
IMS Components
Five components of IMS Environment 1. Database Management System Is the heart of IMS subsystem. Shared by many concurrent tasks. Data is stored in DASD. Application programs access data by making DL/I calls. 2. DL/I (Data Language Interpreter) Is a set of program modules interfacing database and application program. The modules use standard operating system access methods and a set of specialized access methods to handle data transfers to and from the database. Is an interface language used by the application program.
IMS Fundamentals
11
IMS Fundamentals
12
Product Implementations
DC is used to implement the transaction manager DB is used to implement the database manager
IMS Fundamentals
13
MODEL
Child (dependent of dealer segment parent of order, stock, and sales Segments)
ORDER
STOCK
SALES
IMS Fundamentals
14
Illustration follows:
IMS Fundamentals
15
Cp SSE
Ed1
Ad1
Cp SE
Cp SSE
Ed1
Ad1
Bd 22345 67890
Ec1
Bd 12345 67890
Bd 12988 76890
Ec1
IMS Fundamentals
16
Explanation of diagram
The diagram shows how the data elements are arranged in IMS. Data elements are stored in the hierarchical structure or in other way we can say that some data elements are dependent on other. Each grouping of data is called as segments. A segment is the unit of data that DL/I transfers to and from your program. In previous diagram DEALER, MODEL, ORDER, STOCK and SALES are the names of segments.
IMS Fundamentals
17
Concept of Segments
In IMS, segments are defined by the order in which they occur and by their relationship with other segments.
The segment type at the top level of Hierarchy represents the Root segment. Like in the above case the DEALER represents the root segment.
An occurrence of the root segment plus all the segment occurrences subordinate to it makes one database record. All of the segments except the root segment are called dependent segments. Each dependent segment is also called the child segment.
IMS Fundamentals
18
IMS Fundamentals
19
IMS Fundamentals
20
IMS Fundamentals
21
Control Blocks
IMS uses two kinds of control blocks to enable application programs The database descriptor/definition (DBD) and Program communication block (PCB). Database Description (DBD)
A database descriptor (DBD) is a control block that describes the physical structure of the database. The DBD also defines the appearance and contents, or fields, that make up each of the segment types in the database. It describes the way in which it is stored on the DASD and the way it is accessed.
IMS Fundamentals
23
IMS Fundamentals
24
What is DL/I ?
IMS Fundamentals
25
DL/I
DATA BASE
DBD
PSB
APPLICATION PROGRAM
IMS Fundamentals
26
DL/I
DATABASE DATASET
IMS Fundamentals
27
IMS Fundamentals
28
Defining DBD
Suppose the ACCENTURE hierarchical structure has been designed. The name of the segments has been chosen. Now we must tell IMS about this database. IMS needs to know about all the keys, search fields, and relationships that are designed as part of the organization database.
The DBD is usually coded by a DBA (Data Base Administrator). It is then submitted to the system with JCL that invokes a procedure called DBDGEN. This procedure produces an object module which is in turn passed to the linkage editor which produces a load module. The load module is stored in a library named something like IMSVS.DBDLIB.
IMS Fundamentals
29
DBD Functions
Defines the physical storage information. Defines the hierarchical structure. Define the relationship between the segments. Defines the segment layouts. Defines the key field with in the segment. Describe the information necessary to create the database. Defines any logical relationship. Defines the secondary index.
IMS Fundamentals
30
IMS Fundamentals
31
END
IMS Fundamentals
32
IMS Fundamentals
33
IMS Fundamentals
34
IMS Fundamentals
35
Hands On - DBD
IMS Fundamentals
36
Describes the logical structure of one or more data bases to the application program
The logical data structure is defined by creating PSB
IMS Fundamentals
37
In order to execute in the IMS environment, a program must have a PSB that specifies all of the data bases and data base segments that the program may access.
IMS Fundamentals
38
IMS Fundamentals
39
SENSEG Defines the segment types to which the application program will be sensitive. A separate SENSEG statement is required for each segment type. If a segment is defined as sensitive, all the segments in the path from the root to that segment must also be defined as sensitive.
IMS Fundamentals
40
IMS Fundamentals
41
IMS Fundamentals
42
L/LS -
Secondary PROCOPT codes are as follows: E O P S exclusive use of hierarchy or segments get only, does not lock data when in use must be used if program will issue path call using the D command code sequential (LS is required to load HISAM and HIDAM databases; GS gets in ascending sequence)
43
IMS Fundamentals
PCB
IMS Fundamentals
44
SENSEG
PSBGEN END
NAME=EMPLOYEE,PARENT=PROJECT, PROCOPT=A
LANG = COBOL,PSBNAME=ORGAN
IMS Fundamentals
45
Hands On - PSB
IMS Fundamentals
47
The order in which the PCB masks appear in the Entry Statement is important, the linkage section PCB-Mask's can be in any order. GOBACK instead of STOP RUN.
IMS Fundamentals
49
10 PCB-LKF-DB1
IMS Fundamentals
--> Name of Database --> Level of last successful call PIC X(02). --> Status Code PIC X(04). --> PROCOPT from PSB PIC S9(5) COMP. --> Reserved for DL/I PIC X(08). --> Last Segment Successfully retrieved in a call PIC S9(5) COMP. --> Length of Concatenated Key
50
IMS Fundamentals
51
IMS Fundamentals
52
IMS Fundamentals
53
LEFT PAREN (OR SPACE) - If left blank, the SSA will be an unqualified SSA.
IMS Fundamentals
55
KEY FIELD VALUE - This is the value of the field that will be processed. RIGHT PAREN - This statement is used to indicate the end of the SSA.
IMS Fundamentals
56
DL/I Calls
The purpose of a DL/I call is to instruct DL/I to perform a certain action involving the data stored in the IMS database. A DL/I call includes four parts : CALL FUNCTION - Tells DL/I what needs to be done (for example, retrieve, update, insert, delete). PCB - Gives the name of the PCB of the database that will be referenced by the call. I/O AREA - Specifies the work area for the requested segment. SSA - Specifies the segment and path of the data to be accessed.
IMS Fundamentals
58
IMS Fundamentals
59
IMS Fundamentals
60
Retrieval calls
GU (Get Unique) GN (Get Next) Gets the first segment which matches the qualifiers Gets the next segment in hierarchic order which matches the qualifiers in the call
GNP (Get Next Within Parent) Gets the next segment under the current parent which matches the qualifiers specified in the call GHU (Get Hold Unique) GHN (Get Hold Next) GHNP (GHN Within Parent)
IMS Fundamentals
Same as GU, but locks the segment for subsequent update (DLET or REPL) Same as GN, but locks the segment for subsequent update (DLET or REPL) Same as GNP, but locks the segment for subsequent update (DLET or REPL)
61
Update calls
ISRT (Insert) REPL (Replace) To insert a segment in the database To replace an existing segment with new data (The key to segment can not be changed, and previous 'GET HOLD' command must be issued) To delete an existing segment from the data base (The previous 'GET HOLD' command must be issued)
DLET (Delete)
IMS Fundamentals
62
Miscellaneous Calls
CHKP To take a 'check point' or 'commit updates to the database before the program terminates. To restore the database position after a check point has been taken To schedule a PSB in an on-line program To terminate a PSB in an on-line program
XRST
PCB TERM
IMS Fundamentals
63
Command Codes
Command Codes in a SSA makes the call powerful since DL/I treats such SSAs differently from those without the command codes while performing some special functions. Command codes save programming and processing time. Command codes are specified in an SSA following the segment name and an Asterisk *. * in the ninth position in a SSA indicates that one or more command codes follow the * and 10th position will be reserved for the command code. 11th position will be for the left parenthesis (. A Blank or Left parenthesis marks the end of the command codes.
IMS Fundamentals 64
Command Codes
(Contd..)
ONE or MORE command codes can be used in any combination using relational operators like &. Command Codes are codes specified in the SSAs that help to optimize the performance of IMS programs and leads to Simplified Coding. Command Codes extend the functionality of DL/I calls. Multiple DL/I calls can be reduced to a single DL/I call by using Command Codes. If we dont need to use Command Codes while processing we can override the existing command code in the program (before the call where SSA is used) by passing/using the NULL (-) Command Code.
IMS Fundamentals
65
Command Codes
(Contd..)
Concatenated key in the SSA. Retrieve this segment data into the I-O Area (Path call). Locate the first segment occurrence that satisfies the SSA. Locate the last segment occurrence that satisfies the SSA. Do not replace this segment. Locks a segment for your program's exclusive use.
66
Command Codes
U
(Contd..)
Specify the current database positions at that level is not allowed to be changed by the call
P
V
'NULL Used as the place holder in SSA's so that command codes can be removed/inserted from SSA's without having to define separate SSA's in working storage.
IMS Fundamentals
67
01 Employee-Bankdetl-SSA. 05 Filler pic x(11) value EMPLOYEE*C(. 05 Employee-SSA-empno pic x(06) value spaces. 05 Compdtl-SSA-desg pic x(02) value spaces. 05 Bankdtl-SSA-acctno pic x(10) value spaces. 05 Filler pic x value ). 01 Bankdtl-IO-area pic x(21). . . Procedure Division. Pass the key values to empno, desg and account no. before the call. Call CBLTDLI Using DLI-GU PCB-Mask Employee-Bankdetl-SSA Bankdtl-IO-area
IMS Fundamentals 68
01 Employee-SSA. 05 Filler pic x(11) value Employee*D(. 05 Filler pic x(10) value Emplno =. 05 empl-no pic x(06). 05 Filler pic x value ). 01 Compdtl-SSA. . 01 Bankdtl-SSA. . 01 Path-Call-IO-area. 05 emp-io-area pic x(56). 05 comp-io-area pic x(12). 05 bank-io-area pic x(11). Procedure Division. Call CBLTDLI using
IMS Fundamentals
69
11000000 10000009
MOVE 100000009
PROJ0002
EMP00002 EMP00003
IMS Fundamentals
70
10000000 10000009
PROJ0001 PROJ0002
IMS Fundamentals
71
11000000 10001009
PROJ0001 PROJ0002
IMS Fundamentals
72
VALUE EMPLOYEE .
PROJ0001 PROJ0002
IMS Fundamentals
73
GU MISSING - SSAS
01 LOCATE-QSSA. 05 F PIC X(9) VALUE LOCATION . GU-FUNCTION ORGAN-PCB-MASK PROJECT-SEGMENT PROJECT-USSA CALL CBLTDLI USING
PROJ0001 PROJ0002
EMPLOYEE-USSA.
IF ORGAN-PCB-STATUS = bb CONTINUE ELSE PERFORM error-routine.
IMS Fundamentals
74
GU NO - SSAS
11000000 10001009
CALL CBLTDLI USING GU-FUNCTION ORGAN-PCB-MASK LOCATE-SEGMENT
PROJ0001 PROJ0002
IF ORGAN-PCB-STATUS = bb
CONTINUE ELSE PERFORM error-routine.
IMS Fundamentals
75
11000000 10000009
PROJ0001 PROJ0002
TO LOCATE-KEY LOCATE-OP
ELSE
PERFORM error-routine.
IMS Fundamentals 76
GN - Unqualified SSA
11000000 10001009
01 LOCATE-QSSA. 05 F PIC X(9) VALUE EMPLOYEE . ORGAN-PCB-MASK CALL CBLTDLI USING GU-FUNCTION
PROJ0001 PROJ0002
CONTINUE
IMS Fundamentals
77
CALL CBLTDLI USING GN-FUNCTION ORGAN-PCB-MASK EMPLOYEE-SEGMENT LOCATION-QSSA PROJECT-QSSA EMPLOYEE-USSA. IF LOCATE-PCB-STATUS = bb
PROJ0001 PROJ0002
CONTINUE
ELSE PERFORM error-routine.
IMS Fundamentals
78
PROJ0001 PROJ0002
IF LOCATE-PCB-STATUS = bb OR GA OR GK
CONTINUE
ELSE PERFORM error-routine.
IMS Fundamentals
79
VALUE EMPLOYEE .
PROJ0001 PROJ0002
IMS Fundamentals
80
PROJ0001 PROJ0002
PERFORM 1500-GNP-PROJECT
UNTIL ORGAN-PCB-STATUS = GE
ELSE PERFORM ERROR-ROUTINE 1500-GNP-PROJECT. CALL CBLTDLI USING GNP-FUNCTION ORGAN-PCB-MASK SUPPLIER-SEGMENT PROJECT-USSA
IMS Fundamentals
81
ISRT Calls
Inserts a new segment occurrence. Before issuing the call, you must populate the I/O area for the new segment. The I/O area must contain the same fields in the same order, length, and data types that exist on the segment being inserted. ISRT Calls are used to add segments to a DL/I database either during the update processing of new segments or during the load operation. ISRT calls can use qualified or unqualified SSA s, E.g. Of ISRT Call using an unqualified EC SSA, make sure of the pointer before unqualified call.
IMS Fundamentals
82
ISRT Calls
(Contd..)
DL/I will try to execute this call by inserting the EC occurrence in the Database based on the current position in the database CALL 'CBLTDLI' USING CN-ISRT PCB-MASK1 WK-OUTPUT-REC WS-UNQUAL-EC-SSA
E.g. Of ISRT Call using a qualified call CALL 'CBLTDLI' USING CN-ISRT PCB-MASK1 WK-OUTPUT-REC WS-QUAL-EMP-SSA WS-QUAL-CP-SSA WS-UNQUAL-BD-SSA
83
IMS Fundamentals
ISRT Calls
(Contd..)
DL/I will try to execute this call by inserting the BD occurrence in the Database based on the position obtained from the QUAL-EMP segment occurrence and the QUAL-CP segment occurrence.
DL/I returns status code GE if the segment occurrence mentioned using the qualified SSA s is not found.
When the lower level segment types in a database have non unique sequence fields or dont have any sequence fields then the ISRT works based on RULES specified in the DBD. RULES = FIRST, the new segment occurrence is inserted before all existing twins
RULES = LAST, the new segment occurrence is inserted after all existing twins
IMS Fundamentals 84
ISRT Calls
(Contd..)
RULES = HERE, the new segment occurrence is inserted at the current position in the database
The RULES mentioned in the DBD can be overridden by Command Code RULES = FIRST can be overridden by coding Command Code L in SSA However RULES = LAST, CANNOT be overridden by coding Command Code F The D Command Code can be specified to insert more than one segment occurrence types along a path
IMS Fundamentals
85
ISRT Calls
(Contd..)
When D Command Code is being used for insert, the PROCOPT=P should be specified in the PSB. For Load operation, all segments must be inserted in hierarchical sequence. Also the PSB must have PROCOPT = L or LS.
The Status Code GE during ISRT calls happen when the segment occurrence being inserted with Qualified SSA s is not present in the database.
IMS Fundamentals
86
ISRT Calls
(Contd..)
The Status Code II during ISRT calls happen when we try to add a segment occurrence thats already present in the database The Status Code LB during ISRT calls in LOAD operation happen when we try to add a segment occurrence thats already present in the database. The Status Code LC during ISRT calls in LOAD operation happen when the input data is not in hierarchical sequence. The Status Code LD during ISRT calls in LOAD operation happen when one or more segments in the path to the segment being loaded are missing.
The Status Code LE during ISRT calls in LOAD operation happen when the sequence of segment types isnt the same as that specified in the DBD
IMS Fundamentals
87
II The segment already exists in the database. A duplicate key value is being inserted into.
IX Encountered an Insert Rule Violation. Program tried to insert a segment into the wrong place. For e.g. A stock segment is being inserted under the Dealer segment, when it is in fact dependant upon the Model segment.
IMS Fundamentals
88
LB When you try to load the same segment twice i.e. segment already exists LC The segments being loaded are not in their Hierarchical sequence i.e. key values out of sequence LD No Parent for the segments being loaded. You cannot load a dependant segment until its parent has been loaded LE Segment types out of sequence. For e.g. If you tried to load a stock segment before a model segment
IMS Fundamentals
89
REPL Calls
Replaces current data in a selected segment with new data from the I/O area. It must be preceded by a GHU, GHN, or GHNP call. A REPL generally does not use an SSA. The segments key fields cannot be changed. There are two restrictions for REPL Calls Cannot change the length of the Segment Cannot change the value of the Sequence Field Never Code a qualified SSA on a REPL Call. Replace processing can be done with Path Calls.
IMS Fundamentals 90
REPL Calls
(Contd..)
For Replace operation with Path Calls, we can negate replacement of certain intermediate segment occurrences by giving Command Code N
REPL Calls
(Contd..)
The above call will first retrieve a tax occurrence, make some changes to it and then replace it using REPL call .
IMS Fundamentals
92
REPL Calls
(Contd..)
The Status code AJ happens when we try to use Qualified SSA on a REPL Call The Status Code DJ happens when a GHU or GHN call doesnt precede the REPL Call The Status Code DA happens when the program tries to make change to the Segment Key field before giving REPL call
IMS Fundamentals
93
IMS Fundamentals
94
DLET Calls
Deletes the segment previously retrieved and all of its dependents, even if the application is not defined as sensitive to them. It must be preceded by a GHU, GHN, or GHNP call (see GET HOLD Calls). Deletes generally do not use SSAs. Works similar to a REPL call, a Get Hold Call should be given first followed by a DLET call. Never code a qualified SSA with DLET call.
Unqualified SSA s can be coded in a DLET call when we are using Path Calls (Command Code D, since the pointer position is known)
IMS Fundamentals 95
DLET Calls
(Contd..)
A DLET Path Call will delete the entire path. The scope of a Path Delete can however be limited by supplying one unqualified SSA without a command code, such calls should be avoided unless sure of the pointer position.
The Status code AJ happens when we try to use Qualified SSA on a DLET Call.
The Status Code DJ happens when a GHU or GHN call doesnt precede the DLET Call. The Status Code DA happens when the program tries to make change to the Segment Key field before giving DLET call.
IMS Fundamentals 96
IMS Fundamentals
97
AK AT AO
IMS Fundamentals
98
IMS Fundamentals
99
IMS Fundamentals
100
Checkpoint Restart
Why checkpointing? If there are other jobs updating or reading the tables, there should be a checkpoint at an interval < the DB2 timeout interval (typically 30 seconds will suffice). When A large amount of locking activity is taking place. Locks are a finite resources in a DB2 Subsystem. When we do not want to lose work already accomplished. If a job runs a long time, recovery is not just re-running the job, but also waiting for DB2 to roll back changes. Checkpoint intervals are based on the situation. For example, if online activity is present, or we are running parallel processes, checkpoints should be taken at 10 second intervals. If we are running stand alone batch, and have exclusive access to our tables, we might go as high as 60 seconds.
101
IMS Fundamentals
IMS Fundamentals
IMS Fundamentals
103
Evaluate status-code when not space display Restart failed! when space perform xxxx-reformat-data end-evaluate.
IMS Fundamentals
104
ROLL Call:
When issued, the program is Abnormally Terminated with a user abend Code of 0778. It can be issued in a Batch program as CALL CBLTDLI USING ROLL The only parameter specified in the call is the function.
IMS Fundamentals
105
Exercises
Assume there is a Hospital database with the below segments WARD WARD_NO TOT_ROOMS TOT_BEDS WARD_TYPE Unique Key
Unique Key
IMS Fundamentals
106
Exercises (Contd..)
DOCTOR DOC_NAME DOC_ADDR DOC_PHONE DOC_SPL PIC X(20) PIC X(50) PIC X(10) PIC X(15)
Assume the following data is available in the database: WARD Segment: 101, 20, 25, F 102, 10, 22, G 103, 30, 45, M
IMS Fundamentals
107
Exercises (Contd..)
PATIENT Segment: 1001, PAUL, 101/B OAK WOOD NY, 41278906 1231, SIMPSON, 123/C JOHN STREET NJ, 4177231 1231, CATHY, 77-Y WINSTON ROAD ATLANTA, 7634211 1001, PAUL, 101/B OAK WOOD NY, 41278906 DOCTOR Segment: SAMUEL, 11-9 KENNEDY ST CAL, 890076, ORTHO RANDY, 15/A PERKIN HALL IN, 77886611, DENTIST
IMS Fundamentals
108
Exercises (Contd..)
1.
2. 3.
1231, SIMPSON, 123/C JOHN STREET NJ, 4177231 With 1231, SIMPSON, 123/B GEORGE STREET NJ, 4177231
IMS Fundamentals
109
Exercises (Contd..)
4. Write a DLET call to delete the WARD record.
IMS Fundamentals
110
IMS Fundamentals
111