Mainframes 360
The one stop destination for System Z professionals

Tuesday, November 2, 2010

Introduction to IMS/DB

Q. What is IMS/DB?
IMS(Information Management System) is the Hierarchical-Data Management System from IBM. When hierarchical data-structures are implemented using Flat-Files, it is the responsibility of Application-Programmers to ensure that it works flawlessly. Why storing huge-volumes of data having hierarchical-relationship in Flat-Files is a bad idea? Let's say, a list of Employees and the Departments in which they work – this Data is stored in Flat Files.

image

The Departments Data is stored in DEPARTMENT File. The record-layout of the DEPARTMENT File is shown in the picture above. Every Department has a DEPARTMENT-ID, that uniquely identifies the Department. Moreover, a Department has a DEPARMENT-NAME and the total number of employees working under that department are recorded in DEPARTMENT-STRENGTH.

image

Every Department of the company has several Employees working under it. The Employees data is stored in EMPLOYEE File. The snap above shows its record-layout. Each Employee is identified by Unique EMP-KEY, consisting of EMP-ID and DEPT-ID. The Employee's name EMP-NAME is further broken down in FNAME, MNAME and LNAME. The Employee’s Joining Date is stored in EMP-JDATE. This hierarchical relationship between DEPARTMENT File and EMPLOYEE File is depicted in the picture below.

   image

However, there are certain problems with this design.

1. Maintaining Data Consistency - For instance, if the Program adds a new Employee-Record, that has no DEPT-ID, no corresponding department, the DEPARTMENT and EMPLOYEE Files will no longer be synchronized. And the same is true, if a Department-Record is deleted, when active Employees work for that Department. These Employee-Records are orphaned out.

2. COBOL Program and Data Dependency – Because the structure of the Data(File Layout) is hard-coded or embedded in the COBOL Program accessing the data, whenever the data's structure changes(say you add one more field to the DEPARTMENT File), the COBOL Program has to be re-written and re-compiled all over again. The Program heavily depends on the Data.

When you use IMS/DB for storing data, difficulties like these don't come up. That's because the hierarchical relationships between data is now taken care of by IMS. IMS would use a single file for storing DEPARTMENT and its EMPLOYEE's data. The structural information is stored in IMS.
Q. What is meant by Segment-Type, Segment-Occurrence and Levels in IMS?
In IMS/DB, when data is stored about any real-world thing, you call it a Segment. For example, if you record information about Employees, Employee is one-Segment. Because you would be storing  Departments is another segment. In IMS Jargon, I would call them DEPARTMENT Segment and EMPLOYEE Segment.

I'll introduce two new terms as well – Segment Type and Segment Occurrence. A segment-type is one category or class of data. For example, DEPARTMENT Segment-Type. Each instance of a Department is called a Segment-Occurrence. For example, you may have 3 segment-occurrences HR, MARKETING and FINANCE of the Segment-Type DEPARTMENT. Bear in mind, there can be only one segment-type of a particular kind, but infinite occurrences of it.

An IMS Hierarchical-Database can be looked upon as an inverted-tree. The Height of the Tree tells you the number-of-levels in the Tree.

  image

This Hierarchical-database has two Levels.
Q. What is meant by Root-Segment and Database Record?
In an IMS Hierarchical-Database, the segment-type at the top of the hierarchy-tree is called the Root-Segment. For example, in the below database, the DEPARTMENT-Segment is called the Root-Segment.

      image
Suppose the DEPARTMENT Segment-type has 3 segment-occurrences HR, Marketing and Finance. Each of these Department segment-occurrences have Employee Segment-occurrences subordinate to them. HR Department has 2 sub-ordinate Employee Segment-Occurrences RAM and RAJ. Marketing Department has 3 sub-ordinate Employee-Segment occurrences RAKESH, RAVI and RAJESH. Finance Department has 2 sub-ordinate Employee Segment-occurrences ROMEO and ROY.

  image
One root segment-occurrence e.g. HR plus all the segment-occurrences sub-ordinate to it for example RAM and RAJ, together constitute one
Database-Record. Thus, here there are 3 database-records, one for each root segment-occurrence. In all, there are 10 segment-occurrences in this IMS Database.
Q. What are dependent, parent and Child and twin Segments?
All the segments in an IMS Hierarchical DB, other than the Root-Segment are called Dependent-Segments. DEPARTMENT Segment is called Parent-Segment and EMPLOYEE Segment is its Child-Segment.

The term Twin segments is applicable to Segment-Occurrences. Two children with same parent segment-occurrence are called twins. For example, RAKESH and RAVI are child of the same parent segment occurrence Marketing Department, so they are called Twin-Segments.
Q. How data is accessed in an IMS Hierarchical Database?
Data can be accessed in two-ways from an IMS-DatabaseSequential and Random mode of access. When you access data from IMS DB Sequentially, you read it record-by-record. Within each record, the segments are accessed in the following general pattern : Top-to-Bottom, Left-to-Right.

First, a root segment-occurrence is retrieved. Then, IMS DB digs as far deep as possible, right at the bottom, until it reaches the lowest level Segment-Occurrence. It then retrieves all the twin segment-occurrences at that level. Once, all the Twin Segments have been fetched, IMS moves back up in the hierarchy and retrieves any twins of the Parent. This process continues, till all the Database Records have been retrieved. So, the sequence in which the Data is fetched is HR-RAM-RAJ, MARKETING-RAKESH-RAVI-RAJESH and FINANCE-ROMEO-ROY.

  image

Random-Access to Data in a Hierarchical-Database is possible by supplying a concatenated-Key. Every Segment can have a Key-Field(or Sequence Field). For example, DEPARTMENT-ID may be a Key-Field of DEPARTMENT Segment. EMPLOYEE-ID would be Key-Field of Employee-Segment. A Concatenated-Key is formed by combining the Key-Fields of different segment-types  e.g.(DEPARTMENT-ID,EMPLOYEE-ID). This way you can jump or skip  directly to any particular Segment-Occurrence under any Database Record.

To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.