Sunteți pe pagina 1din 111

IMS / DB

Table of Contents
Database System Definition and Types Introduction to IMS IMS terminologies, organization, access methods Control Blocks (DBD and PCB) DBD - Definition, Functions and Macros PSB - Definition, Functions and Macros How to run application program using DL/I SSAs Qualified and Unqualified Command Codes DL/I Calls Status Codes
2

IMS Fundamentals

Table of Contents (Contd..)


System service DL/I calls Checkpoint Restart Rollback calls Exercises Case Study HR Application

IMS Fundamentals

What is a Database System?


A system that allows multiple independent users to have concurrent access
to a central repository of information Advantages Centralized files for all applications Elimination of duplicate space and effort Single information source provides complete accurate information processing Concurrency and easily manageable.

IMS Fundamentals

Types of DBMS
1. Hierarchical A hierarchical database is a kind of database management system that links records together in a tree data structure such that each record type has only one owner, e.g. an order is owned by only one customer. Hierarchical structures were widely used in the first mainframe database management systems. However, due to their restrictions, they often cannot be used to relate structures that exist in the real world.

IMS Fundamentals

Types of DBMS (Contd..)


2. Network

The network model is a database model conceived as a more flexible alternative to the hierarchical model. Where the hierarchical model structures data as a tree of records, with each record having one parent record and many children, the network model allows each record to have multiple parent and child records, forming a lattice structure.

IMS Fundamentals

Types of DBMS (Contd..)


3. Relational

A relational database is organized into tables, in which data is defined so that it can be reorganized and accessed in a number of different ways without having to reorganize the database tables.

IMS Fundamentals

What is IMS?
IMS (Information Management System) is IBM's hierarchical database product
Hierarchical Data base management system that supports the application program while processing data bases in batch or on-line environments. IMS maintains an Inverted Tree Structure starting with the Root Segment by ensuring that no segment has more than one parent. The Hierarchy can go up to fifteen levels down. The Hierarchy can represent up to 255 segment types

IMS Fundamentals

Differences among batch routines

IMS program Where is Plan specified? Batch initialization routine? ?

IMS/DB2 program ?

DB2 program ?

IMS Fundamentals

Why IMS?
Advantages:
Large Volumes of Data can be handled Faster Access of Data Can be combined with DB2 for making data retrieval efficient (DB2 for querying and IMS for processing) Checkpoint restart feature available. Limitations: Not many tools for IMS compared to DB2 (File aid ~ file structure on pc) Rigid design of IMS doesnt make it programmer friendly

IMS Fundamentals

10

IMS Components
Five components of IMS Environment 1. Database Management System Is the heart of IMS subsystem. Shared by many concurrent tasks. Data is stored in DASD. Application programs access data by making DL/I calls. 2. DL/I (Data Language Interpreter) 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. Is an interface language used by the application program.

IMS Fundamentals

11

IMS Components (Contd..)


3. DL/I Control Blocks - There are two main DL/I control blocks namely, Database Descriptor (DBD) which describes the database structure and Program Communication Block (PCB) which identifies how the database may be accessed by the program. 4. Application Program Are designed and coded by the programmers. Programs use a standard DL/I interface to other IMS components. DL/I application programs use standard CALL statements with a parameter list to communicate with IMS. Programs may be written in COBOL, PL/I and ASM. Eg: first stmt in IMS program DLITCBL, all subsequent calls are CBLTDLI.

IMS Fundamentals

12

IMS Components (Contd..) & Features


5. Data Communication Is a set of program modules that allow the program to communicate with remote terminals. Programs communicate with terminals through a Standard Interface Language using CALL statements with a parameter list. Primary Products IMS/ESA Transaction Manager IMS/TM IMS/ESA Database Manager IMS/DB

Product Implementations
DC is used to implement the transaction manager DB is used to implement the database manager

IMS Fundamentals

13

Typical Hierarchical structure


DEALER
Parent of Model segment

MODEL

Child (dependent of dealer segment parent of order, stock, and sales Segments)

ORDER

STOCK

SALES

IMS Fundamentals

Dependents of Model Segment

14

Traversal in IMS database


IMS database traversal generally follows:
Top to bottom Left to right Front to back

Illustration follows:

IMS Fundamentals

15

Traversal in IMS database (Contd..)


Ep - 001 Emp - 002

Cp SSE

Ed1

Ad1

Cp SE

Cp SSE

Ed1

Ad1

Bd 22345 67890

Ec1

Bd 12345 67890

Bd 12988 76890

Ec1

Sd - Jan06 Sd - Feb06 Sd - Mar06

Sd - Jan05 Sd - Feb05 Sd - Mar05

Sd - Jan06 Sd - Feb06 Sd - Mar06

IMS Fundamentals

16

Explanation of diagram
The diagram shows how the data elements are arranged in IMS. Data elements are stored in the hierarchical structure or in other way we can say that some data elements are dependent on other. Each grouping of data is called as segments. A segment is the unit of data that DL/I transfers to and from your program. In previous diagram DEALER, MODEL, ORDER, STOCK and SALES are the names of segments.

IMS Fundamentals

17

Concept of Segments
In IMS, segments are defined by the order in which they occur and by their relationship with other segments.

The segment type at the top level of Hierarchy represents the Root segment. Like in the above case the DEALER represents the root segment.
An occurrence of the root segment plus all the segment occurrences subordinate to it makes one database record. All of the segments except the root segment are called dependent segments. Each dependent segment is also called the child segment.

IMS Fundamentals

18

Terms in an IMS Database


SEGMENT or SEGMENT TYPE - A segment is the smallest structure of the database in the sense that IMS cannot retrieve data in an amount less than a segment - Within each segment there can be one or more data fields - A database record can contain a maximum of 255 types of segments and one hierarchical path can have up to 15 segment types FIELDS - Segments can be broken down into smaller increments called fields, which can be addressed individually by application programs

IMS Fundamentals

19

Terms in an IMS Database (Contd..)


