Ims DB2
Ims DB2
Ims DB2
• Database is a collection of
related datas.
• Storing and control of business
Data (or) Information (or)
Record
• The data independent from one
or more applications programs.
• The data can be centrally
controlled and managed.
DATABASE TYPES
1. Network Database
2. Relational Database
3. Hierarchical Database
NETWORK DATABASE
• In NDBMS, Entity is
said to be a SET.
• Collection of SET’s
forms a Network
Database.
• Interconnection of
each and every SET’s
produces NDBMS
Structure.
NETWORK STRUCTURE
In this structure,
A, B,C & D are SET’s.
Relationship is Many to
Many (M : N) A
Adv : Every Set is linked
together. So we can
B
easily Retrieve C
the Complete details.
D
RELATIONAL DATABASE
• In RDBMS, Entity is
said to be a TABLE.
• Collection of TABLE’s
forms a Relational
Database.
• Establish the
relationship between the
tables by using PK and
FK Concept.
RELATIONAL STRUCTURE
Attributes
Tuples
B E F
C D G
• It is an inverted tree
structure.
• In the above structure,
A, B, C, D, E, F & G are
segments.
• Relationship is One to Many.
DBMS TYPES - OVERVIEW
TYPE ENTITY RELATIONSHIP EG. DB
NDBMS SET M : N IDMS
----------------------------------
RDBMS TABLE OPTIMAL DB2,
SYBEL,
ORACLE, etc
----------------------------------
HDBMS SEGMENT 1 : M IMS
EXAMPLE -
HOSPITAL DATABASE
PATIENT Level 1
Level 2
ILLNESS BILLING HOUSEHOLD
Constraints,
• Maximum 255 Segments are allowed
per Database. Maximum upto 15 Levels.
DATABASE HIERARCHY CHART
• ROOT SEGMENT
• DEPENDENT SEGMENT
• SEGMENT TYPE
• SEGMENT OCCURRENCE
• SIBBLING SEGMENT
• TWIN SEGMENT
• DATABASE RECORD
• HIERARCHICAL PATH
• IMMEDIATE & NON-IMMEDIATE PARENTS
ROOT SEGMENT
A very first segment
or level-1 segment in an
IMS Database is said to
be a Root Segment. Only
one root segment is
allowed per hierarchical
database. In our Example
PATIENT segment is the
root segment.
DEPENDENT SEGMENT
Segments from Level-2
to Level-15 Segments are
said to be dependent
segments. In our example
ILLNESS, TREATMENT,
BILLING, PAYMENT &
HOUSEHOLD are dependent
segments.
SEGMENT TYPE
Every segment name is
said to be a segment
type. The segment type
should be unique in any
hierarchical database.
In our example, we have
six segment types.
SEGMENT OCCURRENCE
Every record in the
segment type is said to
be a segment occurrence.
Collection of segment
occurrences forms a
segment type.
SIBBLING SEGMENT
More than one
segments comes under a
same parent in the same
level is said to be a
sibbling segment. In our
example, ILLNESS,
BILLING & HOUSEHOLD are
sibblings.
TWIN SEGMENT
All occurrences of a
particular segment type
under a single parent
segment occurrence are
called TWINS.
PATIENT(P1)
ILL1 BILL1
ILL2 BILL2
Twins
ILL3 BILL3
ILL4 BILL4
DATABASE RECORD
Database record is
nothing but collection
of entire dependent
details about the root
key. In our example,
Collection of related
Illness, Treatment,
Billing, Payment &
Household details of a
particular patient.
HIERARCHICAL PATH
• Segments are always
accessed and retrieved
along the Hierarchical
Paths.
• A path is a route line that
Begins at the Root segment,
travels through the
segments at Intermediate
levels in the hierarchy and
Ends at a segment in the
Bottom of the hierarchy.
HIERARCHICAL PATH
In our example,
Hierarchical paths are,
PSB DBD
APPLICATION
DL/I
PROGRAM
ACCESS METHODS
HDAM,HISAM
HIDAM,HSAM
GSAM . . . . .
DATA
ESDS
WHY ACCESS METHODS???
• Access methods are
like interfaces to help
us to communicate
between two subsystems
or systems. Based on the
access method type IMS
will organize and
retrieve the datas from
the back-end dataset.
WHY ACCESS METHODS???
• IMS provides number
of access methods to
communicate with back-
end datas. The basic
access methods are HDAM,
HIDAM, HISAM, HSAM,
GSAM. . .
HDAM OVERVIEW
HDAM Stands for
‘Hierarchical Direct
Access Method’. This
access method says we can
perform random operation
against backend ESDS file.
But! is it possible to do
random operation against
ESDS in Batch Environment?
HDAM OVERVIEW
Yes! It is possible
in this case because IMS
provides an inbuilt index
component called
‘Randomizer Module’. As a
user we can store our key
values in this RM Space
and actual values in Data
component called ESDS.
HDAM DATA FLOW
HDAM RANDOMIZER MODULE DATA
(INDEX)
ESDS
KSDS ESDS
If we use HIDAM/HISAM
as an Access method then
IMS Will not provide any
inbuilt index space. So
user has to create an
index component
explicitly.
HSAM/GSAM DATA FLOW
HSAM/GSAM DATA
ESDS
DBD NAME=Hospital,
ACCESS=(HSAM,VSAM)
DBD NAME=Hospital,
ACCESS=(HDAM,VSAM),
RMNAME=(DFSHDC40,010,00000120,
00004096)
DBD Macro Example
Where, DFSHDC40 is the name
of the IBM-supplied randomizing
module, DL/I will use when it
processes the database.
The other values specify
what the structure of the HDAM
will be. 010 tells DL/I to use 10
RAP’s per control interval in the
database root addressable area.
DBD Macro Example
The value 120 specifies the
root addressable area, should use
120 control intervals and 4096
specifies the size of the each
control interval in the root
addressable area.
DATASET Macro
DATASET Macro provides 3
different parameters. They are,
• DD1
• DEVICE
• SIZE
The parameter DD1 is for
specifying the dd name. The same
dd name should be declared in run
jcl to invoke the datas from
database.
DATASET Macro
The DEVICE parameter specifies
the physical storage device(DASD)
name and SIZE parameter specifies
the length of the control
interval in every control area.
DATASET DD1=hosdd,DEVICE=3390,
SIZE=4096
SEGM Macro
SEGM Macro provides 3
different parameters. They are,
• NAME
• BYTES
• PARENT
The NAME Parameter is
for specifying the segment name.
The name should be unique for
each and every segments. It
should not exceed 8 chars. Long.
SEGM Macro
The BYTES operand specifies
the segment length in terms of
bytes and PARENT operand names
the parent of each segment type
thereby defining the Hierarchical
Structure of a database. A root
segment is identified by the
absence of a Parent operand or
Parent=0.
FIELD Macro
The FIELD Macro provides
three different parameters,
• NAME
• BYTES
• START
• TYPE
FIELD Macro
We have 2 different types of
fields, Search field and Sequence
field based on the field type.
NAME parameter contains from
one to three positional sub-
parameters. The first sub-
parameter names the key or search
field. If it is the only sub-
parameter coded, the field will
be considered as a search field.
FIELD Macro
If SEQ is coded as the second
sub-parameter, the field will be
a key field, and the occurrences
will be sequenced in Ascending
order. This sub-parameter is
optional. If specified, only one
key field is allowed per SEGM
statement.
FIELD Macro
If U is coded as the third
sub-parameter, the field is a
UNIQUE sequence field unless M is
specified for Multiple value in
the field. If neither 'U' nor 'M'
is specified when SEQ is coded,
the sequence field is taken to be
unique. This sub-parameter is
optional.
FIELD Macro
The BYTES operand tells the
field length in bytes.
The START operand tells the
starting byte position of the key
or search field relative to the
beginning of the segment. The
starting position will be
initialized for each and every
segment.
FIELD Macro
The TYPE operand tells the
data type of field, accordingly C
specifies a character field of
alphanumeric type, P specifies a
packed Decimal numeric type. C is
the default data type. FIELD
statement for the sequence field,
if there is one, must be the
first such statement for the
segment.
FIELD Macro
Field macro
TYPE codes Data type
C Character
P Packed decimal
Z Zoned decimal
X Hexadecimal
H Halfword binary
F Fullword binary
DBDGEN FINISH END Macros
DBDGEN Macro ends the SEGM and
FIELD definitions in the DBD.
FINISH Macro causes the
assembler to set non-zero
condition code if errors are
encountered during assembly
process.
END Macro marks the end-of-
data to the assembler.
DBD Source for Hospital
Database
PRINT NOGEN
DBD NAME=Hospital,ACCESS=(HDAM,VSAM),
RMNAME=(DFSHDC40,010,00000120,00004096)
DATASET DD1=Hosdd,DEVICE=3390,SIZE=4096
******************PATIENT SEGMENT**********************
SEGM NAME=Patient,BYTES=45,PARENT=0
FIELD NAME=(Patno,seq,u),BYTES=5,START=1,TYPE=C
FIELD NAME=Pname,BYTES=10,START=6,TYPE=C
FIELD NAME=Paddr,BYTES=30,START=16,TYPE=C
DBD Source for Hospital
Database
******************ILLNESS SEGMENT**********************
SEGM NAME=Illness,BYTES=20,PARENT=Patient
FIELD NAME=(Illdate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Illname,BYTES=10,START=11,TYPE=C
******************TRTMENT SEGMENT**********************
SEGM NAME=Treatmnt,BYTES=34,PARENT=Illness
FIELD NAME=(Trdate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Medicine,BYTES=10,START=11,TYPE=C
FIELD NAME=Qnty,BYTES=4,START=21,TYPE=C
FIELD NAME=Doctor,BYTES=10,START=25,TYPE=C
DBD Source for Hospital
Database
******************BILLING SEGMENT**********************
SEGM NAME=Billing,BYTES=15,PARENT=Patient
FIELD NAME=(Billno,seq),BYTES=5,START=1,TYPE=C
FIELD NAME=Billdate,BYTES=10,START=6,TYPE=C
******************PAYMENT SEGMENT**********************
SEGM NAME=Payment,BYTES=20,PARENT=Billing
FIELD NAME=(Paydate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Amount,BYTES=10,START=11,TYPE=C
DBD Source for Hospital
Database
******************HOUSEHLD SEGMENT**********************
SEGM NAME=Househld,BYTES=8,PARENT=Patient
FIELD NAME=(Wardno,seq,m),BYTES=3,START=1,TYPE=C
FIELD NAME=Wardtype,BYTES=5,START=4,TYPE=C
******************END OF STRUCTURE**********************
DBDGEN
FINISH
END
DBD Generation(DBDGEN)
To execute the DBD Source, we
have to call a procedure called
DBDGEN(DBD Generator). This will
assemble all the dbd source
statements before that it will
refer a built-in macro library
called MACLIB and it will
generate the load library called
DBDLIB(DBD Library).
DBD Generation(DBDGEN)
DBD
DBDGEN DBDLIB
Macro
Source code Assemble & Link edit
MACLIB
Program Specification
Block(PSB)
• The DBA defines the logical data
structure by creating a Control
Block called a Program
Specification Block or PSB.
• Logical Data Structure is a term
used to refer to a group of
segments that an application
program may access. To the
application program, the logical
data structure is the database.
Program Specification
Block(PSB)
• PSB is created with a process
called PSB generation or PSBGEN,
very similar to the DBDGEN
process, wherein DBA codes a
series of control statements.
• PSBGEN control statements are
Assembler Language Macros supplied
by IBM and submitted via JCL
invoking a procedure called PSBGEN
producing an OBJECT module.
Program Specification
Block(PSB)
• Macros are stored in Maclib and
Load modules are stored in PSBLIB,
which is the PSB itself and ready
for loading.
• Each PSB consists of one or more
control blocks called Program
Communication Blocks or PCB's.
Each PCB within a PSB defines
exactly one Logical Data
Structure.
Program Specification
Block(PSB)
• All the PCB's within a single PSB
are collectively known as an
Application Data Structure.
• It is possible that more than one
program may share a single PSB,
however, no program can use more
than one PSB in a single execution.
• The Logical Data Structures defines
all the segments that an appln.
program may access using that PSB.
PSB Macros
• PCB
• SENSEG
• PSBGEN
• END
PCB Macro
This is the very first macro
in the PSB. PCB is for creating
number of PCB’s in PSB. This PCB
macro is applicable to both batch
and online based on the operands
coded in the PCB Macro. PCB does
not has any name and accessed only
in sequential manner.
PCB Macro
PSB
PCB1
PCB2
PCB3
PCB4
PCB5
PCB Macro
This macro provides 4 types
of operands,
• TYPE
• NAME
• PROCOPT
• KEYLEN
PCB Macro
The TYPE operand specifies
whether PCB is for Database
processing(Batch) or for
Transaction processing(Online). If
TYPE=DB then its for accessing
database. If TYPE=TP then its for
accessing terminals. To perform
both then we require 2 different
PCB’s.
PCB Macro
The NAME operand tells the
database name which we have
specified in the DBD Macro(NAME
Parameter value). There is no
logical connection between PSB and
DBD in the IMS Architecture(Ref.
Diag.). This NAME parameter is for
automatically routing the control
from PCB to appropriate DBD which
belongs to.
PCB Macro
PROCOPT Stands for Processing
Options. It acts like gateway
between PCB and DBD. Because based
on the processing option values one
can perform the data oriented
operations. Its 4 bytes long.
PROCOPT=L/LS/G/R/I/D/A. . .
L-LOAD LS-LOAD SEQUENCE G-GET
R-REPLACE I-INSERT D-DELETE
A-ALL.
PCB Macro
KEYLEN Stands for Key Length.
It specifies the length of the
longest concatenated key or Key
Feedback Area(KFA) the program can
process in the database.
In our hospital database
KEYLENGTH=43.
Lengths of patno + illdate +
trdate + billno + paydate + wardno.
SENSEG Macro
SENSEG Macro is for creating
number of required logical paths
under PCB to access the database.
It provides 2 basic types of
operands,
• NAME
• PARENT
SENSEG NAME=Patient,PARENT=0
SENSEG NAME=Illness,PARENT=Patient
PSBGEN Macro
PSBGEN Stands for PSB
Generation. This is for specifying
the host language(appln. Program)
type and the PSB name. The operands
are,
• LANG
• PSBNAME
PSBGEN LANG=Cobol/PLI/ASM…,
PSBNAME=Hospsb
PSB Source for Hospital
Database
PCB TYPE=DB,NAME=Hospital,
PROCOPT=L,KEYLEN=43
SENSEG NAME=Patient,PARENT=0
SENSEG NAME=Illness,PARENT=Patient
SENSEG NAME=Treatmnt,PARENT=Illness
SENSEG NAME=Billing,PARENT=Patient
SENSEG NAME=Payment,PARENT=Billing
SENSEG NAME=Househld,PARENT=Patient
PSBGEN LANG=Cobol,PSBNAME=Hospsb
END
PSB Generation(PSBGEN)
To execute the PSB Source, we
have to call a procedure called
PSBGEN(PSB Generation). This will
assemble all the psb source
statements before that it will
refer a built-in macro library
called MACLIB and it will
generate the load library called
PSBLIB(PSB Library).
PSB Generation(PSBGEN)
PSB
PSBGEN PSBLIB
Macro
Source code Assemble & Link edit
MACLIB
ACB Generation(ACBGEN)
ACBGEN Stands for Application
Control Block Generation. This
ACBGEN merges both DBDLIB and
PSBLIB, produces the final load
library called ACBLIB that
application program can access.
If this happens in batch then it
is said to be ‘DYNAMIC BUILD’. If
this happens in online then it is
said to be ‘STATIC BUILD’.
ACB Generation(ACBGEN)
To perform this build
operation, we have to invoke a
catalogue procedure called
DFSRC00. DFSRC00 is the DL/I load
module called Region Controller.
We have to define both PSBLIB
path and DBDLIB path in the
special DD name called ‘IMS’..
This step is said to be a Build
operation.
ACB Generation(ACBGEN)
DBDLIB
ACBGEN
(DFSRC00) ACBLIB
BUILD
PSBLIB
ACBGEN Sample jcl
• //RETRIEVE EXEC PGM=DFSRRC00, PARM=DLI, PATRETRV
• //STEPLIB DD DSN=IMSVS.RESLIB, DISP=SHR
• // DD DSN=IMSVS.PGMLIB, DISP=SHR
• //IMS DD DSN=IMSVS.PSBLIB, DISP=SHR
• // DD DSN=IMSVS.DBDLIB, DISP=SHR
• //SYSUDUMP DD SYSOUT=A
• //HOSDD DD DSN=IMS.VSAM.HOSDB, DISP=OLD
• //OUTPUT DD SYSOUT=A
• //INPUT DD A
• -------------------------------------
• -------------------------------------
• -------------------------------------
• (INPUT TRANSACTIONS)
• -------------------------------------
• -------------------------------------
DL/I (Data Language/I)
• It 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.
• This is an Interface Language
used by the Application Program.
DL/I (Data Language/I)
• We can invoke number of DL/I
subroutines through entry and
call statements.
ENTRY ‘DLITCBL’ USING
Parameters. . .
CALL ‘CBLTDLI’ USING
Parameters. . .
DL/I (Data Language/I)
• The ENTRY Statement is the very
first executable statement in the
program that establishes the
connection between the external
PCB with Internal PCB Mask.
• The CALL Statements are for
performing different data related
operations against the IMS
Database.
DL/I Data Processing
APPLICATION PROGRAM
Calls to DL/I
DL/I
DATABASE
DATASET
DL/I Programming
Considerations
• The application program is
treated as a subroutine of DL/I
and standard subroutine Linkages
and Parameter lists are used to
connect the application program to
the DL/I modules that passes
control to it.
• When DL/I links to the application
program, it passes to the program
a parameter list containing the
addresses of the PCB's in the PSB.
DL/I Programming
Considerations
Working-Storage section:
• The DL/I Function Code variables
are copied here.
• The SSA'S (Segment Search
Arguments) for segment retrievals
are defined here.
• The structure in COBOL for
various segments within the
database are declared here or
simply said to be an I-O Area.
DL/I Programming
Considerations
Function Code:
This is the first parameter
in the list. It names a four byte
function code for the service
requested from DL/I such as
Insert, Update, Delete, and
Browse of database. A function
table Copybook called DLI CALLS
is copied in the application
program using the command
COPY DLI CALLS.
DL/I Programming
Considerations
Function Code Abbreviation
For Write Operation:
ISRT Insert
For Rewrite Operation:
REPL Replace
For Delete Operation:
DLET Delete
DL/I Programming
Considerations
Function Code Abbreviation
For Read Operation:
GU Get Unique
GN Get Next
GHU Get Unique with Hold
GHN Get Next with Hold
GNP Get Next within a Parent
GHNP Get Next within a Parent
with Hold
DL/I Programming
Considerations
DL/I Programming
Considerations
DL/I Programming
Considerations
Working-storage section.
01 func-codes.
05 ins pic x(4) value ‘ISRT’.
05 rep pic x(4) value ‘REPL’.
05 del pic x(4) value ‘DLET’.
05 g1 pic x(4) value ‘GU’.
05 g2 pic x(4) value ‘GN’.
05 g3 pic x(4) value ‘GNP’.
05 g4 pic x(4) value ‘GHU’.
05 g5 pic x(4) value ‘GHN’.
05 g6 pic x(4) value ‘GHNP’.
DL/I Programming
Considerations
Segment Search Argument(SSA):
• This is the second parameter
in the list. This is optional.
Whenever specified, DL/I uses
it to narrow the field of
search to a particular segment
type or to a particular segment
occurrence to be manipulated at
each level of database.
DL/I Programming
Considerations
Segment Search Argument(SSA):
• There can be maximum of 1 SSA
per level upto 15 SSA's for
each database. If SSA is not
used for any level, DL/I will
follow the rules to calculate
the default SSA.
DL/I Programming
Considerations
SSA Types:
There are two types of
SSA’s,
• UNQUALIFIED SSA
• QUALIFIED SSA
DL/I Programming
Considerations
UNQUALIFIED SSA :-
This only specifies the
SEGMENT TYPE the program is
interested in. Here you don't
indicate a particular occurrence of
a segment because you don't care
which occurrence of a segment you
get. The segment name is first
eight characters padded by space.
For example - HOSPITAL. This will
retrieve the first occurrence of
HOSPITAL segment.
DL/I Programming
Considerations
UNQUALIFIED SSA:
DL/I provides the specific
structure for unqualified SSA.
It is said to be a Segment name
without any parameters.
Unqualified SSA Structure
Segment Name Blank
8 Bytes 1 Byte
DL/I Programming
Considerations
UNQUALIFIED SSA Declaration:
01 Unq-ssa.
05 seg-name pic x(8).
05 bla pic x.
(or)
01 unq-ssa pic x(9).
Example:
01 Unq-ssa-pat.
05 seg-name pic x(8) value ‘patient’.
05 bla pic x value SPACES.
DL/I Programming
Considerations
QUALIFIED SSA :
This is addition to the
SEGMENT TYPE, also contains one
or more qualification statements.
A qualified SSA describes the
segment occurrence a program
wants to access. This description
is called a qualification
statement having 3 parts.
DL/I Programming
Considerations
QUALIFIED SSA :
A qualified statement is
enclosed in parenthesis. The
part names the field that DL/I
will use for segment search. The
second part names the Relational
Operator of two bytes telling
DL/I what kind of comparison to
make during the search.
DL/I Programming
Considerations
QUALIFIED SSA :
The third part is a variable
length field that contains the
values for comparison during DL/I
search. Can code more than one
qualification statement.
Note:
In the ninth position of SSA,
A BLANK indicates unqualified SSA.
A LEFT PARENTHESIS indicates qualified SSA.
DL/I Programming
Considerations
QUALIFIED SSA:
DL/I provides the specific
structure for qualified SSA. It
is said to be a Segment name
with number of parameters.
Qualified SSA Structure
Relational
Segment Name ( Field Name Values )
Operator
8 Bytes 1 Byte 8 Bytes 2 Bytes 1 - 255 1 Byte
(EQ/NE/GT/ Bytes
LT/GE/LE)
DL/I Programming
Considerations
QUALIFIED SSA Declaration:
01 Qua-ssa.
05 seg-name pic x(8).
05 ob pic x.
05 fld-name pic x(8).
05 rel-oper pic x(2).
05 values pic x(n).
05 cb pic x.
DL/I Programming
Considerations
QUALIFIED SSA Example:
01 Qua-ssa-pat.
05 seg-name pic x(8) value ‘patient’.
05 ob pic x value ‘(‘.
05 fld-name pic x(8) value ‘patno’.
05 rel-oper pic x(2) value ‘EQ’.
05 values pic x(5) value ‘p1001’.
05 cb pic x value ‘)’.
DL/I Programming
Considerations
INPUT-OUTPUT AREA :
This is the third parameter
in the list. This area is used by
DL/I to put a retrieved segment
or by the application program to
store the data of a segment prior
to addition or updation. If a
single segment occurrence is
received, inserted or updated
this area should be the segment
layout area.
DL/I Programming
Considerations
INPUT-OUTPUT AREA :
The I-O area must be large
enough to contain the data of the
largest segment type. After
determining which segment is
retrieved move the segment
contents to an area describing it.
Another option is to use the
REDEFINES clause to describe each
segment type in the Hierarchy
path.
DL/I Programming
Considerations
INPUT-OUTPUT AREA FOR
PATIENT SEGMENT :
01 PAT-REC.
05 PATNO PIC X(5).
05 PATNAME PIC X(10).
05 PATADDR PIC X(30).
DL/I Programming
Considerations
Linkage Section :
• PCB masks for the PCB's passed to
the program by DL/I is coded here.
• The data names describes the data
areas in the PCB mask for the
PCB's that DL/I loaded.
• Must for every DL/I program since
PCB is a DL/I control block that
is loaded into memory by DL/I
before the program is executed.
DL/I Programming
Considerations
Linkage Section :
• When a DL/I call is issued, the
PCB mask must be specified to
indicate which PCB (database) in
the PSB is to be used to process
the call.
• DL/I updates the PCB mask with
the execution results after every
DL/I call.
DL/I Programming
Considerations
Linkage Section :
DL/I provides an in-built
internal PCB Mask structure,
01 PCB-MASK.
05 DBDNAME PIC X(8).
05 LEVEL-NUMBER PIC X(2).
05 STATUS-CODE PIC X(2).
05 PROC-OPTIONS PIC X(4).
05 INTERNALS PIC X(4).
05 SEGMENT-NAME PIC X(8).
05 KEY-LENGTH PIC S9(5) COMP.
05 NUMBER-OF-SEGS PIC S9(5) COMP.
05 KEY-FEEDBACK-AREA PIC X(n).
DL/I Programming
Considerations
Procedure Division :
The entry code accomplishes three
things in a program written in COBOL.
They are,
• It gives a standard DL/I name to the
entry point of any COBOL - DL/I
program which must be ‘DLITCBL’.
• It hooks the program to the PCB
through the USING clause of the ENTRY
statement.
DL/I Programming
Considerations
Procedure Division :
• The sequence of PCB masks specified in the
ENTRY statement must be identical to the
sequence of their corresponding PCB's in the
PSB. Although the order of PCB masks in the
Linkage Section does not matter.
• The execution of a program terminates with a
GOBACK statement because all DL/I programs
are sub routines of DL/I. Therefore, do not
use STOP-RUN.
• The ENTRY statement provides a mechanism for
DL/I to transfer control to the application
program.
DL/I Programming
Considerations
DL/I Calls:
• Calls to DL/I are made using a DL/I
interface language.
• IMS services are requested via DL/I
calls having a standard format.
• The Language Components are,
* The call statement parameter list.
* The formats of the data items
specified in the list.
• DL/I calls can be imbed in COBOL,
DL/I or Assembler.
DL/I Programming
Considerations
DL/I Calls:
• The entry point name in the CALL
statement is 'CBLTDLI' the name used
whenever a DL/I service is requested
in a COBOL program.
The general command format is,
CALL 'CBLTDLI‘ USING Function code
PCB mask
I-O Area
SSA's.
INSERT Call
To insert occurrences into
segments, we require,
• ISRT as Function code.
• I-O area declaration as same as
physical segment(DBD) structure.
• Internal PCB Mask declaration.
• Entry Statement.
• Input values.
• Call Statements.
INSERT (into patient
segment)
IDENTIFICATION DIVISION.
PROGRAM-ID. PATISRT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PATIENT-REC.
05 PAT-NO PIC X(5).
05 PAT-NAME PIC X(10).
05 PAT-ADDR PIC X(30).
01 UNQUAL-SSA.
05 SEG-NAME PIC X(8) VALUE 'PATIENT'.
05 FILLER PIC X VALUE SPACE.
01 FUN-CODE PIC X(4) VALUE 'ISRT'.
LINKAGE SECTION.
01 PCB-MASK.
05 DBD-NAME PIC X(8).
05 DBD-LEVEL-NO PIC X(2).
05 DBD-STATUS-CODE PIC XX.
05 DBD-PROC-OPT PIC X(4).
05 DBD-INTERNAL PIC X(04).
05 DBD-SEG-NAME PIC X(08).
05 DBD-KEY-LENGTH PIC S9(5) COMP.
05 DBD-NO-SENSEG PIC S9(5) COMP.
05 DBD-KEY-FEEDBACK PIC X(30).
INSERT (into patient
segment)
PROCEDURE DIVISION.
000-MAIN-PROCESS.
ENTRY 'DLITCBL' USING PCB-MASK.
PERFORM 100-ACCEPT-PARA.
PERFORM 100-ISRT-PARA.
GOBACK.
100-ACCEPT-PARA.
ACCEPT PAT-NO.
ACCEPT PAT-NAME.
ACCEPT PAT-ADDR.
100-ISRT-PARA.
CALL 'CBLTDLI' USING FUN-CODE, PCB-MASK, PATIENT-REC
UNQUAL-SSA.
IF DBD-STATUS-CODE = SPACES THEN
DISPLAY 'SUCESSFUL'
DISPLAY 'LEVEL ' DBD-LEVEL-NO
DISPLAY 'SCODE ' DBD-STATUS-CODE
DISPLAY 'SEGMENT NAME ' DBD-SEG-NAME
DISPLAY 'KEY FIELD ' DBD-KEY-FEEDBACK
DISPLAY 'NO OF SENSITIVE SEGMENT ' DBD-NO-SENSEG
INSERT (into patient
segment)
ELSE
DISPLAY 'UN SUCESSFUL'
DISPLAY 'LEVEL ' DBD-LEVEL-NO
DISPLAY 'SCODE ' DBD-STATUS-CODE
DISPLAY 'SEGMENT NAME ' DBD-SEG-NAME
DISPLAY 'KEY FIELD ' DBD-KEY-FEEDBACK
DISPLAY 'NO OF SENSITIVE SEGMENT ' DBD-NO-SENSEG
END-IF.
INSERT (into illness
segment)
IDENTIFICATION DIVISION.
PROGRAM-ID. QUALSSA.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ILL-REC.
05 ILL-DATE PIC X(8).
05 ILL-NAME PIC X(10).
01 QUAL-PATSSA.
05 SEG-NAME PIC X(8) VALUE 'PATIENT '.
05 FILLER PIC X VALUE '('.
05 FNAME PIC X(8) VALUE 'PATNO'.
05 OPER PIC X(2) VALUE 'EQ'.
05 PATNO PIC X(5).
05 FILLER PIC X VALUE ')'.
01 UNQUAL-ILL-SSA PIC X(9) VALUE 'ILLNESS'.
01 FUN-CODE PIC X(4) VALUE 'ISRT'.
INSERT (into illness
segment)
LINKAGE SECTION.
01 PCB-MASK.
05 DBD-NAME PIC X(8).
05 DBD-LEVEL-NO PIC X(2).
05 DBD-STATUS-CODE PIC XX.
05 DBD-PROC-OPT PIC X(4).
05 DBD-INTERNAL PIC X(04).
05 DBD-SEG-NAME PIC X(08).
05 DBD-KEY-LENGTH PIC S9(4) COMP.
05 DBD-NO-SENSEG PIC S9(4) COMP.
05 DBD-KEY-FEEDBACK PIC X(30).
PROCEDURE DIVISION.
000-MAIN-PROCESS.
ENTRY 'DLITCBL' USING PCB-MASK.
PERFORM 100-ACCEPT-PARA.
PERFORM 100-ISRT-PARA.
GOBACK.
INSERT (into illness
segment)
100-ACCEPT-PARA.
ACCEPT PATNO.
ACCEPT ILL-DATE.
ACCEPT ILL-NAME.
100-ISRT-PARA.
CALL 'CBLTDLI' USING FUN-CODE, PCB-MASK, ILL-REC
QUAL-PATSSA,UNQUAL-ILL-SSA.
IF DBD-STATUS-CODE = SPACES THEN
DISPLAY 'SUCESSFUL'
DISPLAY 'LEVEL ' DBD-LEVEL-NO
DISPLAY 'SCODE ' DBD-STATUS-CODE
DISPLAY 'SEGMENT NAME ' DBD-SEG-NAME
DISPLAY 'KEY FIELD ' DBD-KEY-FEEDBACK
DISPLAY 'NO OF SENSITIVE SEGMENT ' DBD-NO-SENSEG
ELSE
DISPLAY 'UN SUCESSFUL'
DISPLAY 'LEVEL ' DBD-LEVEL-NO
DISPLAY 'SCODE ' DBD-STATUS-CODE
DISPLAY 'SEGMENT NAME ' DBD-SEG-NAME
DISPLAY 'KEY FIELD ' DBD-KEY-FEEDBACK
DISPLAY 'NO OF SENSITIVE SEGMENT ' DBD-NO-SENSEG
END-IF.
GET Call
SEQUENTIAL RETRIEVAL USING GN CALL:
• This retrieves a series of
segments in Sequential order.
• GN call is issued to retrieve the
next segment occurrence from the
current database position
established by a GU or GN call.
DL/I will start the search from
current position forward to try
to satisfy the call.
GET Call
SEQUENTIAL RETRIEVAL USING GN CALL:
• Unqualified GN calls will
traverse through the entire
database.
• One or more GN calls can be
issued to retrieve the rest of
the occurrences with the
duplicate key.
GET Call
SEQUENTIAL RETRIEVAL USING GN CALL:
• After each call examine the PCB
mask fields for the status code,
segment name and level number to
determine the segment occurrence
retrieved. Also it is difficult
to figure out when you will go up
in level, go down in level, or
stay at the same level in
database.
GET Call
SEQUENTIAL RETRIEVAL USING GN CALL:
• DL/I Sequential Processing
sequence within a database is
always Top to Bottom, Left to
Right and Front to Back along
Twin occurrences.
• An important issue to be
considered in sequential calls is
the concept of position within
the database.
Call Types
Logical AND:
* (Asterisk) or the & (Ampersand)
Logical OR:
+ (Plus) or the | (Vertical Bar)
Multiple Qualifications
Structure
1 - 255
8 Bytes 1 Byte 8 Bytes 2 Bytes Bytes
Relational
Segment Name1 ( Field Name1 Values
Operator1
1 Byte
Logical Relational
Field Name2 Values
Operator Operator2
………………………………
………………………………
…………………………… )
Multiple Qualifications
QUALIFIED SSA Declaration with
multiple qualifications:
01 Qua-ssa-mul.
05 segname pic x(8) value ‘patient’.
05 ob pic x value ‘(‘.
05 fld-name1 pic x(8) value ‘patno’.
05 rel-oper1 pic x(2) value ‘eq’.
05 value1 pic x(5) value ‘p1001’.
05 lo1 pic x value ‘&’
05 fld-name2 pic x(8) value ‘patname’.
05 rel-oper2 pic x(2) value ‘eq’.
05 value2 pic x(5) value ‘john’.
05 cb pic x value ‘)‘.
Command Codes
• The command code is not an
independent concept. It always
depends on SSA’s.
• Command codes can simplify the
IMS Application programs.
• Command codes in a SSA makes the
call powerful since DL/I treats
such SSA'S differently from those
without the command codes while
performing some special functions.
Command Codes
• Command codes are specified in an
SSA following the segment name and
an Asterisk '*‘.
• An Asterisk '*' in the ninth
position in a SSA indicates that one
or more command codes follow the
asterisk.
• A Blank or Left Parenthesis marks
the end of command codes.
• ONE or MORE command codes can be
used in any combination.
Command Codes
Command code
identifier
Command Codes Structure
Target C
Segment * Command ( Key Key Key . . . . . Key )
Name code 1 2 3 15
C Command Code
Without C Command code:
GU
PATIENT (PATNO=p1001)
ILLNESS (ILLDATE=01/03/2010)
TREATMNT (TRDATE=03/03/2010)
C Command Code
With C Command code:
TREATMNT * C (
p1001
01/03/2010
02/03/2010 )
Q Command Code
• Q command code is only used when
multiple applications will be
accessing the same database at the
same time. Normally used in the
O/L MPP where the O/L programs are
running under multitasking
environment and more than one task
can update the same database at
the same time.
Q Command Code
• If you do not want this to happen,
issue DL/I calls with Q command
code to ENQUEUE the particular
segment occurrence for exclusive
use by your task, preventing other
online transactions from updating
the segment until your task is
completed.
Q Command Code
• Other users cannot make a Get Hold
type call for that segment, only
get calls can access that segment.
Get Hold type calls must wait
until the Enqueued segment has
been Dequeued through the DEQ
call, CHKP call, or the program
termination.
Q Command Code
• Q command code set at the root
segment level will not allow any
other user to gain access to any
segment in that database record.
• A one-byte class identifier in the
range of 'A 'through' J follows Q
command code. This class
identifier must be specified in
the DEQ call to dequeue the
segments
P Command Code
• P command code allows the parentage
to be set at any levels in the
database other than the one
identified by the last SSA.
• Code the P command code in the SSA
for the segment at which you would
like the parentage established and
DL/I will still retrieve the segment
identified by the last SSA, but sets
parentage where you set the P command
code.
P Command Code
• The parentage will be destroyed
when another GU or GN call is
executed.
With P Command Code:
GU PATIENT(PATNO=p1001)
ILLNESS * P (ILLDATE=01/03/2010)
TREATMNT(TRDATE=03/03/2010)
By using a P command code, you saved one
call by retrieving the first Treatmnt segment
in the Get Unique call itself and setting the
parentage at the illness level.
NULL Command Code
• The NULL command code '__’ is used
in the SSA to simplify the
construction of SSA within the
program and does not perform any
function at all.
• The SSA is treated as if no
command code were coded.
NULL Command Code
• The null command code '__'
reserves one or more positions in
a SSA into which you can store
command codes during the program
execution. This way making it
possible to use the same set of
SSA'S for more than one purpose.
• PATIENT *------- (PATNO = P1001)
Multiple Positioning
within the PCB
• With Multiple Positioning DL/I
maintains a unique position within
a Database Record for each
dependent segment type at each
level in each Hierarchical path in
the database.
• Multiple Positioning is normally
used to access segments of two or
more types dependent on a specific
parent.
Multiple Positioning
within the PCB
• The segments are processed
sequentially at the same time,
enabling parallel processing
within the database.
• Multiple Positioning lets a
program maintain more than one
position within a database using a
single PCB.
Multiple Positioning
within the PCB
• Multiple Positioning for a
database is specified in the PCB
statement in the PSB for POS
operand. For example
PCB TYPE=DB, NAME=HOSPITAL,
POS=M or S
M stands for Multiple, S stands
for Single Positioning.
If POS operand is not coded,
the default is single positioning.
Multiple PCB’s in a PSB
• When a program needs access to more
than one database, it has a PCB for
each.
• A single PCB can refer to only one DBD
• Multiple PCB's can also be defined for
a single database in which case the
program has two or more views of the
same database and DL/I will maintain a
unique position in that database for
each PCB you define on it.
Multiple PCB’s in a PSB
• Multiple PCB's on the same database is
defined when the program require access
to two completely different logical
data structures, each describing
different segments in different
hierarchical paths from the same
database.
• Each PCB in PSB has its own PCB mask in
the Linkage Section and is specified in
the ENTRY statement for addressing that
block in the order in which PCB's
appear in the PSB.
Multiple PCB’s in a PSB
PSB
01 PCB-MASK5.
PCB5
05 . . . . .
05 . . . .
Multiple PCB’s in a PSB
LINKAGE SECTION. PSB
CALL ‘CBLTDLI’ USING ISRT
PCB-MASK1, PAT-IO-AREA, PCB1
UNQ-SSA-PAT.
CALL ‘CBLTDLI’ USING GN, PCB-MASK2,
PAY-IO-AREA, QUA-SSA-PAT, PCB2
QUA-SSA-BILL, UNQ-SSA-PAY.
CALL ‘CBLTDLI’ USING GU
PCB-MASK3, HLD-IO-AREA, PCB3
QUA-SSA-PAT, QUA-SSA-HLD.
CALL ‘CBLTDLI’ USING GU
PCB-MASK4, WARD-IO-AREA, PCB4
QUA-SSA-PAT, QUA-SSA-WARD.
A1 A2 A3
ESDS OSAM
A1 B1 C1 D1 B2 Free Space
C2 C3 C4 B3 D2 Free Space
C5 A3 B4 D3 D4 A2 Free Sp
D6 Free Space
HIDAM Primary
Database(ESDS)
PRINT NOGEN
DBD NAME=Hospital,ACCESS=(HIDAM,VSAM),
DATASET DD1=Hosdd,DEVICE=3390,SIZE=4096
******************PATIENT SEGMENT**********************
SEGM NAME=Patient,BYTES=45,PARENT=0
LCHILD NAME=(IDXSEG,IDXDBD),PTR=INDEX
FIELD NAME=(Patno,seq,u),BYTES=5,START=1,TYPE=C
FIELD NAME=Pname,BYTES=10,START=6,TYPE=C
FIELD NAME=Paddr,BYTES=30,START=16,TYPE=C
HIDAM Primary
Database(ESDS)
******************ILLNESS SEGMENT**********************
SEGM NAME=Illness,BYTES=18,PARENT=Patient
FIELD NAME=(Illdate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Illname,BYTES=10,START=11,TYPE=C
******************TRTMENT SEGMENT**********************
SEGM NAME=Treatmnt,BYTES=32,PARENT=Illness
FIELD NAME=(Trdate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Medicine,BYTES=10,START=11,TYPE=C
FIELD NAME=Qnty,BYTES=4,START=21,TYPE=C
FIELD NAME=Doctor,BYTES=10,START=25,TYPE=C
HIDAM Primary
Database(ESDS)
******************BILLING SEGMENT**********************
SEGM NAME=Billing,BYTES=15,PARENT=Patient
FIELD NAME=(Billno,seq),BYTES=5,START=1,TYPE=C
FIELD NAME=Billdate,BYTES=10,START=6,TYPE=C
******************PAYMENT SEGMENT**********************
SEGM NAME=Payment,BYTES=20,PARENT=Billing
FIELD NAME=(Paydate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Amount,BYTES=10,START=11,TYPE=C
HIDAM Primary
Database(ESDS)
******************HOUSEHLD SEGMENT**********************
SEGM NAME=Househld,BYTES=8,PARENT=Patient
FIELD NAME=(Wardno,seq,m),BYTES=3,START=1,TYPE=C
FIELD NAME=Wardtype,BYTES=5,START=4,TYPE=C
******************END OF STRUCTURE**********************
DBDGEN
FINISH
END
HIDAM Primary Index(KSDS)
PRINT NOGEN
DBD NAME=IDXDBD,ACCESS=INDEX
DATASET DD1=idxdd1
******************INDEX SEGMENT**********************
SEGM NAME=IDXSEG,BYTES=5,PARENT=0
LCHILD NAME=(PATIENT,HOSPITAL),INDEX=PATNO
FIELD NAME=(Fld1,seq,u),BYTES=5,START=1,TYPE=C
DBDGEN
FINISH
END
HIDAM Access Method
(Secondary Indexing)
• Secondary indexes provide
alternate entry points when
processing HISAM, HIDAM, or HDAM
data bases.
• Segments can be accessed in a
sequence other than that specified
by the root key.
HIDAM Access Method
(Secondary Indexing)
For example, If you want to access
the Treatment(Intermediate or
Target) segment directly, you can
access it directly without
accessing the immediate and non-
immediate parents through
secondary indexing concept. The
number of call statements to the
database is reduced. Overall
processing is simplified and
efficient.
HIDAM Access Method
(Secondary Indexing)
REGULAR DATABASE SECONDARY INDEX DATABASE
SECONDARY INDEX
(KSDS)
TREATMENT KEY VALUES
HIDAM Primary
Database(ESDS)
PRINT NOGEN
DBD NAME=Hospital,ACCESS=(HIDAM,VSAM),
DATASET DD1=Hosdd,DEVICE=3390,SIZE=4096
******************PATIENT SEGMENT**********************
SEGM NAME=Patient,BYTES=45,PARENT=0
LCHILD NAME=(IDXSEG,IDXDBD),PTR=INDEX
FIELD NAME=(Patno,seq,u),BYTES=5,START=1,TYPE=C
FIELD NAME=Pname,BYTES=10,START=6,TYPE=C
FIELD NAME=Paddr,BYTES=30,START=16,TYPE=C
HIDAM Primary
Database(ESDS)
******************ILLNESS SEGMENT**********************
SEGM NAME=Illness,BYTES=18,PARENT=Patient
FIELD NAME=(Illdate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Illname,BYTES=10,START=11,TYPE=C
******************TRTMENT SEGMENT**********************
SEGM NAME=Treatmnt,BYTES=32,PARENT=Illness
LCHILD NAME=(SIDXSEG,SIDXDBD),PTR=INDEX
FIELD NAME=(Trdate,seq,m),BYTES=10,START=1,TYPE=C
XDFLD NAME=LOGNAME,SRCH=TRDATE
FIELD NAME=Medicine,BYTES=10,START=11,TYPE=C
FIELD NAME=Qnty,BYTES=4,START=21,TYPE=C
FIELD NAME=Doctor,BYTES=10,START=25,TYPE=C
HIDAM Primary
Database(ESDS)
******************BILLING SEGMENT**********************
SEGM NAME=Billing,BYTES=15,PARENT=Patient
FIELD NAME=(Billno,seq),BYTES=5,START=1,TYPE=C
FIELD NAME=Billdate,BYTES=10,START=6,TYPE=C
******************PAYMENT SEGMENT**********************
SEGM NAME=Payment,BYTES=20,PARENT=Billing
FIELD NAME=(Paydate,seq,m),BYTES=10,START=1,TYPE=C
FIELD NAME=Amount,BYTES=10,START=11,TYPE=C
HIDAM Primary
Database(ESDS)
******************HOUSEHLD SEGMENT**********************
SEGM NAME=Househld,BYTES=8,PARENT=Patient
FIELD NAME=(Wardno,seq,m),BYTES=3,START=1,TYPE=C
FIELD NAME=Wardtype,BYTES=5,START=4,TYPE=C
******************END OF STRUCTURE**********************
DBDGEN
FINISH
END
HIDAM Secondary
Index(KSDS)
PRINT NOGEN
DBD NAME=SIDXDBD,ACCESS=INDEX
DATASET DD1=idxdd2,OVFLW=idxdd3
******************INDEX SEGMENT**********************
SEGM NAME=SIDXSEG,BYTES=5,PARENT=0
LCHILD NAME=(TREATMNT,HOSPITAL),INDEX=LOGNAME
FIELD NAME=(Fld1,seq,m),BYTES=5,START=1,TYPE=C
DBDGEN
FINISH
END
HIDAM Primary & Secondary
Index Flow
OVFLW :
idxdd3
PRIMARY INDEX SECONDARY INDEX
(KSDS) (KSDS)
DD NAME : idxdd1 DD NAME : idxdd2
DATABASE
(ESDS)
DD NAME : hosdd
PCB Structure for
Secondary Index
TREATMENT
ILLNESS
PATIENT
BILLING HOUSEHLD
PAYMENT
PCB Coding for Secondary
Index
PCB TYPE=DB,NAME=Hospital,
PROCOPT=A,KEYLEN=43,PROCSEQ=SIDXDBD
SENSEG NAME=Treatmnt,PARENT=0
SENSEG NAME=Illness,PARENT=Treatmnt
SENSEG NAME=Patient,PARENT=Illness
SENSEG NAME=Billing,PARENT=Patient
SENSEG NAME=Payment,PARENT=Billing
SENSEG NAME=Househld,PARENT=Patient
PSBGEN LANG=Cobol,NAME=Spsb
END