To represent M:N relationship
in a hierarchical structure,
we must allow duplication of
child record instances.
HIERARCHICAL OCCURENCE TREE
The main concepts are:
Type indicators such as D, E, W. etc.
Descendent of a node
Subtree of a node
Level (0, 1, 2, etc.)
Hierarchical sequence
(used to linearize a tree)
Complete hierarchical path
(from root to a leaf)
Child pointer
Parent pointer
Twin pointer (sibling pointer)
For example, the following is the hierarchical schema of a company database:
The tree representation of the above hierarchical schema is shown below:
The two occurrences of the PCR type (DEPARTMENT and EMPLOYEE) are shown
in (a), and the two occcurrences of the PCR type (DEPARTMENT and PROJECT)
are shown in (b).
HIERARCHICAL SEQUENCE
The hierarchical schema for part of the COMPANY database is as shown:
The hierarchical occurrence tree of the hierarchical schema is as shown:
The hierarchical sequence for the occurrence tree is as shown:
VIRTUAL PARENT-CHILD RELATIONSHIPS
Gain in flexibility, loss in the
complexity (almost a network model)
IMS CONCEPTS
PDBR type
Use DBD to specify PDBR type
PDBR occurrence
LDBR type
DBD, PSB and PCB
Storage organization
How an application invokes IMS
IMS DATABASE EXAMPLE
The PDBR type is as shown:
The LDBR type is as shown:
To specify PDBR type, the DBD statements may look like:
1 DBD NAME=EDUCPDBD
2 SEGM NAME=COURSE,BYTES=256
3 FIELD NAME=(COURSE#,SEQ),BYTES=3,START=1
4 FIELD NAME=TITLE,BYTES=33,START=4
5 FIELD NAME=DESCRIPTN,BYTES=220,START=37
6 SEGM NAME=PREREQ,PARENT=COURSE,BYTES=36
7 FIELD NAME=(COURSE#,SEQ),BYTES=3,START=1
8 FIELD NAME=TITLE,BYTES=33,START=4
.....
To specify LDBR type, the DBD statements may look like:
1 PCB TYPE=DB.DBNAME=EDUCPDBD,KEYLEN=15
2 SENSEG NAME=COURSE.PROOPT=G
3 SENSEG NAME=OFFERING,PARENT=COURSE.PROOPT=G
4 NAME=STUDENT,PARENT=OFFERING,PROOPT=G
IMS QUERY EXAMPLES
(1) To retrieve the first occurrence of segment OFFERING whose
location is 'MADRID', we can use GET UNIQUE command,
GU COURSE
OFFERING (LOCATION='MADRID')
Where (LOCATION='MADRID')
is called the SEGMENT SEARCH ARGUMENT (SSA)
(2) To retrieve all the STUDENT segments for the COURSE OFFERING
in Madrid, we can use GET UNIQUE to get first segment, and GET NEXT to
retrieve subsequent segments.
GU COURSE
OFFERING (LOCATION='MADRID')
STUDENT
NS GN STUDENT
(This loop is terminated on segment not found)
GO TO NS
IMS QUERY EXAMPLES
(3) Similarly, to retrieve only grade 'A' students for course
offering in Madrid, we can add an SSA on STUDENT segment,
GU COURSE
OFFERING (LOCATION='MADRID')
NS GN STUDENT (GRADE='A')
(This loop is terminated on segment not found)
GO TO NS
(4) When no segment name is specified, GET NEXT can be used to
retrieve all segments.
GU COURSE
NS GN
(This loop is terminated when all segments are retrieved)
GO TO NS
IMS QUERY EXAMPLES
(5) To retrieve all child segments within a parent segment, we can
use GET NEXT WITHIN PARENT.
GU COURSE (COURSE#='M23')
OFFERING (DATE='730813')
NS GNP STUDENT
(This loop is terminated when all STUDENT segments
under same OFFERING segment are retrieved)
GO TO NS
(6) Similarly, we can retrieve all segments within a root segment,
as follows.
GU COURSE (COURSE#='M23')
NS GNP
(This loop is terminated when all segments under
root segment are retrieved)
GO TO NS
IMS QUERY EXAMPLES
(7) To perform insertion of a new segment, the new segment must be
present in I/O work area. Then the insertion command can be issued.
ISRT COURSE (COURSE#='M23')
OFFERING (DATE='730813')
STUDENT
(8) To delete a segment, the command GET HOLD is used to "hold" a
segment in work area, and then the DLET command can be issued.
GHU COURSE (COURSE#='M23')
OFFERING (DATE='730813')
DLET
(9) Similar commands are used for segment update.
GHU COURSE (COURSE#='M23')
OFFERING (DATE='730813')
(updated segment is in I/O work area)
REPL
MUMPS