SEGMENT OCCURANCE - Segment Occurrence identifies the data that belongs to a particular Segment Type PARENT - A segment that has one or more dependant segments beneath it in the hierarchy. CHILD - A segment that is a dependent on another segment above it in the hierarchy.

IMS Fundamentals

20

Terms in an IMS Database (Contd..)


TWINS - All occurrences of a particular segment type under a single parent segment occurrence are called TWINS DATABASE (IMS) - A database consists of all root segment occurrences along with their dependents. - Is normally shared by multiple applications. DATABASE RECORD - A database record has one root segment occurrence along with all the occurrences of its child segments in hierarchic sequence

IMS Fundamentals

21

Organization and Access Methods


Organization The way data is organized. e.g. KSDS,ESDS,RRDS,LDS Access Method The process followed to access the data. E.g. VSAM IMS Access Methods are Hierarchic sequentially accessed databases HSAM, SHSAM, HISAM, SHISAM, GSAM Hierarchic direct databases HDAM, HIDAM Fast Path databases provide fast access with limited functionality DEDB, MSDB
IMS Fundamentals 22

Control Blocks
IMS uses two kinds of control blocks to enable application programs The database descriptor/definition (DBD) and Program communication block (PCB). Database Description (DBD)

A database descriptor (DBD) is a control block that describes the physical structure of the database. The DBD also defines the appearance and contents, or fields, that make up each of the segment types in the database. It describes the way in which it is stored on the DASD and the way it is accessed.

IMS Fundamentals

23

Control Blocks (Contd..)


Program Communication Block (PCB) A program communication block (PCB) defines an application program's view of the database. It describes the logical structure of a database as a particular program views it. It identifies which pieces of a data a program is allowed to access and the kinds of functions (operations) it can perform on each collection of data. This is useful when an application program needs to process only some of the segments in a database which is a very common need.

IMS Fundamentals

24

What is DL/I ?

DL/I is Data Language Interpreter is a data management facility that

serves as an interface between an application program and a database.

IMS Fundamentals

25

DL/I and Application program

DL/I

and the Application Program


OPERATING SYSTEM

DL/I Your Address Space or Region

DATA BASE

DBD

PSB

APPLICATION PROGRAM

IMS Fundamentals

26

How DL/I Relates to your application program


STANDARD FILE PROCESSING APPLICATION PROGRAM DL/I DATA BASE PROCESSING APPLICATION PROGRAM
CALLS TO DL/I

STANDARD COBOL I/O STATEMENTS

DL/I

OPERATING SYSTEM ACCESS METHOD

OPERATING SYSTEM ACCESS METHOD

FILE DATA SET

DATABASE DATASET

IMS Fundamentals

27

DBD - Data base definition


DBD A database description/definition (DBD) is a series of macro statements that define the type of database, all segments and fields, and any logical relationships or indexing. DBD macro statements are submitted to the DBDGEN utility, which generates a DBD control block and stores it in the IMS.DBDLIB library for use when an application program accesses the database. Apart from describing the physical structure and interdependency of segments in database, it also names the DBD and the access method that will be used by DL/I for data manipulation.

IMS Fundamentals

28

Defining DBD
Suppose the ACCENTURE hierarchical structure has been designed. The name of the segments has been chosen. Now we must tell IMS about this database. IMS needs to know about all the keys, search fields, and relationships that are designed as part of the organization database.

The DBD is usually coded by a DBA (Data Base Administrator). It is then submitted to the system with JCL that invokes a procedure called DBDGEN. This procedure produces an object module which is in turn passed to the linkage editor which produces a load module. The load module is stored in a library named something like IMSVS.DBDLIB.

IMS Fundamentals

29

DBD Functions
Defines the physical storage information. Defines the hierarchical structure. Define the relationship between the segments. Defines the segment layouts. Defines the key field with in the segment. Describe the information necessary to create the database. Defines any logical relationship. Defines the secondary index.

IMS Fundamentals

30

DBD - Data base definition Macros


DBD DATASET Names the database being described and specifies its organization. Specifies the names of files used to store the data. Defines each file which comprises the data base. It defines the DD names and the dataset information. Defines the name of the segment type, its position in the data base and how it is related to other segments. Defines a relationship between two different segment types. This could be an index relationship, a logical relationship or a secondary index. Defines a field within a segment. It identifies the field name, its length in bytes, its starting position, and the type of data in the field.

SEGM LCHILD FIELD

IMS Fundamentals

31

DBD-Data base definition Macros


(Contd..)
XDFLD DBDGEN Defines the source fields for a secondary index. This statement ends the SEGM and FIELD definitions for the DBD. Marks the end of statements defining the DBD. This statement marks the end-of-data to the assembler process.

END

IMS Fundamentals

32

Data Base Definition/Descriptor (DBD)


The first macro DBD identifies the name of the Database and Access Methods The second macro is DATASET which defines the DD name that will be mentioned in the run JCL The SEGM Macro is used to define a segment and each SEGM Macro will have many Fields (defined by FIELD NAME) PARENT=0 indicates that it is a root segment The Segments in the DBD should be listed in the same order as that in the Database The TYPE indicates the type of data being referred to

IMS Fundamentals

33

Data Base Descriptor (DBD)


(Contd..)
The RULES can be FIRST, LAST AND HERE. This is primarily used for INSERT operations with no key field or has a NON UNIQUE key.
RULES = LAST Insert as the LAST OCCURANCE for the NON UNIQUE key RULES =FIRST Insert as the FIRST OCCURANCE for the NON UNIQUE key RULES = HERE Insert at the CURRENT POSITION established in the database for the corresponding NON UNIQUE key PARENT=(SEGMENTNAME,SNGL) Only pointer PARENT=(SEGMENTNAME,DBLE) Two pointers DBDGEN process creates the DBD load

IMS Fundamentals

34

Data types in DBD Macro


The following data types are allowed in a DBD macro:
C : Character P : Packed decimal Z : Zoned decimal X : Hexadecimal H : Halfword binary F : Fullword binary

IMS Fundamentals

35

Hands On - DBD

Create the structure of a Database from the given DBD in mainframe

IMS Fundamentals

36

PSB Program specification block


PSB is the view of an IMS database or the "Program Can See part of the database for an application program

Describes the logical structure of one or more data bases to the application program
The logical data structure is defined by creating PSB

Defines segment sensitivity for each data base


Defines the processing options for the segments

IMS Fundamentals

37

PSB - Program specification block


(Contd..)

The PSB is made up of PCBs (program communication blocks)


Each PCB refers to a particular view of the database If our program is using 5 databases then we need to have minimum 5 PCB's, each PCB pointing to a particular database

In order to execute in the IMS environment, a program must have a PSB that specifies all of the data bases and data base segments that the program may access.

IMS Fundamentals

38

PSB - Program specification block


(Contd..)
The PSB statements are processed by the PSBGEN and a load module is produced, much the same as the DBDGEN process. Within the PSB are one or more control blocks, called PCBs or program communication blocks. There is a control block for each data base that may be accessed. If more than one pointer is required for processing the data base in the program, then there will be multiple PCBs for the same data base. If there is a secondary index associated with the data base, then there is a separate PCB to specify the secondary index processing option.

IMS Fundamentals

39

PSB - Program Specification Block - Macros


PCB Defines the database to be accessed by the application program. The statement also defines the type of operations allowed by the application program. Each database requires a separate PCB statement. PSB generation allows for up to 255 database PCBs.

SENSEG Defines the segment types to which the application program will be sensitive. A separate SENSEG statement is required for each segment type. If a segment is defined as sensitive, all the segments in the path from the root to that segment must also be defined as sensitive.

IMS Fundamentals

40

PSB - Program Specification Block Macros (Contd..)


SENFLD - Defines the fields in a segment type to which the application program is sensitive. Can be used only in association with field-level sensitivity. The SENFLD statement must follow the SENSEG statement to which it is related. PSBGEN - Identifies the language of the program that will use the PSB and gives a name to the PSB coded at the end.

IMS Fundamentals

41

PSB - Program Specification Block Macros (Contd..)


PROCOPT - Defines the type of access to a database or segment. PROCOPTs can be used on the PCB or SENSEG statements. Primary PROCOPT codes are as follows: G R I D read only replace, includes G insert delete, includes G

IMS Fundamentals

42

PSB - Program Specification Block Macros (Contd..)


A K get and update, includes G, R, I, D used on SENSEG statement; program will have key-only sensitivity to this segment load database

L/LS -

Secondary PROCOPT codes are as follows: E O P S exclusive use of hierarchy or segments get only, does not lock data when in use must be used if program will issue path call using the D command code sequential (LS is required to load HISAM and HIDAM databases; GS gets in ascending sequence)
43

IMS Fundamentals

PSB - Program Specification Block


(Contd..)

Illustration of using PROCOPT codes.

PCB

TYPE=DB DBDNAME=INVENORG, KEYLEN=24, PROCOPT=GO (G as primary, O as secondary)

IMS Fundamentals

44

PSB - Program Specification Block


(Contd..)
SENSEG SENSEG NAME=LOCATION,PARENT=0, PROCOPT=O NAME=PROJECT,PARENT=LOCATION

SENSEG
PSBGEN END

NAME=EMPLOYEE,PARENT=PROJECT, PROCOPT=A
LANG = COBOL,PSBNAME=ORGAN

IMS Fundamentals

45

PSB - Program Specification Block


(Contd..)
TYPE=DB TYPE=TP SENSEG -- required for each database the program can access -- required for output message destinations in case of IMS/DC -- required for each segment in the database the application program can access (up to 30000 SENSEG statements can be defined for PSB generation) SENFLD -- required for each field in the segment that an application program can access (up to 255 SENFLD statements can be defined for each SENSEG and an overall 10000 SENFLD can occur in a PSB) PROCOPT -- required to specify the program's processing options KEYLEN -- indicates the greatest KEYLEN from all the paths in a DB PSBGEN -- required for each PSB generation END -- required for each PSB generation
IMS Fundamentals 46

Hands On - PSB

Create the structure of a PSB from the given DBD in mainframe

IMS Fundamentals

47

How to Run an Application Program Using DL/I


DL/I Batch initialization module (DFSRRC00). //STEP1 EXEC PGM=DFSRRC00,REGION=962K,TIME=2,COND=(4,LT), // PARM=(DLI,PGMNAME,PSBNAME,,,,,,,,,,,N)

Application program and DL/I execute together.


CALL CBLTDLI USING DLI-function

PCB-Mask Segment-io-area { SSA(s) }


IMS Fundamentals 48

COBOL Basics For Processing a DL/I database


ENTRY statements ENTRY 'DLITCBL USING PCB-MASK1 PCB-MASK2 PCB-MASK3

The order in which the PCB masks appear in the Entry Statement is important, the linkage section PCB-Mask's can be in any order. GOBACK instead of STOP RUN.

IMS Fundamentals

49

COBOL Basics For Processing a DL/I database (Contd..)


LINKAGE SECTION. 01 PCB-MASK1. 05 PCB-EMPLOYEE-DB. 10 PCB-DBN-DB1 10 PCB-LEV-DB1 10 PCB-STC-DB1 10 PCB-PRO-DB1 10 PCB-RES-DB1 10 PCB-SGN-DB1

10 PCB-LKF-DB1
IMS Fundamentals

--> Name of Database --> Level of last successful call PIC X(02). --> Status Code PIC X(04). --> PROCOPT from PSB PIC S9(5) COMP. --> Reserved for DL/I PIC X(08). --> Last Segment Successfully retrieved in a call PIC S9(5) COMP. --> Length of Concatenated Key
50

PIC X(08). PIC X(02).

COBOL Basics For Processing a DL/I database (Contd..)


10 PCB-NOS-DB1 PIC S9(5) COMP. --> Number of Segments used to create the concatenated key 10 PCB-KFB-DB1 PIC X(26). --> Key Feed Back Area (to get the concatenated key) 10 FILLER REDEFINES PCB-KFB-DB1. 15 PCB-KFB-KEY1-SEG1-EMPDB PIC X(06). 15 FILLER PIC X(20). Key

IMS Fundamentals

51

Some common status codes


SPACES successful retrieval. GB End of database. GE Not found. II Duplicate segment while insertion. DA Key field changed. DJ No get hold call before DLET or REPL. GK Segment of diff type but at the same hierarchical level. GA Higher level segment was retrieved during sequential call.

IMS Fundamentals

52

SSA - Segment Search Argument


Segment Search Argument The SSA is used to specify to DL/I the segment and path of the data you want to access with the DL/I call. In most cases, a separate SSA is used for each hierarchical level on the path to the required segment. The SSA may be unqualified or it may be qualified with the key field name and value of the segment being accessed. An example of a typical SSA entry in a COBOL application program. The KEY-FIELD-VALUE depends on the length of the key field of the segment being searched.

IMS Fundamentals

53

SSA - Segment Search Argument


(Contd..)
01 SSA1. 05 SEGMENT-NAME PIC X(08). 05 COMMAND-CODES PIC X(03). 05 LEFT-PAREN PIC X(01). 05 KEY-FIELD-NAME PIC X(08). 05 OPERATOR PIC X(02). 05 KEY-FIELD-VALUE PIC X(08). 05 RIGHT-PAREN PIC X(01). CALL CBLTDLI USING CALL-FUNCTION PCB-DB IO-AREA SSA1 SSA2 . . . SSA n.
IMS Fundamentals 54

SSA - Segment Search Argument


(Contd..)
An SSA contains the following statements: SEGMENT NAME COMMAND CODES - This value tells DL/I which segment to access. - IMS command codes can be used here to modify the DL/I call.

LEFT PAREN (OR SPACE) - If left blank, the SSA will be an unqualified SSA.

IMS Fundamentals

55

SSA - Segment Search Argument


(Contd..)
KEY FIELD NAME - The key field, search field, or index field that will be used in the segment search. OPERATOR - A relational operator (for example, EQ, GT, LT) can be used.

KEY FIELD VALUE - This is the value of the field that will be processed. RIGHT PAREN - This statement is used to indicate the end of the SSA.

IMS Fundamentals

56

Qualified and Unqualified SSAs


Qualified call A qualified call is the one in which we have SSAs. Qualified call can be either with Qualified SSA or Unqualified SSA. Qualified SSA Has 8 characters segment name followed by ( in the 9th position of the SSA defined. Unqualified SSA Has 8 characters Segment name followed by space in the 9th position of the SSA defined. Unqualified call An un-qualified call on the other hand has no SSA.
IMS Fundamentals 57

DL/I Calls
The purpose of a DL/I call is to instruct DL/I to perform a certain action involving the data stored in the IMS database. A DL/I call includes four parts : CALL FUNCTION - Tells DL/I what needs to be done (for example, retrieve, update, insert, delete). PCB - Gives the name of the PCB of the database that will be referenced by the call. I/O AREA - Specifies the work area for the requested segment. SSA - Specifies the segment and path of the data to be accessed.

IMS Fundamentals

58

DL/I Calls (Contd..)


Format of a DL/I call in a COBOL application program. CALL CBLTDLI USING CALL-FUNCTION PCB-DB IO-AREA SSA1 SSA2 . . . SSA n.

IMS Fundamentals

59

DL/I Calls (Contd..)


DL/I calls can be subdivided into: Retrieval calls Update calls and Miscellaneous calls Generally all the DL/I calls are defined in a copybook and copied into the program. There by reusing the copybook in all IMS programs. Only calls that are required by a program can be used.

IMS Fundamentals

60

Retrieval calls
GU (Get Unique) GN (Get Next) Gets the first segment which matches the qualifiers Gets the next segment in hierarchic order which matches the qualifiers in the call

GNP (Get Next Within Parent) Gets the next segment under the current parent which matches the qualifiers specified in the call GHU (Get Hold Unique) GHN (Get Hold Next) GHNP (GHN Within Parent)
IMS Fundamentals

Same as GU, but locks the segment for subsequent update (DLET or REPL) Same as GN, but locks the segment for subsequent update (DLET or REPL) Same as GNP, but locks the segment for subsequent update (DLET or REPL)
61

Update calls
ISRT (Insert) REPL (Replace) To insert a segment in the database To replace an existing segment with new data (The key to segment can not be changed, and previous 'GET HOLD' command must be issued) To delete an existing segment from the data base (The previous 'GET HOLD' command must be issued)

DLET (Delete)

IMS Fundamentals

62

Miscellaneous Calls
CHKP To take a 'check point' or 'commit updates to the database before the program terminates. To restore the database position after a check point has been taken To schedule a PSB in an on-line program To terminate a PSB in an on-line program

XRST

PCB TERM

IMS Fundamentals

63

Command Codes
Command Codes in a SSA makes the call powerful since DL/I treats such SSAs differently from those without the command codes while performing some special functions. Command codes save programming and processing time. Command codes are specified in an SSA following the segment name and an Asterisk *. * in the ninth position in a SSA indicates that one or more command codes follow the * and 10th position will be reserved for the command code. 11th position will be for the left parenthesis (. A Blank or Left parenthesis marks the end of the command codes.
IMS Fundamentals 64

Command Codes

(Contd..)

ONE or MORE command codes can be used in any combination using relational operators like &. Command Codes are codes specified in the SSAs that help to optimize the performance of IMS programs and leads to Simplified Coding. Command Codes extend the functionality of DL/I calls. Multiple DL/I calls can be reduced to a single DL/I call by using Command Codes. If we dont need to use Command Codes while processing we can override the existing command code in the program (before the call where SSA is used) by passing/using the NULL (-) Command Code.

IMS Fundamentals

65

Command Codes

(Contd..)

The 10 Command Codes available in IMS are :


C D F L N Q
IMS Fundamentals

Concatenated key in the SSA. Retrieve this segment data into the I-O Area (Path call). Locate the first segment occurrence that satisfies the SSA. Locate the last segment occurrence that satisfies the SSA. Do not replace this segment. Locks a segment for your program's exclusive use.
66

Command Codes
U

(Contd..)

Specify the current database positions at that level is not allowed to be changed by the call

P
V

Establish Parentage at this level


Specify the current database position at that & all levels above are not allowed to be changed by the call

'NULL Used as the place holder in SSA's so that command codes can be removed/inserted from SSA's without having to define separate SSA's in working storage.

IMS Fundamentals

67

Examples for command codes


Command code C can be used to replace multiple SSAs into one single SSA. If we are retrieving just lower level segment occurrences instead of defining multiple SSAs, with field name, relational op and search value, define the concatenated key for the segment.

01 Employee-Bankdetl-SSA. 05 Filler pic x(11) value EMPLOYEE*C(. 05 Employee-SSA-empno pic x(06) value spaces. 05 Compdtl-SSA-desg pic x(02) value spaces. 05 Bankdtl-SSA-acctno pic x(10) value spaces. 05 Filler pic x value ). 01 Bankdtl-IO-area pic x(21). . . Procedure Division. Pass the key values to empno, desg and account no. before the call. Call CBLTDLI Using DLI-GU PCB-Mask Employee-Bankdetl-SSA Bankdtl-IO-area
IMS Fundamentals 68

Examples for command codes


(Contd..)
Command code D (path call) can be used to replace multiple IMS CALL statements with a single CALL statement. If we need to retrieve all the I/O areas of the path traversed, the calls can be combined together with a I/O area definition, that would accommodate all the fields retrieved. IO area should be defined with caution.

01 Employee-SSA. 05 Filler pic x(11) value Employee*D(. 05 Filler pic x(10) value Emplno =. 05 empl-no pic x(06). 05 Filler pic x value ). 01 Compdtl-SSA. . 01 Bankdtl-SSA. . 01 Path-Call-IO-area. 05 emp-io-area pic x(56). 05 comp-io-area pic x(12). 05 bank-io-area pic x(11). Procedure Division. Call CBLTDLI using

DLI-GU Pcb-mask path-call-io-area employee-ssa compdtl-ssa bankdtl-ssa

IMS Fundamentals

69

Some examples of IMS retrieval calls

GU - Get Unique - Fully Qualified SSA


01 LOCATE-QSSA.
05 05 05 05 05 F F LOCATE-OP F PIC X(9) VALUE LOCATION(. PIC X(08) VALUE LOCATEID. PIC X(02) VALUE SPACES. VALUE ZERO. VALUE ). LOCATE-OP PIC X(01) TO

11000000 10000009

LOCATE-KEY PIC X(08)

MOVE 100000009

TO LOCATE-KEY GU-FUNCTION ORGAN-PCB-MASK LOCATE-SEGMENT

PROJ0002

MOVE EQ CALL CBLTDLI USING

EMP00002 EMP00003

LOCATE-QSSA IF LOCATE-PCB-STATUS = bb CONTINUE ELSE PERFORM error-routine.

IMS Fundamentals

70

IMS retrieval calls (Contd..)

GU - Multiple Fully Qualified SSAs


MOVE 10000009 MOVE EQ MOVE PROJ0002 MOVE EQ TO LOCATE-KEY TO LOCATE-OP TO PROJECT-KEY TO PROJECT-OP PARTS-PCB-MASK SUPPLIER-SEGMENT LOCATE-QSSA PROJECT-QSSA IF LOCATE-PCB-STATUS = bb CONTINUE ELSE PERFORM error-routine.

10000000 10000009

CALL CBLTDLI USING GU-FUNCTION

PROJ0001 PROJ0002

EMP00001 EMP00002 EMP00003

IMS Fundamentals

71

IMS retrieval calls (Contd..)

GU - Get Unique - Unqualified SSA


01 LOCATE-QSSA. 05 F PIC X(9) VALUE LOCATION . ORGAN-PCB-MASK LOCATE-SEGMENT

11000000 10001009

CALL CBLTDLI USING GU-FUNCTION

PROJ0001 PROJ0002

LOCATE-QSSA. IF LOCATE-PCB-STATUS = bb CONTINUE ELSE PERFORM error-routine.

EMP00001 EMP00002 EMP00003

IMS Fundamentals

72

IMS retrieval calls (Contd..)

GU MULTIPLE - Unqualified SSA


11000000 10001009 10000001
01 LOCATION-USSA. 01 PROJECT-USSA 05 F PIC X(9) PIC X(9) VALUE LOCATION . VALUE PROJECT .

01 EMPLOYEE-USSA PIC X(9)

VALUE EMPLOYEE .

PIC X(9) VALUE LOCATION . ORGAN-PCB-MASK EMPLOYEE-SEGMENT LOCATION-USSA PROJECT-USSA EMPLOYEE-USSA.

CALL CBLTDLI USING GU-FUNCTION

PROJ0001 PROJ0002

EMP00001 EMP00002 EMP00003

IF LOCATE-PCB-STATUS = bb CONTINUE ELSE PERFORM error-routine.

IMS Fundamentals

73

IMS retrieval calls (Contd..)

GU MISSING - SSAS
01 LOCATE-QSSA. 05 F PIC X(9) VALUE LOCATION . GU-FUNCTION ORGAN-PCB-MASK PROJECT-SEGMENT PROJECT-USSA CALL CBLTDLI USING

11000000 10001009 10000001

PROJ0001 PROJ0002

EMPLOYEE-USSA.
IF ORGAN-PCB-STATUS = bb CONTINUE ELSE PERFORM error-routine.

EMP00001 EMP00002 EMP00003

IMS Fundamentals

74

IMS retrieval calls (Contd..)

GU NO - SSAS

11000000 10001009
CALL CBLTDLI USING GU-FUNCTION ORGAN-PCB-MASK LOCATE-SEGMENT

PROJ0001 PROJ0002

IF ORGAN-PCB-STATUS = bb
CONTINUE ELSE PERFORM error-routine.

EMP00001 EMP00002 EMP00003

IMS Fundamentals

75

IMS retrieval calls (Contd..)

GN - Fully Qualified SSA


01 LOCATE-QSSA. 05 F F LOCATE-OP LOCATE-KEY F TO PIC X(9) VALUE LOCATION(. PIC X(08) VALUE LOCATEID. PIC X(02) VALUE ZERO. PIC X(08) PIC X(01) VALUE ZERO. VALUE ). 05 05 05 05

11000000 10000009

PROJ0001 PROJ0002

MOVE 110000000 MOVE EQ

TO LOCATE-KEY LOCATE-OP

CALL CBLTDLI USING GN-FUNCTION ORGAN-PCB-MASK LOCATE-SEGMENT LOCATE-QSSA IF LOCATE-PCB-STATUS = bb CONTINUE

EMP00001 EMP00002 EMP00003

ELSE
PERFORM error-routine.
IMS Fundamentals 76

IMS retrieval calls (Contd..)

GN - Unqualified SSA
11000000 10001009
01 LOCATE-QSSA. 05 F PIC X(9) VALUE EMPLOYEE . ORGAN-PCB-MASK CALL CBLTDLI USING GU-FUNCTION

PROJ0001 PROJ0002
CONTINUE

LOCATE-SEGMENT EMPLOYEE-USSA. IF LOCATE-PCB-STATUS = bb ELSE PERFORM error-routine.

EMP00001 EMP00002 EMP00003

IMS Fundamentals

77

IMS retrieval calls (Contd..)


GN MULTIPLE Unqualified SSAS
11000000 10001009 10000001

CALL CBLTDLI USING GN-FUNCTION ORGAN-PCB-MASK EMPLOYEE-SEGMENT LOCATION-QSSA PROJECT-QSSA EMPLOYEE-USSA. IF LOCATE-PCB-STATUS = bb

PROJ0001 PROJ0002

EMP00001 EMP00002 EMP00003

CONTINUE
ELSE PERFORM error-routine.

IMS Fundamentals

78

IMS retrieval calls (Contd..)


GN-Combination of SSA types
11000000 10001009 10000001

CALL CBLTDLI USING

GN-FUNCTION ORGAN-PCB-MASK GENERAL-IO-AREA .

PROJ0001 PROJ0002

IF LOCATE-PCB-STATUS = bb OR GA OR GK

CONTINUE
ELSE PERFORM error-routine.

EMP00001 EMP00002 EMP00003

IMS Fundamentals

79

IMS retrieval calls (Contd..)


GN - No SSAS
11000000 10001009 10000001
01 LOCATION-USSA. 01 PROJECT-USSA 05 F PIC X(9) PIC X(9) VALUE LOCATION . VALUE PROJECT .

01 EMPLOYEE-USSA PIC X(9)

VALUE EMPLOYEE .

PIC X(9) VALUE LOCATION . ORGAN-PCB-MASK EMPLOYEE-SEGMENT LOCATION-USSA PROJECT-USSA EMPLOYEE-USSA.

CALL CBLTDLI USING GU-FUNCTION

PROJ0001 PROJ0002

EMP00001 EMP00002 EMP00003

IF LOCATE-PCB-STATUS = bb CONTINUE ELSE PERFORM error-routine.

IMS Fundamentals

80

IMS retrieval calls (Contd..)

GNP GET NEXT WITH IN PARENT


11000000 10001009 10000001
CALL CBLTDLI USING GU-FUNCTION ORGAN-PCB-MASK LOCATION-SEGMENT LOCATIONI-QSSA IF ORGAN-PCB-STATUS = BB

PROJ0001 PROJ0002

PERFORM 1500-GNP-PROJECT

UNTIL ORGAN-PCB-STATUS = GE
ELSE PERFORM ERROR-ROUTINE 1500-GNP-PROJECT. CALL CBLTDLI USING GNP-FUNCTION ORGAN-PCB-MASK SUPPLIER-SEGMENT PROJECT-USSA

EMP00001 EMP00002 EMP00003

IMS Fundamentals

81

ISRT Calls
Inserts a new segment occurrence. Before issuing the call, you must populate the I/O area for the new segment. The I/O area must contain the same fields in the same order, length, and data types that exist on the segment being inserted. ISRT Calls are used to add segments to a DL/I database either during the update processing of new segments or during the load operation. ISRT calls can use qualified or unqualified SSA s, E.g. Of ISRT Call using an unqualified EC SSA, make sure of the pointer before unqualified call.

IMS Fundamentals

82

ISRT Calls

(Contd..)

DL/I will try to execute this call by inserting the EC occurrence in the Database based on the current position in the database CALL 'CBLTDLI' USING CN-ISRT PCB-MASK1 WK-OUTPUT-REC WS-UNQUAL-EC-SSA

E.g. Of ISRT Call using a qualified call CALL 'CBLTDLI' USING CN-ISRT PCB-MASK1 WK-OUTPUT-REC WS-QUAL-EMP-SSA WS-QUAL-CP-SSA WS-UNQUAL-BD-SSA
83

IMS Fundamentals

ISRT Calls

(Contd..)

DL/I will try to execute this call by inserting the BD occurrence in the Database based on the position obtained from the QUAL-EMP segment occurrence and the QUAL-CP segment occurrence.

DL/I returns status code GE if the segment occurrence mentioned using the qualified SSA s is not found.
When the lower level segment types in a database have non unique sequence fields or dont have any sequence fields then the ISRT works based on RULES specified in the DBD. RULES = FIRST, the new segment occurrence is inserted before all existing twins

RULES = LAST, the new segment occurrence is inserted after all existing twins
IMS Fundamentals 84

ISRT Calls

(Contd..)

RULES = HERE, the new segment occurrence is inserted at the current position in the database
The RULES mentioned in the DBD can be overridden by Command Code RULES = FIRST can be overridden by coding Command Code L in SSA However RULES = LAST, CANNOT be overridden by coding Command Code F The D Command Code can be specified to insert more than one segment occurrence types along a path

IMS Fundamentals

85

ISRT Calls

(Contd..)

When D Command Code is being used for insert, the PROCOPT=P should be specified in the PSB. For Load operation, all segments must be inserted in hierarchical sequence. Also the PSB must have PROCOPT = L or LS.

The Status Code GE during ISRT calls happen when the segment occurrence being inserted with Qualified SSA s is not present in the database.

IMS Fundamentals

86

ISRT Calls

(Contd..)

The Status Code II during ISRT calls happen when we try to add a segment occurrence thats already present in the database The Status Code LB during ISRT calls in LOAD operation happen when we try to add a segment occurrence thats already present in the database. The Status Code LC during ISRT calls in LOAD operation happen when the input data is not in hierarchical sequence. The Status Code LD during ISRT calls in LOAD operation happen when one or more segments in the path to the segment being loaded are missing.

The Status Code LE during ISRT calls in LOAD operation happen when the sequence of segment types isnt the same as that specified in the DBD

IMS Fundamentals

87

ISRT Calls (INSERT MODE) Status Codes


The following are some status codes encountered while issuing a ISRT call to insert a segment into an already loaded database:

II The segment already exists in the database. A duplicate key value is being inserted into.
IX Encountered an Insert Rule Violation. Program tried to insert a segment into the wrong place. For e.g. A stock segment is being inserted under the Dealer segment, when it is in fact dependant upon the Model segment.

IMS Fundamentals

88

ISRT Calls (LOAD MODE) Status Codes


The following are some status codes encountered while issuing a ISRT call to load segments into an empty database:

LB When you try to load the same segment twice i.e. segment already exists LC The segments being loaded are not in their Hierarchical sequence i.e. key values out of sequence LD No Parent for the segments being loaded. You cannot load a dependant segment until its parent has been loaded LE Segment types out of sequence. For e.g. If you tried to load a stock segment before a model segment

IMS Fundamentals

89

REPL Calls
Replaces current data in a selected segment with new data from the I/O area. It must be preceded by a GHU, GHN, or GHNP call. A REPL generally does not use an SSA. The segments key fields cannot be changed. There are two restrictions for REPL Calls Cannot change the length of the Segment Cannot change the value of the Sequence Field Never Code a qualified SSA on a REPL Call. Replace processing can be done with Path Calls.
IMS Fundamentals 90

REPL Calls

(Contd..)

For Replace operation with Path Calls, we can negate replacement of certain intermediate segment occurrences by giving Command Code N

E.g. Of REPL Call


CALL 'CBLTDLI' USING CN-GHU PCB-MASK1 WK-REC WS-QUAL-EMP-SSA WS-QUAL-SAL-SSA WS-QUAL-TAX-SSA Change some values obtained in WK-REC
IMS Fundamentals 91

REPL Calls

(Contd..)

CALL 'CBLTDLI' USING CN-REPL PCB-MASK1 WK-REC

The above call will first retrieve a tax occurrence, make some changes to it and then replace it using REPL call .

IMS Fundamentals

92

REPL Calls

(Contd..)

The Status code AJ happens when we try to use Qualified SSA on a REPL Call The Status Code DJ happens when a GHU or GHN call doesnt precede the REPL Call The Status Code DA happens when the program tries to make change to the Segment Key field before giving REPL call

IMS Fundamentals

93

REPL Calls Status Codes


The following are some status codes encountered while issuing a REPL call :

DJ Replace call issued without an immediately preceding GETHOLD call


DA Program has changed the segments KEY FIELD RX Encountered a Replace Rule Violation AJ Used a qualified SSA

IMS Fundamentals

94

DLET Calls
Deletes the segment previously retrieved and all of its dependents, even if the application is not defined as sensitive to them. It must be preceded by a GHU, GHN, or GHNP call (see GET HOLD Calls). Deletes generally do not use SSAs. Works similar to a REPL call, a Get Hold Call should be given first followed by a DLET call. Never code a qualified SSA with DLET call.

Unqualified SSA s can be coded in a DLET call when we are using Path Calls (Command Code D, since the pointer position is known)
IMS Fundamentals 95

DLET Calls

(Contd..)

A DLET Path Call will delete the entire path. The scope of a Path Delete can however be limited by supplying one unqualified SSA without a command code, such calls should be avoided unless sure of the pointer position.

The Status code AJ happens when we try to use Qualified SSA on a DLET Call.
The Status Code DJ happens when a GHU or GHN call doesnt precede the DLET Call. The Status Code DA happens when the program tries to make change to the Segment Key field before giving DLET call.
IMS Fundamentals 96

DLET Call Status Codes


The following are some status codes encountered while issuing a DLET call :

DJ Delete call issued without an immediately preceding GETHOLD call


DA Program has changed the segments KEY FIELD DX Encountered a Delete Rule Violation AJ Used a qualified SSA

IMS Fundamentals

97

Some more DL/I Status codes


AB AC AH AJ AI The call did not specify a segment IO area SSA with a hierarchical error Call requires at least one SSA Call specifies an Invalid SSA Error encountered when trying to open the database dataset. An error in the JCL DD statement The field named in a qualified SSA is not correct The IO area specified in the call is too large but the programs PSB may be incorrect Call caused an operation resulting in a physical IO error

AK AT AO

IMS Fundamentals

98

System Service DL/I Calls


The four important DL/I calls that perform various system service functions are : 1) CHKP 2)XRST 3)ROLL 4)ROLB

CHECKPOINT (CHKP) Call


A point in the execution of program when the changes made to the database are considered complete and accurate. Checkpoint (CHKP) call is used for recovery purposes, in the IMS programming environment it is the method used to ensure data integrity. Once check pointed, the changes made are not reversible. CHKP call causes all the database changes made since the last checkpoint to be permanently committed to the physical database thereby making Backout impossible. A CHKP call causes the database position for a PCB to be reset, apart from releasing all the locks held by the program.

IMS Fundamentals

99

System Service DL/I Calls (Contd..)


In addition, the CHKP call Enables you to save as many as seven data areas in your program, which are restored when your program is restarted In case of ABENDs, IMS will control the process of backing out database updates up to the last checkpoint. Works with the Extended Restart (XRST) call to restart your program if it terminates abnormally

IMS Fundamentals

100

Checkpoint Restart
Why checkpointing? If there are other jobs updating or reading the tables, there should be a checkpoint at an interval < the DB2 timeout interval (typically 30 seconds will suffice). When A large amount of locking activity is taking place. Locks are a finite resources in a DB2 Subsystem. When we do not want to lose work already accomplished. If a job runs a long time, recovery is not just re-running the job, but also waiting for DB2 to roll back changes. Checkpoint intervals are based on the situation. For example, if online activity is present, or we are running parallel processes, checkpoints should be taken at 10 second intervals. If we are running stand alone batch, and have exclusive access to our tables, we might go as high as 60 seconds.
101

IMS Fundamentals

Checkpoint Restart (Contd..)


E.g.
MOVE LENGTH MOVE LENGTH MOVE LENGTH MOVE LENGTH MOVE LENGTH MOVE LENGTH MOVE LENGTH CALL CBLTDLI OF W400-REFORMAT-AREAS TO FJCHKPTL-LENGTH-1 OF W410-INDICATORS TO FJCHKPTL-LENGTH-2 OF W450-COUNTERS TO FJCHKPTL-LENGTH-3 OF W460-HOLD-AREA TO FJCHKPTL-LENGTH-4 OF GVPOINPT-PO-DETAILS TO FJCHKPTL-LENGTH-5 OF W700-CHKP-IO-AREA TO FJCHKPTL-LENGTH-6 OF GVFULOLT-DETAILS TO FJCHKPTL-LENGTH-7 USING DLI-CHKP L100-LOGICAL-TERMINAL-PCB FJCHKPTL-LENGTH-1 W400-REFORMAT-AREAS longest segment first FJCHKPTL-LENGTH-2 W410-INDICATORS FJCHKPTL-LENGTH-3 W450-COUNTERS FJCHKPTL-LENGTH-4 W460-HOLD-AREA FJCHKPTL-LENGTH-5 GVPOINPT-PO-DETAILS FJCHKPTL-LENGTH-6 W700-CHKP-IO-AREA FJCHKPTL-LENGTH-7 GVFULOLT-DETAILS
102

IMS Fundamentals

System Service DL/I Calls (Contd..)


RESTART (XRST) Call The program that issued a symbolic CHKP call must issue a restart call (XRST). The XRST call which is issued only once, does not have to be the first call issued in the program, (though it must be issued before any CHKP call). Any call issued before the XRST call is not within the scope of the Restart. Whether a program is to be restarted or not is determined by DL/I with the help of PARM parameter specified in the EXEC statement for the program in the execution JCL, or the Checkpoint ID provided in the Restart Work Area. The XRST call should precede the CHKP call in the program and it has the same list of working storage fields that are present in CHKP call. XRST does nothing, it just leaves the specified working storage fields as they were stored in the checkpoint record and restores the fields.

IMS Fundamentals

103

System Service DL/I Calls (Contd..)


E.g. CALL CBLTDLI USING DLI-XRST L100-LOGICAL-TERMINAL-PCB FJCHKPTL-LENGTH-1 W400-REFORMAT-AREAS FJCHKPTL-LENGTH-2 W410-INDICATORS FJCHKPTL-LENGTH-3 W450-COUNTERS FJCHKPTL-LENGTH-4 W460-HOLD-AREA FJCHKPTL-LENGTH-5 GVPOINPT-PO-DETAILS FJCHKPTL-LENGTH-6 W700-CHKP-IO-AREA FJCHKPTL-LENGTH-7 GVFULOLT-DETAILS

Evaluate status-code when not space display Restart failed! when space perform xxxx-reformat-data end-evaluate.

IMS Fundamentals

104

ROLLBACK Calls - ROLL and ROLB


When issued, will backout all the database updates made by the program since the most recent Checkpoint. This will nullify the effect of any incorrect processing done by the program.

ROLL Call:
When issued, the program is Abnormally Terminated with a user abend Code of 0778. It can be issued in a Batch program as CALL CBLTDLI USING ROLL The only parameter specified in the call is the function.

IMS Fundamentals

105

Exercises
Assume there is a Hospital database with the below segments WARD WARD_NO TOT_ROOMS TOT_BEDS WARD_TYPE Unique Key

PIC X(5) PIC X(10) PIC X(10) PIC X(3)

PATIENT PAT_NO PAT_NAME PAT_ADDR PAT_PHONE

PIC X(5) PIC X(20) PIC X(50) PIC X(10)

Unique Key

IMS Fundamentals

106

Exercises (Contd..)
DOCTOR DOC_NAME DOC_ADDR DOC_PHONE DOC_SPL PIC X(20) PIC X(50) PIC X(10) PIC X(15)

Assume the following data is available in the database: WARD Segment: 101, 20, 25, F 102, 10, 22, G 103, 30, 45, M

IMS Fundamentals

107

Exercises (Contd..)
PATIENT Segment: 1001, PAUL, 101/B OAK WOOD NY, 41278906 1231, SIMPSON, 123/C JOHN STREET NJ, 4177231 1231, CATHY, 77-Y WINSTON ROAD ATLANTA, 7634211 1001, PAUL, 101/B OAK WOOD NY, 41278906 DOCTOR Segment: SAMUEL, 11-9 KENNEDY ST CAL, 890076, ORTHO RANDY, 15/A PERKIN HALL IN, 77886611, DENTIST

IMS Fundamentals

108

Exercises (Contd..)
1.
2. 3.

Write the DBD structure for the Hospital database.


Write the PSB structure. Write a REPL call to replace the PATIENT record. Use qualified SSA to search the record on PAT_NO.

1231, SIMPSON, 123/C JOHN STREET NJ, 4177231 With 1231, SIMPSON, 123/B GEORGE STREET NJ, 4177231

IMS Fundamentals

109

Exercises (Contd..)
4. Write a DLET call to delete the WARD record.

102, 10, 22, G


5. Write an ISRT call to insert the DOCTOR record.

CHRISTY, 78/L TOM ST OHIO, 892357, OPTHALMOLOGY

IMS Fundamentals

110

Case Study HR Application

IMS Fundamentals

111