IMS DB — Hierarchical Database Complete Guide
In this tutorial, you'll learn about IMS DB. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
IMS DB (Information Management System Database) is IBM's hierarchical database management system for mainframes, organizing data in parent-child segment trees for high-speed Transaction processing with unparalleled reliability.
What You'll Learn
- The hierarchical database model and how it differs from relational
- IMS segments, PCB, and DL/I — the key building blocks
- How to write COBOL programs that query and update IMS databases
- Real-world telecom and banking use cases
Why IMS DB Matters
IMS has been running continuously since 1968 — over 55 years. It processes billions of transactions daily in banking, telecom, and government systems. Most people don't realize that every time they make a phone call or complete a wire transfer, IMS is likely involved. It is the most battle-tested database system ever built.
Durga Antivirus Pro applies IMS-style hierarchical threat classification in its malware analysis engine. Doda Browser uses segment-based Caching inspired by IMS's hierarchical data model.
Learning Path
flowchart LR A[z/OS Guide] --> B[VSAM Complete Guide] B --> C[IMS DB
You are here] C --> D[DB2 for z/OS] D --> E[CICS Transaction Processing]
What Is a Hierarchical Database?
Imagine a family tree. One parent (a customer) has multiple children (accounts), and each child has their own children (transactions). That's a hierarchical database.
Unlike relational databases with flat tables and JOINs, IMS stores data as segments in a tree. Each segment type has:
- A parent segment above it (except the root)
- Zero or more child segments below it
- Twin segments — siblings of the same type
Segment Structure Example
CUSTOMER (root segment)
├── ACCOUNT (child of CUSTOMER)
│ ├── TRANSACTION (child of ACCOUNT)
│ └── TRANSACTION (twin — another transaction)
├── ACCOUNT (twin — another account)
│ └── TRANSACTION
└── ADDRESS (child of CUSTOMER)
To find all transactions for an account, IMS traverses: CUSTOMER → ACCOUNT → Transaction. No JOIN needed — the hierarchy is the relationship.
Key IMS Concepts
| Concept | Description | Analogy |
|---|---|---|
| Segment | A data record with fields | A row in a table |
| Segment Type | The template for a segment | A table definition |
| Parent | Segment above in hierarchy | A folder containing files |
| Child | Segment below in hierarchy | A file inside a folder |
| Twin | Sibling of the same type | Multiple files in the same folder |
| PCB | Program Communication Block | A database handle |
| DL/I | Data Language/I — the access language | SQL for IMS |
DL/I Calls — How Programs Access IMS
Instead of SQL, IMS programs use DL/I calls — special COBOL statements that navigate the hierarchy.
Key DL/I Calls
| Call | Purpose |
|---|---|
| GU (Get Unique) | Retrieve a specific segment by key |
| GN (Get Next) | Read the next segment in hierarchy |
| GNP (Get Next within Parent) | Read next segment under current parent |
| ISRT (Insert) | Add a new segment |
| DLET (Delete) | Remove a segment |
| REPL (Replace) | Update a segment |
Anatomy of a DL/I Call
CALL 'CBLTDLI' USING GU
PCB-ADDRESS
SEGMENT-IO-AREA
ROOT-SSA
CHILD-SSA.
Explanation: CBLTDLI is the interface module. GU is the function code. The PCB tells IMS which database to use. The SSA (Segment Search Argument) specifies which segment to retrieve and with what key.
Writing a COBOL Program to Read IMS
Here's a COBOL program that reads a customer's account and their transactions:
IDENTIFICATION DIVISION.
PROGRAM-ID. IMSREAD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PCB-ADDRESS PIC X(4).
01 CUST-SEG.
05 CUST-ID PIC X(6).
05 CUST-NAME PIC X(30).
01 ACCT-SEG.
05 ACCT-NUM PIC X(8).
05 ACCT-TYPE PIC X(2).
05 ACCT-BAL PIC 9(7)V99.
01 TXN-SEG.
05 TXN-DATE PIC X(8).
05 TXN-AMT PIC 9(7)V99.
05 TXN-TYPE PIC X(1).
01 ROOT-SSA.
05 SSA-NAME PIC X(8) VALUE 'CUSTOMER '.
05 FILLER PIC X(1) VALUE '('.
05 SSA-KEY PIC X(20).
05 FILLER PIC X(1) VALUE ')'.
01 STATUS-CODE PIC X(2).
PROCEDURE DIVISION.
ENTRY 'DLITCBL' USING PCB-ADDRESS.
MOVE '1001' TO SSA-KEY.
CALL 'CBLTDLI' USING GU
PCB-ADDRESS
CUST-SEG
ROOT-SSA.
MOVE PCB-STATUS TO STATUS-CODE.
DISPLAY 'CUSTOMER: ' CUST-NAME.
DISPLAY 'ID: ' CUST-ID.
CALL 'CBLTDLI' USING GN
PCB-ADDRESS
ACCT-SEG.
DISPLAY 'ACCOUNT: ' ACCT-NUM.
DISPLAY 'BALANCE: ' ACCT-BAL.
STOP RUN.
Expected output:
CUSTOMER: Jane Doe
ID: 1001
ACCOUNT: 40020001
BALANCE: 000125000
Hierarchical vs Relational
| Feature | IMS DB | DB2 |
|---|---|---|
| Data model | Hierarchical (tree) | Relational (tables) |
| Access method | DL/I calls (GU, GN, ISRT) | SQL (SELECT, INSERT) |
| Relationship | Physical parent-child pointers | Foreign keys + JOINs |
| Best for | High-volume OLTP, deterministic paths | Complex queries, ad hoc reporting |
| Learning curve | Steep — requires understanding the hierarchy | Moderate — widely taught |
Real-World Use: Telecom Call Records
Telecom companies use IMS to store call detail records (CDRs). The hierarchy might be:
SUBSCRIBER (phone number as key)
├── CALL_RECORD
│ ├── CALL_DETAIL (start time, duration)
│ └── CHARGING (rate, tax, total)
├── CALL_RECORD
│ └── ...
└── SUBSCRIPTION_PLAN
When a call is made, IMS inserts a CALL_RECORD segment under the SUBSCRIBER in milliseconds. Millions of CDRs are inserted daily with 99.999% availability.
Common Errors
1. PCB Status Code 'GE' — Segment Not Found
The GU call couldn't find the segment. Check that the key value matches an existing root segment.
2. PCB Status Code 'GA' — Hierarchy Mismatch
Your program tried to access a child segment without first establishing a parent. Always issue GU on the root before GNP on children.
3. PCB Status Code 'LB' — Deadlock
Two programs are competing for the same segments. IMS detects this and rolls back one Transaction. Implement retry logic.
4. PCB Status Code 'II' — Invalid SSA
The Segment Search Argument has a syntax error. Verify SSA format: SEGMENTNAME(keyfield = value).
5. DL/I call with wrong PCB
Each database needs its own PCB. Passing the wrong PCB causes unpredictable results. Verify PCB order matches the PSBGEN.
6. Forgetting to initialize SSA
Uninitialized SSA fields contain garbage that IMS treats as key criteria. Always clear SSA before building search arguments.
7. Not checking PCB status after every call
Assume nothing. After every DL/I call, check the status code field. Ignoring it is the most common source of production bugs.
Practice Questions
What is the difference between GU and GN in DL/I? GU (Get Unique) retrieves a specific segment using key equality. GN (Get Next) returns the next segment in hierarchical sequence, regardless of key.
What does a PCB (Program Communication Block) do? It establishes the interface between the COBOL program and the IMS database, defining which database is accessed and containing the status code after each DL/I call.
How does IMS handle concurrent access? IMS uses segment-level locking. When one program reads a segment, other programs cannot modify it until the first program commits its Transaction.
Why would you choose IMS over DB2? IMS offers predictable, deterministic performance for known access paths (customer → account → Transaction). For high-volume OLTP with simple, fixed access patterns, IMS is faster than DB2.
What is a twin segment? A twin is another segment of the same type under the same parent. For example, multiple ACCOUNT segments under one CUSTOMER segment.
Challenge: Design an IMS hierarchy for an e-commerce order system. Include customer, shipping address, payment method, order header, order line items, and shipment tracking segments. Write the GU calls to retrieve all orders for a given customer.
Mini Project: IMS Balance Inquiry System
Build a COBOL program that accepts a customer ID, retrieves the customer name, lists all accounts with their balances, and displays the total combined balance.
IDENTIFICATION DIVISION.
PROGRAM-ID. BALINQ.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PCB-ADDRESS PIC X(4).
01 CUST-SEG.
05 CUST-ID PIC X(6).
05 CUST-NAME PIC X(30).
01 ACCT-SEG.
05 ACCT-NUM PIC X(8).
05 ACCT-TYPE PIC X(2).
05 ACCT-BAL PIC 9(7)V99.
01 ROOT-SSA.
05 FILLER PIC X(8) VALUE 'CUSTOMER '.
05 FILLER PIC X(1) VALUE '('.
05 SSA-KEY PIC X(20).
05 FILLER PIC X(1) VALUE ')'.
01 WS-TOTAL-BAL PIC 9(9)V99 VALUE 0.
01 WS-STATUS PIC X(2).
01 WS-ACCT-COUNT PIC 9(2) VALUE 0.
PROCEDURE DIVISION.
ENTRY 'DLITCBL' USING PCB-ADDRESS.
DISPLAY 'ENTER CUSTOMER ID: '.
ACCEPT CUST-ID.
MOVE CUST-ID TO SSA-KEY.
CALL 'CBLTDLI' USING GU
PCB-ADDRESS
CUST-SEG
ROOT-SSA.
IF PCB-STATUS NOT = ' '
DISPLAY 'CUSTOMER NOT FOUND'
STOP RUN.
DISPLAY 'CUSTOMER: ' CUST-NAME.
PERFORM UNTIL WS-STATUS = 'GE'
CALL 'CBLTDLI' USING GNP
PCB-ADDRESS
ACCT-SEG
IF WS-STATUS = ' '
ADD ACCT-BAL TO WS-TOTAL-BAL
ADD 1 TO WS-ACCT-COUNT
DISPLAY ACCT-NUM ': ' ACCT-BAL
END-IF
END-PERFORM.
DISPLAY 'TOTAL ACCOUNTS: ' WS-ACCT-COUNT.
DISPLAY 'TOTAL BALANCE: ' WS-TOTAL-BAL.
STOP RUN.
Expected output:
ENTER CUSTOMER ID: 1001
CUSTOMER: Jane Doe
40020001: 000125000.00
40020002: 000045000.00
40020003: 000500000.00
TOTAL ACCOUNTS: 3
TOTAL BALANCE: 000670000.00
FAQ
What's Next
| Tutorial | What You'll Learn |
|---|---|
| DB2 for z/OS Complete Guide | Master relational databases on the mainframe with SQL |
| CICS Transaction Processing Guide | Build online Transaction processing applications |
| VSAM Complete Guide | Master indexed file access methods on z/OS |
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Updated 2026-06-21.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro