Hierarchical data: segments, DBDs and PSBs
An IMS database is a tree. Each record starts with a root segment, with child segments hanging beneath it. The DBD describes the tree; a PSB describes which parts a particular program may see and how it may use them.
Segments instead of rows
Where DB2 stores rows in tables and joins them, IMS stores segments in a fixed parent-child structure. One database record is a root segment plus all its dependents.
- Parent and child: ACCOUNT is a child of CUSTOMER; TRANSACT is a child of ACCOUNT.
- Twins: several ACCOUNT segments under the same CUSTOMER are twins.
- Hierarchical sequence: IMS visits segments top to bottom, left to right, front to back. A 'get next' call follows this order.
The DBD: what the database looks like
A DBD (database description) defines the segments, their fields, which fields are keys, and how the database is stored. It is generated by a DBA with the DBDGEN utility.
| Access method | In short |
|---|---|
| HDAM / PHDAM | Root segments found by hashing the key; fast direct access |
| HIDAM / PHIDAM | Root segments found through an index; supports sequential processing by key |
| HISAM | Indexed sequential; mostly older or special-purpose databases |
| DEDB | Fast Path data entry database for very high volume and availability |
The 'P' versions are HALDB (High Availability Large Database), which split a large database into partitions that can be reorganised and recovered separately.
The PSB: what a program may see
A program does not see the whole database. Its PSB (program specification block) contains one PCB per database it uses, listing the sensitive segments (SENSEG) it can access and a processing option (PROCOPT) such as G (get), I (insert), R (replace), D (delete) or A (all).
PCB TYPE=DB,DBDNAME=CUSTDB,PROCOPT=G,KEYLEN=20 SENSEG NAME=CUSTOMER,PARENT=0 SENSEG NAME=ACCOUNT,PARENT=CUSTOMER PSBGEN LANG=COBOL,PSBNAME=CUSTINQ
This read-only program can see customers and accounts but not transactions or addresses. Online programs also receive an I/O PCB for exchanging messages with the terminal or client. Before use, DBDs and PSBs are combined into application control blocks (ACBs).
Common mistakes
IMS paths are fixed by the DBD. To reach TRANSACT you go through CUSTOMER and ACCOUNT. Design and read programs along the hierarchy.
If a segment is not a SENSEG in your PCB, it simply does not exist for your program.
Database structure changes need DBDGEN, related PSBGENs and an ACB generation, coordinated by the DBA.
What you will see at work
- When you get an IMS change, the first documents to ask for are the DBD and your program's PSB.
- DBAs schedule reorganisations of HALDB partitions separately, which keeps the rest of the database available.
- Many shops keep diagrams of their IMS hierarchies because the shape drives every program.
Key terms
Check your understanding.
Take this lesson's quiz and save your progress. Free.