100% found this document useful (3 votes)
680 views

Ims DB Material: Prepared by Ramanadham

This document provides an overview of IMS (Information Management System) database material, including: - The hierarchical structure of IMS databases and key concepts like segments, paths, parent/child relationships. - How to access IMS databases using DL/I calls and different types of access like sequential, random, and dynamic. - Descriptions of important IMS database terms like root segment, parent segment, child segment, and concatenated keys. - Background information on how IMS databases were developed and comparisons to other database types like relational databases.

Uploaded by

Rising Sun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
680 views

Ims DB Material: Prepared by Ramanadham

This document provides an overview of IMS (Information Management System) database material, including: - The hierarchical structure of IMS databases and key concepts like segments, paths, parent/child relationships. - How to access IMS databases using DL/I calls and different types of access like sequential, random, and dynamic. - Descriptions of important IMS database terms like root segment, parent segment, child segment, and concatenated keys. - Background information on how IMS databases were developed and comparisons to other database types like relational databases.

Uploaded by

Rising Sun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 55

IMS DB MATERIAL

PREPARED BY
Ramanadham
IMS DB MATERIAL
Basic Topics

Files Vs Databases
Networked, Hierarchical & Relational structure
Access Types - HSAM, HISAM, HDAM, HIDAM, VSAM
IMS DB - A Hierarchical Structure
Database Definitions - DBD
Program Specification Block, Program Control Block
DL/I Calls - Data Retrieval and Manipulation
DL/I Functions
Qualified/ Unqualified Calls, SSAs, Command Codes
DL/I Status codes
Data Sensitivity - Segment Level & Field level
Difference between MPP, BMP, DLI

Page 2 of 55
IMS DB MATERIAL
File Vs Database

Data more redundant Redundancy avoided


Duplicate data Minimize Duplicates
Data insecure Security provided
No control over data Field level sensitivity
Threat to Integrity Consistency of data
Lack of inbuilt Data Logging,
Recovery features Commits & Rollbacks
Lack of data Locks Automatic locks

IMS DB - BACKGROUND

Information Management System Database is a IBM’s product which is large system hierarchical
DBMS concept. In casual conversation, either IMS DB or IMS TM may be referred to simply as
IMS.

IBM designed IMS with Rockwell and Caterpillar in 1966 for the Apollo program. DB2 gets its
name because IMS, which was created first, was named initially as DB1. In IMS, the hierarchical
model is implemented using blocks of data known as segments. Each segment can contain
several pieces of data, which are called fields.

IMS DB or DB2, WHICH IS BETTER

There is no point of doing argue on which database is good or bad. As every database is designed
for something. I work on both the type of database. Both the databases (DB2 and IMS) are
having advantages on various aspects. We cannot tell which database is good or bad. Only the
things I wanted to highlight here is that…

 Data retrieval time in IMS is very fast as compared to DB2 system. Because of hierarchical
structure in IMS, But in case of DB2, Data is retrieved by joining the tables by establishing
the relationships among the tables.
 Most of the Mainframe project (generally old one) has the IMS as the database & Over 90
percent of the Fortune 1000 companies use IMS as their DBMS for their existing MF
Applications of choice for fulfilling the requirements of performance, reliability, and
availability.
 But now a days, everyone looking for DB2 as it is much simpler or has more advantages.
Many companies are also migrating from IMS to DB2 for new Applications.
 The main advantages of converting from IMS/DB to DB2 would be the better support for ad
hoc query, support of standard SQL (instead of non-standard DL/1), But you should do a
project plan and cost/benefit analysis before making your final decision (conversion can be
very costly).
 In terms of CPU requirements, DB2 will consume more CPU than IMS.

Page 3 of 55
IMS DB MATERIAL
DESCRIBE IMS?

It is a software product developed by IBM for creating and managing the physical storage and
retrieval of Data that is organized using the Hierarchical Data Structure.

HOW TO ACCESS IMS DATABASE? We use the Database Manager Interface Language -
DL/I.

DIFFERENT DATABASES IN MAINFRAMES?

Hierarchical Structures (e.g. IMS DB)

 One to Many Relationships


 Inverted Tree like Structure
 Best for storing parent and child type entities

Relational Structures (e.g. DB2)

 One to Many, Many to One


 Best for ease of data retrieval

Network Structures (e.g. IDMS)

 Many to Many relationships


 Complex structure using Pointers
 Best for keeping storage

HIERARCHICAL DATABASE

Hierarchical database data is organized like Tree structure. In other words, some data elements
are dependent on other. The most recognized example of hierarchical model database is an IMS
designed by IBM.

WHAT IS HIERARCHICAL STRUCTURE

 A Hierarchical structure consists of logically related data elements organized by their relative
dependence or independence upon each other.
 Each data element in the Hierarchical database is called as SEGMENT.
 In the hierarchical structure there can be up to 255 segment types in a Database record and up
to 15-segment level in any one hierarchical path.
 The structure allows repeating information using parent/child relationships: each parent can
have many Childs but each child has only one parent.
 In a hierarchical structured database access to data starts at the top of the hierarchy and
moves downward.

Page 4 of 55
IMS DB MATERIAL
This is the data base we are using in our application………

This is the data base we are using in our entire programs….

Page 5 of 55
IMS DB MATERIAL

This is the first customer information…..

This is Second customer information…..

Page 6 of 55
IMS DB MATERIAL

This is Third customer information…..

SEGMENT/SEGMENT TYPE

A segment contains group of logically related field items. Each Segment in the database is called
as Segment type. If we are talking about Segment type that means we are talking about all
occurrences in a segment.

Max number of segments allowed for a single database is 255.


Max number of fields per segment is 255.
Max number of fields per database is 1000.

Ex: we have taken of INVOICE database in all our examples, there are 4 segment types i.e.
INVCSEGM, CUSTSEGM, ITEMSEGM and PRICESEGM.

Page 7 of 55
IMS DB MATERIAL
SEGMENT OCCURRENCE

A segment occurrence is the single occurrence of that particular segment type. In the
INVOCEDBD database there is 3 customers data information, which is stored in the database.

Ex: We have 3 occurrences for the Root segment. If we talk about the ITEMSEGM occurrences,
if we pick up 1st customer record, he has purchased 2 items that means for Customer 1 there are 2
item occurrences.

How many segment occurrences can a segment has: A (no limit)

DATABASE RECORD

A database record consists of a single occurrence of the ROOT segment and all of its dependent
segments.

In the INVOCEDBD database, we have 3 Customer’s data, i.e. a single database record consist
of single occurrence of the INVCSEGM segment and all of the segment occurrences below it.

Ex: Cust1-database record1


Cust2-database record2
Cust3-database record3

ROOT SEGMENT

A root segment is the one, which is located at the top most in the hierarchical structured
database. The root segment of the database is located at first level. A root segment does not have
any parent segment.

Note: A root segment is also a Parent segment But Parent segment is not root segment always.

Ex: INVCSEGM

PARENT SEGMENT:

A segment that has one or more child segments directly below it in the Hierarchy is called a
PARENT segment.
(OR)
Each segment that has one or more dependent segments is a parent segment.

Ex: INVCSEGM is parent of CUSTSEGM


CUSTSEGM is parent of ITEMSEGM
ITEMSEGM is parent of PRICSEGM

Page 8 of 55
IMS DB MATERIAL
CHILD SEGMENT

Each dependent segment in the hierarchy is a child segment. A child Segment is also called as
Dependent segment.

Ex: CUSTSEGM, ITEMSEGM & PRICSEGM are the child segments.

TWIN SEGMENT

The term Twins applies only to segment occurrences. Two or more segment Occurrences of the
same Segment type, if they are under same parent Occurrence then they are called as twin
segment.

PATH

A path is the series of segments that leads from the top of a data base record (Root segment
occurrence) down to any specific segment occurrence. A path in the Hierarchy need not to be
complete to the lowest level. In other words, you can’t skip intermediate levels.

TYPES OF ACCESSING THE DATA IN IMS

 SEQUENTIAL.
 RANDOM.
 DYNAMIC.

SEQUENTIAL

Sequential processing is chosen when we want to retrieve all occurrences of the Database or the
entire occurrences with in a segment type. (Multiple records with all the field values for a
database record)

Ex: If the database has 4 segments INVCSEGM, CUSTSEGM, ITEMSEGM & PRICSEGM
with total of 3 records in the database. Sequential access will retrieve all the 3 Records for a
database with all field items.

RANDOM

Random processing is chosen when we want to retrieve a particular occurrence with


In a database.

For Random processing we pass key values to retrieve the record (a particular occurrence) with
all field items.

Ex 1: To retrieve Root segment occurrence we pass key values for Root segment.

Page 9 of 55
IMS DB MATERIAL
Ex 2: To retrieve Customer segment occurrence we pass key values for Root segment &
customer segment.
Ex 3: To retrieve Item segment occurrence we pass key values for Root segment & customer
segment & Item segment.
Ex 4: To retrieve Price segment occurrence we pass key values for Root segment & customer
segment & Item segment & Price segment.

DYNAMIC

Dynamic processing is chosen when we want to retrieve multiple child occurrences


(Sequential) for a for a particular parent (random) occurrence with in a database.

Ex: Random + Sequential = Dynamic

NOTE: Both for Random & Dynamic processing we pass key values to retrieve each
Segment (root/Childs) data.

CONCATENATED KEY

To access any segment occurrence at the lower level we pass key Values to all the segments
starting from the root segment to the current segment (Lower level segment). The combination of
all the key values which we passed to the segments For Random processing is called
concatenated key.

DL/I

DL/I mean Data language Interface. DL/I is a program module, which is used to connect the IMS
application program to the databases

DL/I allow the Application program to Retrieve/Update/Delete/Insert data elements from the
segments sequentially or randomly.

WHAT ARE THE CONTROL BLOCKS IN IMS DATABASE

DL/I use a set of control blocks to define a database structure. It is a complete responsibility of a
DBA to generate both DBD & PSB.

1. DBD (Database definition) 2. PSB (Program specification Block)


PCB (Program communication Block)

DBD : DBD describes the Physical structure of a hierarchical database.


PSB : PSB describes the access allowed by an Application program on single/multiple
Databases.
PCB : PCB describes the access allowed by a program for a single database.

Page 10 of 55
IMS DB MATERIAL
ACCESS TYPES

HIDAM (Hierarchical Indexed Direct Access Method):

HIDAM databases are typically used when you need both random and sequential access to
database records and random access to paths of segment in a database record. HIDAM index
database searches for a root segment’s address.

Other data access types we have are HSAM, HISAM, SHSAM, SHISAM, GSAM, HDAM,
PHDAM, PHIDAM, MSDB, DEDB and INDEX.

DBD STRUCTURE

The Process of creating a DBD is called as DBDGEN. To generate a DBD, the database
administrator codes a job stream that contains a set of assembler language or Macro instructions
that define the structure of the database.

It is a member in PDS EX: CY11791.SOURCE.DBDLIB (INVOCDBD)

PRINT NOGEN
DBD NAME = INVOCDBD, ACCESS = HIDAM
DATASET DD1 = INVC, DEVICE = 3380, SIZE = 4096
*INVCSEGEMENT DECLERATION
SEGM NAME = INVCSEGM, PARENT = 0, BYTES = 14
FIELD NAME = (INVCNO, SEQ, U), START = 1, BYTES = 4, TYPE = P
FIELD NAME = INVCDATE, START = 5, BYTES = 10, TYPE = C
*CUSTSEGMENT DECLERATION
SEGM NAME = CUSTSEGM, PARENT = INVCSEGM, BYTES = 10
FIELD NAME = FSTNAME, START = 1, BYTES = 5, TYPE = C
FIELD NAME = LSTNAME, START = 6, BYTES = 5, TYPE = C
* ITEMSEGMENT DECLERATION
SEGM NAME = ITEMSEGM, PARENT = CUSTSEGM, BYTES = 10
FIELD NAME = ITEMNO, START = 1, BYTES = 5, TYPE = C
FIELD NAME = ITEMNAME, START = 6, BYTES = 5, TYPE = C
* PRICESEGMENT DECLERATION
SEGM NAME = PRICSEGM, PARENT = ITEMSEGM, BYTES = 8
FIELD NAME = ITEMQTY, START = 1, BYTES = 4, TYPE = P
FIELD NAME = TOTPRICE, START = 5, BYTES = 4, TYPE = P
DBDGEN
FINISH
END

DBD Defines

 Segment names a program may access

Page 11 of 55
IMS DB MATERIAL
 Type of Access method for the Database (ACCESS = HIDAM).
 Various fields’ formats within the accessed segments.
 Data type of each field items, Start and End position of the field.
 Names and formats of the fields used for search.
 Hierarchical relationships of the accessed segments.

DBD : Database Description, describes physical Database


DBDGEN : DBDGEN Utility, Describes the physical structure of the Database and creates
DBD
DBD : Names the database and identifies the access method
DBD Name = INVOCDBD, ACCESS= HIDAM
DATASET : Specifies DD Name used in the JCL and other parameters
DATASET DD1=INVC, DEVICE=3380, SIZE= (4096)
SEGM : Names the segment. Identifies the parent and establishes the length
SEGM NAME =INVCSEGM, PARENT=0, BYTES=14
FIELD : Defines fields. And identifies search &key fields by SEQ parameter
FIELD NAME = (INVCNO, SEQ, U), START = 1, BYTES = 4, TYPE = P
DBDGEN : Indicates the end of the DBDGEN process

SEQUENCED FIELD

 A key or sequenced field is a field with the segment that DL/I use to maintain Segments in
the Ascending Sequence.
 Only a single field within each segment may be designated as a key or sequence field.
 Key field in a segment is OPTIONAL.
 Key field may be UNIQUE or NON-UNIQUE.
 A root segment is required to have a UNIQUE key field. Unique key field is defined as U &
Non Unique field is defined as M in the DBD.

PSB STRUCTURE

The Process of creating a PSB is called as PSBGEN. The DBA defines the logical data structure
by creating a Control Block called a PSB.

Program Specification Block, describes Logical structure of the Database that a program will
use. It contains one or more PCB’s (Program Communication Block). PCB describes one
Database.

 PSBGEN control statements are Assembler Language Macros supplied by IBM and
submitted via JCL to produce an OBJECT module, which is stored in PSBGEN.
 Although each database has a single physical structure that’s defined by a DBD, the
application program that processes it can have different views of it.
 PSB describes the access allowed by an Application program on single/Multiple databases.
 A PSB consists of one or more control blocks called Program Communication Block’s or
PCB’s.

Page 12 of 55
IMS DB MATERIAL
 Each PCB describes the access allowed by a program for a single database.

PRINT NOGEN
PCB TYPE = DB, NAME = INVCDBD, KEYLEN = (TOT SEQ FIELD LEN), PROCOPT=G
SENSEG NAME = INVCSEGM, PARENT =0
SENFIELD NAME = INVCNO, BYTES = 4
SENFIELD NAME = INVCDATE, BYTES = 10
SENSEG NAME = CUSTSEGM, PARENT = INVCSEGM
SENFIELD NAME = FNAME, BYTES = 5
SENFIELD NAME = LNAME, BYTES = 5
SENSEG NAME = ITEMSEGM, PARENT = CUSTSEGM
SENFIELD NAME = ITEMNO, BYTES = 5
SENFIELD NAME = ITEMNAME, BYTES = 5
SENSEG NAME = PRICSEGM, PARENT = ITEMSEGM
SENFIELD NAME = TOTQTY, BYTES = 4
SENFIELD NAME = TOTPRIC, BYTES = 4
PSBGEN NAME = INVCPSB, TYPE = COBOL
FINISH
END

PSBGEN : Produces a load module stored in the PSBLIB library and creates PSB Major
PCB : Describes type (DB or DC), name of the DBD, Key length (length of the longest
Macros Used concatenated key the program can process) and processing Option
PCB TYPE=DB, DBDNAME=INVOCDBD, KEYLEN=4, PROCOPT=LS
SENSEG : Define the name of the segments in the Database your program needs access to
SENSEG NAME=CUSTSEG, PARENT=INVCSEGM
SENFIELD: Subordinate to the SENSEG macro, only fields that are defined by the SENFIELD
macro can be accessed from the I/O Area.
ACB (Access Control Block)
ACB are generated by IMS as expansion of information contained in PSB in order to speed up
the access to applicable DBD’s. It is ACB rather than PSB that is IMS uses when application
program runs .In batch program ACB can either be created ahead of time, or at extraction time,
depending on the JCL used to invoke the program.

 Access Control Blocks for an application program combines the Database Descriptor and
the Program Specification Block into an executable form.
 ACBGEN is known as Access Control Blocks Generator. It is used to generate ACBs.
 For online programs, we need to pre-build ACBs. Hence the ACBGEN utility is executed
before executing the application program.
 For batch programs, ACBs can be generated at execution time too.

Page 13 of 55
IMS DB MATERIAL
USE OF PROCOPT OPTION IN THE PCB

 The PROCOPT operand is an Optional in the PCB Statement. It stands for the processing
options and identifies the Processing types that may be performed on each segment’s by the
application program.
 PROCOPT option is used for controlling the authority & the processing action allowed
against the data a given user is permitted.
 PORCOPT option can be coded either in database level (PCB) or at the segment level.
Segment Level will override at the database level.

DIFFERENT PROCOPT OPTIONS

PROCOPT USAGE
OPTION
G Read
I Insert access on the database
R Replace access on the database
D Delete access on the database
A All (all options I, R, D, G)
K Key sensitive only
P Path call
L Load (to create initial version of the database)
LS Load sequential

Restriction of Segment is allowed by coding SENSEG & Restriction of Field is allowed


by coding SENFIELD in a PCB.

SEGMENT LEVEL SENSITIVITY

The access is restricted to certain segments and some segments in the Database given access with
PROCOPT option. The segments, which are allowed for access either for
(read/insert/delete/update) is called segment level sensitivity. Restriction of Segment is allowed
by coding SENSEG with PROCOPT statement.

FIELD LEVEL SENSITIVITY

The access is restricted to certain fields and some fields given access within a segment with
PROCOPT option. The fields, which are allowed for access either for (read/insert/delete/update)
is called Field level sensitivity can be accessed. Restriction of Field is allowed by coding
SENFIELD in a PCB.

PCB MASK

Define in linkage Section and establishes correspondence between linkage Section PCB-mask
and PSB’s within your program.

Page 14 of 55
IMS DB MATERIAL
 The second parameter, which is coded in any DL/I call statement, is PCB-MASK.
 The PCB Mask is the area common to the (COBOL) Application program and DL/I. It is
used to pass information about each DLI call back to the program.
 A PCB-MASK referred in a call statement is declared in the Linkage section of the COBOL
DL/I application program.
 You need to code one PCB Mask with unique 01 level name for each Database being
accessed by the program,
 PCB-mask is coded in the linkage section and the rest of all (DL/I function, I/O area & SSA)
shall always coded in the working storage 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

SAMPLE PCB-MASK LAYOUT

VARIABLE DESCRIPTION
01 INVC-PCB-MASK.
05 INVC-DBD-NAME PIC X(8). Name of the Database being processed
05 INVC-SEG-LEVEL PIC XX. Specifies current segment level in the DB
05 INVC-STATUS-CODE PIC XX. Status code of the last DL/I call statement
05INVC-PROC-OPT PIC X(4). Type of processing authorized on database
05 FILLER PIC X(8).
05 INVC-SEG-NAME PIC X(8). Stores name of the segment just proceeded
05 INVC-KEY-LENGTH PIC S9(5). Length of the concatenated key retrieved
05 INVC-NUM-SENSEGS PIC S9(5). Count of segments accessed
05 INVC-KEY-VALUE PIC X(20). Key value of the concatenated key retrieved

 DL/I update the PCB mask with the execution results after every DL/I call.
 The most common fields, which can be validated in a PCB mask, are status-code, segment
name.
 DBD-NAME field tells what database we are accessing.
 SEGMENT-level field tells at which level the control is after the DLI call execution.
 STATUS-CODE field tells about the call status whether the call is success (spaces) or fail (2
digit non zero return code).
 PROC-OPT field tells the processing which is performed on the current segment.
 SEGMENT-name field tells that after the call statement execution in which segment the
control is in.
 SEGMENT-KEY-LENGTH field tells the total key length till the current segment (count of
total sequence key lengths till the current segment).
 NOF-SENSEG field tells the total number of segments accessed including the current
segment after execution of the call statement.
 KEY-VALUE field tells total key value till the current segment (value of total sequence key
lengths till the current segment).If no. of segments increases, then key value also increases
 INVC-STATUS-CODE and INVC-SEGM-NAME fields are validation fields.

Page 15 of 55
IMS DB MATERIAL
01 IOPCB-MASK.(online)
05 IOPCB-LTERM PIC X(8).
05 IOPCB-RESERVED PIC X(2).
05 IOPCB-STAT PIC X(2).
05 IOPCB-CURR-DATE PIC S9(7) COMP-3.
05 IOPCB-CURR-TIME PIC S9(7) COMP-3.
05 IOPCB-MSG-SEQ-NO PIC 9(9) COMP.
05 IOPCB-MOD-NAME PIC X(8).
05 IOPCB-USERID PIC X(8).

REQUIREMENTS FOR BUILDING AN IMS PROGRAM

Three statements that is always mandatory in building an IMS program.

ENTRY STATEMENT
DLI CALL STATEMENT
GOBACK STATEMENT

ENTRY STATEMENT

Any IMS program the first executable statement is Entry statement. Any IMS program is under
the control of the DL/I batch initialization module. DL /I first load the appropriate control block

Page 16 of 55
IMS DB MATERIAL
and then loads your application program and passes control to it. In short your application
program will always act as a sub program under DL/I.

ENTRY ‘DLITCBL’ USING PCB-MASK1


PCB-MASK2.

 The first statement in your application program you see in an IMS DB program is Entry
statement, and is coded soon after the procedure division.
 PCB masks for the PCB’S passed to the program by DL/I is coded in the linkage section
 The number of PCB masks using in an ENTRY statement says the number of databases using
in the application program.
 The PCB masks should be coded in the same sequence order in an ENTRY statement, as they
exist in the PSB. They can be coded in any order in a linkage section.
 PCB mask says what database we are using in our application program; Status of the Call
statement, segment level, segment name, and number of segments accessed, key Length. Etc.

GOBACK STATEMENT

Any IMS DB program should always end with the GOBACK Statement to release all the
resources used in the program. As the control comes first from DL/I database, coding GOBACK
statement allows the control to return to DL/I and then to operating system, GOBACK is the last
statement in IMS program.

If GOBACK is not coded (STOPRUN, EXITPROGRAM) then control directly reaches to


operating system i.e. all the resources (databases) won’t get released and they will be under lock
state.

DL/I CALL STATEMENT

Here in an IMS program to access the data from IMS database we code DL/I call statement.

Ex: CALL ‘CBLTDLI’ USING DL/I FUNCTION =read, insert, update, delete
PCB-MASK =Source Database name
I/O AREA =Storage area

CALL ‘CBLTDLI’ USING DL/I FUNCTION =read, insert, update, delete


PCB-MASK =Source Database name
I/O AREA =Storage area
SSA =key values passage

In normal file processing to access the data from a file we have I/O operations on a file (input,
output, extend, I-o) for performing the functions (read, update, insert, delete).

Ex:

Page 17 of 55
IMS DB MATERIAL
READ INFILE INTO WS-FILEREC

Read function Source file Storage area

WRITE INFILE INTO WS-FILEREC

Write function Source file Storage area

Note : File status has the status of the I/O operations performed on the file.

DL/I FUNCTION

 The first parameter, which is coded in any DL/I call statement, is DL/I function.
 DL/I function coded in the DL/I call statement tells the purpose of accessing the database,
whether to read/update/delete/Insert.
 A DL/I function code is a 4-character field, which is declared in the working storage section
and is referred by using the information passed through CALL parameter.
 Function codes used mostly are: GU, GN, GNP (Get Next within Parent), GHU, GHN,
GHNP, ISRT, DLET and REPL.
 Usage of each function is referred in the table given below. All the hold calls below are used
when we have an intent to change the database

DL/I FUNCTION FUNCTION USAGE


GN Sequential read
GU Random read
GNP Dynamical read
GHN Hold sequentially for changing all database records
GHU Hold randomly for changing of particular record
GHNP Hold sequentially for changing for a parentage
ISRT Inserting data
REPL Update the data
DLET Delete the data
CHKP Issue checkpoint for recovery (commit point)
XRST Issue of Restart from the check point

I/O AREA

 The third parameter, which is coded in any DL/I call statement, is I/O area.
 I/O area in a call statement tells the place where the retrieved data needs to be stored in a
retrieval call & at the time of updating or insertion will update the database from the I/O area,
so for updating/insertion/deletion of database we need to build the I/O area first before the
call statement.

Page 18 of 55
IMS DB MATERIAL
 I/O Area holds the standard Record Description, which holds the database segments for
manipulation, used by DL/I to pass segment data to your programs.
 It can be used by programs to add or replace data. In some cases multiple segments in a
parent child relationship can be retrieved or inserted together, in which case the I/O area
should be large enough to hold the largest concatenation of these segments for path calls.
 I/O area referred in a call statement is declared in the working storage section.

RULES FOR SEQUENTIAL PROCESSING

 Left-Right (left most unprocessed first)


 Top-Bottom
 Bottom-Up

PROG 1……Sample program for retrieving the data from the database and write it into a
file that file should have all the customers’ details.

ID DIVISION.
PROGRAM.ID. INVCPGM.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT INVCFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD INVCFILE.
01 INVCREC.
05 INVENO PIC S9(7) COMP-3.
05 INVCDATE PIC X(10).
05 FSTNAME PIC X(5).
05 LSTNAME PIC X(5).
05 ITEMNO PIC X(5).
05 ITEMNAME PIC X(5).
05 ITEMQTY PIC S9(7) COMP-3.
05 TOTPRIC PIC S9(7) COMP-3.
WORKING-STORAGE SECTION.
01 WS-IO-AREA PIC X(14).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GN PIC X(4) VALUE ‘GN ‘.
01 WS-INVC-REC
05 WS-INVCDATA
10 WS-INVCNO PIC S9(7) COMP-3.
10 WS-INVCDATE PIC X(10).
05 WS-CUSTDATA
10 WS-FNAME PIC X(5).
10 WS-LNAME PIC X(5.

Page 19 of 55
IMS DB MATERIAL
05 WS-ITEMDATA
10 WS-ITEMNO PIC X(5).
10 WS-ITEMNAME PIC X(5).
05 WS-PRICDATA
10 WS-ITEMQTY PIC S9(7) COMP-3.
10 WS-TOTPRICE PIC S9(7) COMP-3.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 INVC-DBD-NAME PIC X(8) VALUE ‘INVOCDBD’.
05 INVC-SEGM-LEVEL PIC X(2).
05 INVC-STATUS-CODE PIC X(2).
05 INVE-PROC-OPT PIC X(4).
05 FILLER PIC X(8).
05 INVC-SEGM-NAME PIC X(8).
05 INVC-KEY-LENGTH PIC S9(7) COMP-3.
05 INVC-NOF-SENSEG PIC S9(7) COMP-3
05 INVC-KEY-VALUE PIC X(18).
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA UNTIL EODB = ‘Y’.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN OUTPUT INVCFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GN
INVC-PCB-MASK.
WS-IO-AREA.
IF INVC-STATUS-CODE = SPACES
PERFORM 2100-VALIDATE-SEGMENT-PARA
ELSE
IF INVC-STATUS-CODE = ‘GB’
MOVE ‘Y’ TO EODB
END-IF.
2100-VALIDATE-SEGMENT-PARA
EVALUTATE INVC-SEGM-NAME
WHEN INVCSEGM
INITIALIZE WS-INVCDATA
MOVE WS-IO-AREA TO WS-INVCDATA
WHEN CUSTSEGM
INITIALIZE WS-CUSTDATA
MOVE WS-IO-AREA TO WS-CUSTDATA
WHEN ITEMSEGM
INITIALIZE WS-ITEMDATA

Page 20 of 55
IMS DB MATERIAL
MOVE WS-IO-AREA TO WS-ITEMDATA
WHEN PRICSEGM
INITIALIZE WS-PRICDATA
MOVE WS-IO-AREA TO WS-PRICDATA
WRITE WS-INVC-REC FROM WS-INVC-DATA
END-EVALUATE.
3000-CLOSE-PARA
CLOSE INVCFILE.

OUTPUT: 1001 10/10/2008 MANI KANTA IT001 PEN 10 500.00


IT002 BOOK 20 600.00
1002 10/10/2008 TULSI RAMU IT002 PEN 15 750.00
1003 10/10/2008 LALIT BABU IT001 PEN 20 1000.00
IT002 BOOK 15 450.00
IT003 FILE 20 800.00

SSA (SEGMENT SEARCH ARGUMENT)

 The fourth parameter, which is coded in any DL/I call statement, is SSA.
 The SSA in a DL/I call statement is optional. SSA is coded in a working storage section
of the DL/I program.
 We can code only 1 SSA at each level in the HIERARCHY. Maximum levels in a
hierarchy are 15 hence we can code up to 15 SSA in a DL/I call statement.
 The concept of SSA comes and needs to be coded in a DL/I call statement when we want
to retrieve a particular (specific) data from the from a IMS Database.

Ex: Specific data means


1. Retrieve only single child occurrence data for a single customer.
2. Retrieve multiple child occurrences for a single customer.
3. Retrieve only child segment data for all the customers.

The number of SSA’s need to be coded is based on the level of the data we want to retrieve.
SSA contains information of the Segment name to be retrieved, or segment name and segment
key with a specific value or name and search field with a value.

If we want to retrieve the data at level 5, then we need to Code 5 SSA’s in our DL/I call
statement for a single occurrence.

SSA TYPES

1. QUALIFIED SSA 2. UNQUALIFIED SSA

QUALIFIED SSA

Page 21 of 55
IMS DB MATERIAL
It is used when want to retrieve a particular child (specific) occurrence of a specific segment type
in an IMS database.

UN QUALIFIED SSA
It is used when want to retrieve all occurrence in a specific segment in an IMS database.

TYPES OF CALLS

QUALIFIED CALL: If any SSA’s exist in a call statement then it is called as qualified call.
UN QUALIFIED CALL: If no SSA’s exist in a call statement then it is called as UN Qualified
call.

USAGE OF UN QUALIFIED SSA

 Searches for a specific Segment type i.e., all the occurrences in particular segment.
 Un Qualified SSA is recognized by the 9th position Spaces as argument.
 Once the call is issued and it recognizes the segment name and directly reaches to the
segment & access the data from the segment sequentially.
 We can only code 1 UN Qualified SSA in one DL/I call.

Ex:
01 UNQUL-INVC-SSA PIC X (9) VALUE ‘INVCSEGM ’

PROG 2…..Retrieve INVC Details of all customers and write it into file by using
UNQUALIFIED SSA.

ID DIVISION.
PROGRAM.ID. INVCPGM.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT INVCFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD INVCFILE.
01 INVCREC PIC X(14).
WORKING-STORAGE SECTION.
01 WS-IO-AREA PIC X(14).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GN PIC X(4) VALUE ‘GN ‘.
01 WS-INVC-REC
05 WS-INVCNO PIC S9(7) COMP-3.
05 WS-INVCDATE PIC X(10).
01 UNQUL-INVC-SSA PIC X(9) VALUE ‘INVCSEGM ‘.

Page 22 of 55
IMS DB MATERIAL
LINKAGE SECTION.
01 INVC-PCB-MASK
05 INVC-DBD-NAME PIC X(8) VALUE ‘INVOCDBD’.
05 INVC-SEGM-LEVEL PIC X(2).
05 INVC-STATUS-CODE PIC X(2).
05 INVE-PROC-OPT PIC X(4).
05 FILLER PIC X(8).
05 INVC-SEGM-NAME PIC X(8).
05 INVC-KEY-LENGTH PIC S9(7) COMP-3.
05 INVC-NOF-SENSEG PIC S9(7) COMP-3
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA UNTIL EODB = ‘Y’.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN OUTPUT INVCFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GN
INVC-PCB-MASK
WS-IO-AREA
UNQUL-INVC-SSA.

IF INVC-STATUS-CODE = SPACES
WRITE INVEREC FROM WS-INVC-DATA
ELSE
IF INVC-STATUS-CODE = ‘GB’
MOVE ‘Y’ TO EODB
END-IF.
3000-CLOSE-PARA.
CLOSE INVCFILE.

OUTPUT: 1001 10/10/2008


1002 10/10/2008
1003 10/10/2008

USAGE OF QUALIFIED SSA

 Searches for a specific occurrence of a specific segment.


 It specifies the segment name and the Key or Search field with a field value along with
relational operator to retrieve the necessary Segment type occurrences.

Page 23 of 55
IMS DB MATERIAL
 It allows access to the database segment directly.
 Qualified SSA is recognized by the 9th position as left parenthesis “ ( “as argument in the
SSA declaration in the working storage section.
 First 8 bytes are for the SEGMENT name, 9th position is left parenthesis, 10th to 17th bytes is
for SEGMENT KEY FIELD name, 18th & 19th position is for the relational operation & 20th
position on will be the value against the Key field & the last byte in the SSA for closing with
right parenthesis “ ) ”.
Ex: 01 QUAL-INVC-SSA.
05 FILLER PIC X (9) VALUE ‘INVCSEGM (‘.
05 FILLER PIC X (10)VALUE ‘INVOCNO = ‘.
05 WS-INVCNO PIC S9 (7) COMP-3 VALUE 1003.
05 FILLER PIC X (1) VALUE ‘)’.

PROG 3…..Write a program to retrieve the price details of customer who’s having
INVCNO 1003, FSTNAME ‘LALIT’, ITEMNO ‘IT003’ AND ITEMQTY IS 20 by
using QUALIFIED SSA.

ID DIVISION.
PROGRAM.ID. INVCPGM.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT PRICFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD PRICFILE.
01 PRICREC. PIC X(8)
WORKING-STORAGE SECTION.
01 DLI-GU PIC X(4) VALUE ‘GU ‘.
01 PRIC-DTLS PIC X(8).
01 PRIC-IO-AREA PIC X(8).
01 QUAL-INVC-SSA
05 FILLER PIC X(9) VALUE ‘INVCSEGM(‘
05 FILLER PIC X(10) VALUE ‘INVC NO =’
05 WS-INVCNO PIC S9(7) COMP-3 VALUE 1003.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-CUST-SSA
05 FILLER PIC X(9) VALUE ‘CUSTSEGM(‘
05 FILLER PIC X(10) VALUE ‘FNAME =’
05 WS-FNAME PIC S9(7) COMP-3 VALUE ‘LALIT’
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-ITEM-SSA
05 FILLER PIC X(9) VALUE ‘ITEMSEGM(‘
05 FILLER PIC X(10) VALUE ‘ITEM NO =’

Page 24 of 55
IMS DB MATERIAL
05 WS-ITEMNO PIC S9(7) COMP-3 VALUE ‘IT003’.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-PRIC-SSA
05 FILLER PIC X(9) VALUE ‘PRICSEGM(‘
05 FILLER PIC X(10) VALUE ‘ITEMQTY =’
05 WS-ITEMQTY PIC S9(7) COMP-3 VALUE 20.
05 FILLER PIC X(1) VALUE ‘)’.
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA.
PERFORM 3000-CLOSE-PARA.
GOBACK.

1000-OPEN-PARA.
OPEN OUTPUT INVCFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GU
INVC-PCB-MASK
PRIC-IO-AREA
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA
QUAL-PRIC-SSA.

IF INVC-STATUS-CODE = SPACES
MOVE INVC-IO-AREA TO PRIC-DTLS
WRITE PRICREC FROM PRIC-DTLS
ELSE
IF INVC-STATUS-CODE = ‘GE’
DISPLAY ‘INVALID KEY’
END-IF.

3000-CLOSE-PARA.
CLOSE PRICFILE.

OUTPUT: 20 800

Always the IO-AREA contains the data of last SSA coded in the CALL statement. In case I want
to retrieve the all the data for particular database record i.e., INVCNO, INVCDATE, FNAME,
LNAME, ITEMNO, ITEMNAME, ITEMQTY AND TOTPRIC we should code 4 SSA’s and 4
CALL statements then only we can retrieve the entire database record for particular customer.

Page 25 of 55
IMS DB MATERIAL
PROG 4………Write a program to retrieve the ALL details (INVCNO, INVCDATE,
FNAME, LNAME, ITEMNO, ITEMNAME, ITEMQTY AND TOTPRIC) of customer
who’s having INVCNO 1003, FSTNAME ‘LALIT’, ITEMNO ‘IT003’ AND ITEMQTY
IS 20 by using QUALIFIED SSA.

ID DIVISION.
PROGRAM.ID. INVCPGM.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT INVCFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD INVCFILE.
01 INVCREC PIC X(42).
WORKING-STORAGE SECTION.
01 INVC-IO-AREA PIC X(14).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GU PIC X(4) VALUE ‘GU ‘.
01 WS-INVC-DATA
05 INVC-DATA
10 WS-INVCNO PIC S9(7) COMP-3.
10 WS-INVCDATE PIC X(10).
05 CUST-DATA
10 WS-FNAME PIC X(5).
10 WS-LNAME PIC X(5.
05 ITEM-DATA
10 WS-ITEMNO PIC X(5).
10 WS-ITEMNAME PIC X(5).
05 PRIC-DATA
10 WS-ITEMQTY PIC S9(7) COMP-3.
10 WS-TOTPRICE PIC S9(7) COMP-3.
01 QUAL-INVC-SSA.
05 FILLER PIC X(9) VALUE ‘INVCSEGM(‘
05 FILLER PIC X(10) VALUE ‘INVC NO =’
05 WS-INVCNO PIC S9(7) COMP-3 VALUE 1003.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-CUST-SSA.
05 FILLER PIC X(9) VALUE ‘CUSTSEGM(‘
05 FILLER PIC X(10) VALUE ‘FNAME =’
05 WS-FNAME PIC S9(7) COMP-3 VALUE ‘LALIT’
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-ITEM-SSA.
05 FILLER PIC X(9) VALUE ‘ITEMSEGM(‘

Page 26 of 55
IMS DB MATERIAL
05 FILLER PIC X(10) VALUE ‘ITEM NO =’
05 WS-ITEMNO PIC S9(7) COMP-3 VALUE ‘IT003’.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-PRIC-SSA.
05 FILLER PIC X(9) VALUE ‘PRICSEGM(‘
05 FILLER PIC X(10) VALUE ‘ITEMQTY =’
05 WS-ITEMQTY PIC S9(7) COMP-3 VALUE 20.
05 FILLER PIC X(1) VALUE ‘)’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 INVC-DBD-NAME PIC X(8) VALUE ‘INVOCDBD’.
05 INVC-SEGM-LEVEL PIC X(2).
05 INVC-STATUS-CODE PIC X(2).
05 INVE-PROC-OPT PIC X(4).
05 FILLER PIC X(8).
05 INVC-SEGM-NAME PIC X(8).
05 INVC-KEY-LENGTH PIC S9(7) COMP-3.
05 INVC-NOF-SENSEG PIC S9(7) COMP-3
05 INVC-KEY-VALUE PIC X(18).
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA.
IF EODB = ‘Y’
DISPLAY ‘NOT A VALID OCCURRENCE’
END-IF.

PERFORM 3000-CLOSE-PARA.
GOBACK.

1000-OPEN-PARA.
OPEN OUTPUT INVCFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GU
INVC-PCB-MASK.
INVC-IO-AREA.
QUAL-INVC-SSA
IF INVC-STATUS-CODE = SPACES
MOVE INVC-IO-AREA TO INVC-DATA
PERFORM 2100-VALIDATE-CUST-PARA
ELSE
IF INVC-STATUS-CODE = ‘GE’
MOVE ‘Y’ TO EODB
END-IF.
2100-VALIDATE-CUST-PARA

Page 27 of 55
IMS DB MATERIAL
INTITIALIZE INVE-IO-AREA
CALL ‘CBLTDLI’ USING DLI-GU
INVC-PCB-MASK.
INVC-IO-AREA.
QUAL-INVC-SSA
QUAL-CUST-SSA
IF INVC-STATUS-CODE = SPACES
MOVE INVC-IO-AREA TO CUST-DATA
PERFORM 2200-VALIDATE-ITEM-PARA
ELSE
IF INVC-STATUS-CODE = ‘GE’
MOVE ‘Y’ TO EODB
END-IF.
2200-VALIDATE-ITEM-PARA
INTITIALIZE INVE-IO-AREA
CALL ‘CBLTDLI’ USING DLI-GU
INVC-PCB-MASK.
INVC-IO-AREA.
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA
IF INVC-STATUS-CODE = SPACES
MOVE INVC-IO-AREA TO ITEM-DATA
PERFORM 2300-VALIDATE-PRIC-PARA

ELSE
IF INVC-STATUS-CODE = ‘GE’
MOVE ‘Y’ TO EODB
END-IF.
2300-VALIDATE-PRIC-PARA
INTITIALIZE INVE-IO-AREA
CALL ‘CBLTDLI’ USING DLI-GU
INVC-PCB-MASK.
INVC-IO-AREA.
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA
QUAL-PRIC-SSA
IF INVC-STATUS-CODE = SPACES
MOVE INVC-IO-AREA TO PRIC-DATA
WRITE INVCREC FROM WS-INVC-DATA
ELSE
IF INVC-STATUS-CODE = ‘GE’
MOVE ‘Y’ TO EODB
END-IF.

Page 28 of 55
IMS DB MATERIAL
3000-CLOSE-PARA
CLOSE INVCFILE.

OUTPUT: 1003 10/10/2008 LALIT BABU IT003 FILE 20 800.00

DYNAMIC ACCESS

 When we want to retrieve multiple occurrences for a particular parent is called Dynamic
Access i.e., select the particular occurrence Random after that access Sequentially.
Dynamic Access = Random + Sequential
 For Dynamic Access we use the DLI function as GNP.

RULES FOR CODING “GNP” CALL

 We should set a parentage by coding GU / GN call and should be success.


 Perform GNP call after parentage is set.
 GNP call should contain only one SSA (Unqualified SSA).
 GNP call can be coded with more than 1 SSA only to override the default parentage which is
already been set.

Ex: CALL ‘CBLTDLI’ USING DLI-GU


INVC-PCB-MASK
I-O- AREA
QUAL-INVC-SSA.

CALL ‘CBLTDLI’ USING DLI-GNP


INVC-PCB-MASK
I-O- AREA
UNQUL-ITEM-SSA.

It retrieves the particular customer INVC details and all the ITEM details for that customer

PROG 5…. Write a program that retrieves all the ITEM details of customer1 also INVC
details and write the result into a file.

ID DIVISION.
PROGRAM.ID. INVCPGM.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT INVCFILE ASSIGN TO UT11.

Page 29 of 55
IMS DB MATERIAL
DATA DIVISION.
FILE SECTION.
FD INVCFILE.
01 INVCREC PIC X(24).
WORKING-STORAGE SECTION.
01 INVC-IO-AREA PIC X(14).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GU PIC X(4) VALUE ‘GU ‘.
01 DLI-GNP PIC X(4) VALUE ‘GNP ‘.
01 WS-INVC-DATA
05 INVC-DATA
10 WS-INVCNO PIC S9(7) COMP-3.
10 WS-INVCDATE PIC X(10).
05 ITEM-DATA
10 WS-ITEMNO PIC X(5).
10 WS-ITEMNAME PIC X(5).
01 QUAL-INVC-SSA.
05 FILLER PIC X(9) VALUE ‘INVCSEGM(‘
05 FILLER PIC X(10) VALUE ‘INVC NO =’
05 WS-INVCNO PIC S9(7) COMP-3 VALUE 1001.
05 FILLER PIC X(1) VALUE ‘)’.
01 UNQUL-PRIC-SSA PIC X(9) VALUE ‘ITEMSEGM’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 ------------------
-------------------
-------------------
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN OUTPUT INVCFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GU
INVC-PCB-MASK
INVC-IO-AREA
QUAL-INVC-SSA.
IF INVC-STATUS-CODE = SPACES
MOVE INVC-IO-AREA TO INVC-DATA
PERFORM 2100-PROCESS-PARA UNTIL EODB = ‘Y’
ELSE
IF WS-STATUS-CODE = ‘ GE ‘

Page 30 of 55
IMS DB MATERIAL
DISPLAY ‘ INVALID KEY’
END-IF.
2100-PROCESS-PARA
CALL ‘CBLTDLI’ USING DLI-GNP
INV-PCB-MASK
INVC-IO-AREA
UNQUL-ITEM-SSA
IF STATUS-CODE = SPACES
MOVE INVC-DATA TO INVCREC
WRITE INVCREC
ELSE
IF INVC-STATUS-CODE = ‘GE’
MOVE ‘Y’ TO EODB
ELSE
IF INVC-STATUS-CODE = ‘GP’
DISPLAY ‘ NO PARENTAGE SET’
ABEND THE PROGRAM
END-IF.
3000-CLOSE-PARA.
CLOSE INVCFILE.

OUTPUT: 1001 10/10/2008 IT001 PEN


IT002 BOOK

REASONS FOR GETTING ‘ GP ’ STATUS CODE

 If a GNP call is issued without first establishing parentage on a segment by a GU or GN


call.
 If the GU or GN call is issued to establish the parentage is not executed successfully
before the GNP call was issued.
 An established parent segment is deleted before the GNP call depending on that parent is
issued.
 If the SSA’s coded in the GNP call contains errors.

USAGE OF COMMAND CODES?

 Usage of command codes will improve the DL/I call function & Avoid some coding in a
program.

Page 31 of 55
IMS DB MATERIAL
 Command code in SSA is used to define the action to be performed by the DLI for
segment retrieval.
 Command code is referred in the SSA of the DL/I call statement make the call more
qualify. Command code can be used both in Qualified & UN Qualified SSA’s.
 Use of Command code in the SSA is recognized by the 9th position “*” as argument &
10th position should be coded with a Command code.
 Command codes can be useful to go to certain occurrences of the segment and avoid
some coding in a program.

Usage of each Command code is referred in the given below table.

COMMAND CODE in 10th position USAGE


- (Hyphen) Null
F (First occurrence) To retrieve first occurrence in a segment type
L (Last occurrence) To retrieve last occurrence in a segment type
C (Concatenated Key) To retrieve the unique occurrence using one SSA
D (Path Call) To get the higher level segment in a Path call
N (Path Call ignore) Path call ignores segment. Do not replace this
segment.
P (Parentage set) Establish Parentage at this level.
Q
U Maintain the current position at this level
V Maintain the current position at this & higher level.

“F “COMMAND CODE:
 “F” command code is used to retrieve the first occurrence from a segment.
 If “F” command code is used in Un qualified SSA it retrieves the first occurrence from
the segment specified

01 UNQUL-INVC-SSA PIC X (11) VALUE ‘INVCSEGM*F ’


 It retrieves the first occurrence from the root segment.

PROG 6…. Write a program that retrieves the first occurrence in PRICSEGM and write
it into file using command code “ F “ and UNQUAL-SSA.

ID DIVISION.
PROGRAM.ID. COMCDF.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT PRICFILE ASSIGN TO INVC.
DATA DIVISION.

Page 32 of 55
IMS DB MATERIAL
FILE SECTION.
FD INVCFILE.
01 PRICREC PIC X(8).
WORING-STORAGE SECTION.
01 PRIC-IO-AREA PIC X(8).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GN PIC X(4) VALUE ‘GN ‘.
01 UNQUL-PRIC-SSA PIC X(11) VALUE ’PRICSEGM*F ’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 -------------------
------------------
--------------------
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN OUTPUT PRICFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GN
INVC-PCB-MASK
PRIC-IO-AREA
UNQUL-PRIC-SSA
IF INVC-STATUS-CODE = SPACES
WRITE PRICREC FROM PRIC-IO-AREA
ELSE
IF INVC-STATUS-CODE = ‘GB’
DISPLAY ‘NO OCCURRENCES’
END-IF.
3000-CLOSE-PARA.
CLOSE PRICFILE.

OUTPUT: 10 500.00

If “ F ” command code is used in Qualified SSA & the key value you passed is a Sequence field
with duplicities then it retrieves the 1st occurrence among the duplicate records. For
Ex: 01 QUAL-PRIC-SSA.
05 FILLER PIC X (11) VALUE ‘CUSTSEGM*F(‘.
05 FILLER PIC X (10) VALUE ‘FSTNAME IS:‘.
05 WS-FNAME PIC X (5) VALUE ‘LALIT’

Page 33 of 55
IMS DB MATERIAL
05 FILLER PIC X (1) VALUE ‘)’.

CUSTSEGM first name is not declared as sequence field, hence customer has 2 names LALIT
KUMAR, LALIT BABU if the SSA coded as first name then it retrieves First occurrence with
that name matches.

“ L “ COMMAND CODE
 “L” command code is used to retrieve the last occurrence from a segment.
 If “L” command code is used in Unqualified SSA it retrieves the last occurrence from the
segment specified.
Ex:
01 UNQUL-INVC-SSA. PIC X (11) VALUE ‘INVCSEGM*L ’

It retrieves the last occurrence from the INVC segment.

PROG 7…. Write a program that retrieves the last occurrence in PRICSEGM and write it
into file using command code “ L “ and UNQUAL-SSA.

ID DIVISION.
PROGRAM.ID. COMCDF.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT PRICFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD INVCFILE.
01 PRICREC PIC X(8).
WORING-STORAGE SECTION.
01 PRIC-IO-AREA PIC X(8).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GN PIC X(4) VALUE ‘GN ‘.
01 UNQUL-PRIC-SSA PIC X(11) VALUE ’PRICSEGM*L ’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 -------------------
------------------
--------------------
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA.
PERFORM 3000-CLOSE-PARA.
GOBACK.

Page 34 of 55
IMS DB MATERIAL
1000-OPEN-PARA.
OPEN OUTPUT PRICFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GN
INVC-PCB-MASK
PRIC-IO-AREA
UNQUL-PRIC-SSA
IF INVC-STATUS-CODE = SPACES
WRITE PRICREC FROM PRIC-IO-AREA
ELSE
IF INVC-STATUS-CODE = ‘GB’
DISPLAY ‘NO OCCURRENCES’
END-IF.
3000-CLOSE-PARA.
CLOSE PRICFILE.

OUTPUT: 20 800.00

If “ L ” command code is used in Qualified SSA & the key value you passed is a Sequence
field with duplicities then it retrieves the last occurrence among the duplicate records.

Ex: 01 QUAL-INVC-SSA.
05 FILLER PIC X (11) VALUE‘CUSTSEGM*L (‘.
05 FILLER PIC X (10) VALUE ‘FISTNAME = ‘.
05 WS-FNAME PIC X(5) VALUE ‘LALIT’.
05 FILLER PIC X (1) VALUE ‘)’.

CUSTSEGM first name is not declared as sequence field, hence customer has 2 names LALIT
KUMAR, LALIT BABU, if the SSA coded as first name last occurrence with that name
matches.

F & L Command Codes are useful in case of Unqualified SSA, In case of Qualified SSA when
the passed key value having duplicate values then only it is useful.

“ D ” COMMAND CODE
“D” command code is used to retrieve the data at the higher level.

Ex: CALL ‘CLBTDLI’ USING DLI-GU


PCB-MASK
WS-IO-AREA
QUAL-INVC-SSA.
QUAL-CUST-SSA.

Page 35 of 55
IMS DB MATERIAL
QUAL-ITEM-SSA.
QUAL-PRIC-SSA.
If the call statement is coded and the SSA does not contain any command code when call is
success data will retrieve from PRICSEGM (lower segment).
Always whatever coded the last SSA in the CALL statement that data stored in the IO-AREA

By using this we can retrieve the data coded in the last SSA. In case we want to retrieve all the
data related to one customer we coded 4 SSA’s and 4 CALL in the PROG 4…. To avoid that we
are using command code “D”. By using this we can code 4 SSA’s and 1 CALL statement.

PROG 8………Write a program to retrieve the ALL details (INVCNO, INVCDATE,


FNAME, LNAME, ITEMNO, ITEMNAME, ITEMQTY AND TOTPRIC) of customer
who’s having INVCNO 1003, FSTNAME ‘LALIT’, ITEMNO ‘IT003’ AND ITEMQTY
IS 20 by using COMMAND CODE “D”.

ID DIVISION.
PROGRAM.ID. COMDCD.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT INVCFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD INVCFILE.
01 INVCREC PIC X(42).
WORKING-STORAGE SECTION.
01 INVC-IO-AREA PIC X(42).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GU PIC X(4) VALUE ‘GU ‘.
01 WS-INVC-DATA
05 INVC-DATA
10 WS-INVCNO PIC S9(7) COMP-3.
10 WS-INVCDATE PIC X(10).
05 CUST-DATA
10 WS-FNAME PIC X(5).
10 WS-LNAME PIC X(5.
05 ITEM-DATA
10 WS-ITEMNO PIC X(5).
10 WS-ITEMNAME PIC X(5).
05 PRIC-DATA
10 WS-ITEMQTY PIC S9(7) COMP-3.
10 WS-TOTPRICE PIC S9(7) COMP-3.
01 QUAL-INVC-SSA.
05 FILLER PIC X(9) VALUE ‘INVCSEGM*D(‘
05 FILLER PIC X(10) VALUE ‘INVC NO=’

Page 36 of 55
IMS DB MATERIAL
05 WS-INVCNO PIC S9(7) COMP-3 VALUE 1003.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-CUST-SSA.
05 FILLER PIC X(9) VALUE ‘CUSTSEGM*D(‘
05 FILLER PIC X(10) VALUE ‘FNAME =’
05 WS-INVCNO PIC S9(7) COMP-3 VALUE ‘LALIT’
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-ITEM-SSA.
05 FILLER PIC X(9) VALUE ‘ITEMSEGM*D(‘
05 FILLER PIC X(10) VALUE ‘ITEM NO=’
05 WS-INVCNO PIC S9(7) COMP-3 VALUE ‘IT003’.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-PRIC-SSA.
05 FILLER PIC X(9) VALUE ‘PRICSEGM*D(‘
05 FILLER PIC X(10) VALUE ‘ITEMQTY=’
05 WS-ITEMQTY PIC S9(7) COMP-3 VALUE 20.
05 FILLER PIC X(1) VALUE ‘)’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 INVC-DBD-NAME PIC X(8) VALUE ‘INVOCDBD’.
05 INVC-SEGM-LEVEL PIC X(2).
05 INVC-STATUS-CODE PIC X(2).
05 INVE-PROC-OPT PIC X(4).
05 FILLER PIC X(8).
05 INVC-SEGM-NAME PIC X(8).
05 INVC-KEY-LENGTH PIC S9(7) COMP-3.
05 INVC-NOF-SENSEG PIC S9(7) COMP-3
05 INVC-KEY-VALUE PIC X(18).
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN OUTPUT INVCFILE.
2000-PROCESS-PARA.
INTITIALIZE WS-INVE-DATA
CALL ‘CBLTDLI’ USING DLI-GU
INVC-PCB-MASK.
INVC-IO-AREA.
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA
QUAL-PRIC-SSA

Page 37 of 55
IMS DB MATERIAL
IF INVC-STATUS-CODE = SPACES
MOVE INVC-IO-AREA TO WS-INVC-DATA
WRITE INVCREC FROM WS-INVC-DATA
ELSE
IF INVC-STATUS-CODE = ‘GE’
DISPLAY ‘INVALID OCCURRENCE’
END-IF.

3000-CLOSE-PARA
CLOSE INVCFILE.

OUTPUT: 1003 10/10/2008 LALIT BABU IT003 PEN 20 1000.00

If the call statement is coded and the SSA has D command code then & if call is success data
will retrieve from INVC, CUST, and ITEM & PIRC SSA & will place in INVC-IO-AREA this
time IO-AREA length should be 42.

If I did not code D command code at any level data won’t be retrieved from that level but the key
values should be passed & IO-AREA should be reduced accordingly.

“ C ” COMMAND CODE:
“C” command code usage reduces the number of SSAs coded to retrieve the data at the lower
level. To retrieve the data at the lower level you don’t have to code separate SSAs for each level
in the hierarchical path. Instead, you can use a single SSA with the “ C “ command code.

CALL ‘CLBTDLI’ USING DLI-GU


PCB-MASK
WS-IO-AREA (length is 8 if no command code)
QUAL-INVC-SSA.
QUAL-CUST-SSA.
QUAL-ITEM-SSA.
QUAL-PRIC-SSA.
01 QUAL-PRIC-SSA.
05 FILLER PIC X (11) VALUE ‘PRICSEGM*C(‘.
05 INVC-QUAL-SSA PIC S9(7)COMP-3.
05 CUST-QUAL-SSA PIC X(5).
05 ITEM-QUAL-SSA PIC X(5).
05 PRIC-QUAL-SSA PIC S9(7)COMP-3.
05 FILLER PIC X(1) VALUE ‘)’.

Page 38 of 55
IMS DB MATERIAL
Can declare by using “ C “ command code in this format instead coding with 4 SSA to get the
result.

PROG 9…..Write a program that retrieves the price details of cust3 who’s INVCNO:
1003, FAME ‘LALIT’ ITEMNO: ‘IT003’ AND ITEMQTY IS 20.

ID DIVISION.
PROGRAM.ID. COMDCC.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT PRICFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD PRICFILE.
01 PRICREC PIC X(8).
WORKING-STORAGE SECTION.
01 PRIC-IO-AREA PIC X(8).
01 EODB PIC X(1) VALUE ‘N’.
01 DLI-GU PIC X(4) VALUE ‘GU ‘.
01 QUAL-PRIC-SSA
05 FILLER PIC X (11) VALUE ‘PRICSEGM*C(‘.
05 INVC-QUAL-SSA PIC S9(7)COMP-3 VALUE ‘1003’.
05 CUST-QUAL-SSA PIC X(5) VALUE ‘LALIT’.
05 ITEM-QUAL-SSA PIC X(5) VALUE ‘IT003’.
05 PRIC-QUAL-SSA PIC S9(7)COMP-3 VALUE 20.
05 FILLER PIC X(1) VALUE ‘)’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 --------------
--------------
---------------
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN OUTPUT INVCFILE.
2000-PROCESS-PARA.
CALL ‘CBLTDLI’ USING DLI-GN
INVC-PCB-MASK.
PRIC-IO-AREA.
QUAL-PRIC-SSA

Page 39 of 55
IMS DB MATERIAL
IF INVC-STATUS-CODE = SPACES
MOVE PRIC-IO-AREA TO PRICREC
WRITE PRICREC
ELSE
IF INVC-STATUS-CODE = ‘GB’
DISPLAY ‘INVALID OCCURRENCE’
END-IF.
3000-CLOSE-PARA
CLOSE PRICFILE.

OUTPUT: 20 800

“ P ” COMMAND CODE:
“ P ” command code is used to set the parentage. When a call statement is coded parentage will
be set for the segment with the last SSA coded in the call statement.

It is used to override the default parentage settings. i.e., if you want to set the parentage at the
higher level.

01 QUAL-INVC-SSA.
05 FILLER PIC X (9) VALUE ‘INVCSEGM (‘.
05 FILLER PIC X (10) VALUE ‘INVCNO = ‘.
05 WS-INVCNO PIC S9(7) COMP-3 VALUE ‘1003’.
05 FILLER PIC X (1) VALUE ‘)’.
01 QUAL-CUST-SSA.
05 FILLER PIC X (9) VALUE ‘CUSTSEGM *P(‘.
05 FILLR PIC X (10) VALUE ‘FISTNAME = ‘.
05 WS-FNAME PIC X (5) VALUE ‘LALIT’.
05 FILLR PIC X (1) VALUE ‘)’.
01 QUAL-ITEM-SSA.
05 FILLER PIC X (9) VALUE ‘ITEMSEGM (‘.
05 FILLR PIC X (10) VALUE ‘ITEMNO = ‘.
05 WS-ITEMNO PIC X (5) VALUE ‘IT001’.
05 FILLER PIC X (1) VALUE ‘)’.
01QUAL-PRIC-SSA.
05 FILLER PIC X (9) VALUE ‘PRICSEGM (‘.
05 FILLER PIC X (10) VALUE ‘ITEMQTY = ‘.
05 WS-ITMQTY PIC X (5) VALUE ‘10’.
05 FILLER PIC X (1) VALUE ‘)’.

By default parentage is set at the PRIC segment, as coding the “ P “ command code at the
customer segment will override the default parentage settings. Parentage is now set at the CUST

Page 40 of 55
IMS DB MATERIAL
segment. If more than one P command code is coded parentage will be set at the last “ P “
command coded.

“ N ” COMMAND CODE

“ N ” command code is used at the path call for either of the REPL/DELETE processing. N
command is coded along with the Unqualified SSA which is to say that you don’t the data in the
mentioned segment not to be replaced /deleted.

01 QUAL-INVC-SSA.
05 FILLER PIC X (11) VALUE ‘INVCSEGM*D (‘.
05 FILLER PIC X (10) VALUE ‘INVCNO = ‘.
05 WS-INVCNO PIC S9 (7) COMP-3 VALUE ‘1003’.
05 FILLER PIC X (1) VALUE ‘)’.
01 QUAL-CUST-SSA.
05 FILLER PIC X (11) VALUE ‘CUSTSEGM*D (‘.
05 FILLER PIC X (10) VALUE ‘FISTNAME = ‘.
05 WS-FSTNAME PIC X (5) VLUE ‘LALITH’.
05 FILLER PIC X (1) VALUE ‘)’.
01 QUAL-ITEM-SSA.
05 FILLER PIC X (11)VALUE ‘ITEMSEGM*D (‘.
05 FILLR PIC X (10) VALUE ‘ITEMNO = ‘.
05 WS-ITEMNO PIC X (5) VALUE ‘ITEM1’.
05 FILLR PIC X (1) VALUE ‘)’.
01 QUAL-PRIC-SSA.
05 FILLER PIC X (11) VALUE ‘PRICSEGM*D (‘.
05 FILLER PIC X (10) VALUE ‘ITEMQTY = ‘.
05 WS-ITEMQTY PIC X (5) VALUE ‘10’.
05 FILLER PIC X (1) VALUE ‘)’.

In the above example data is retrieved from all the segments & now when u give replace (REPL)
call directly data will get updated in all the segments. To override that & don’t what the data to
be replaced in any one of the segments than we need to code “ N “ command code with
unqualified SSA.

MOVE N TO ITEM-SSA.
CALL ‘CLBTDLI’ USING DLI-REPL
PCB-MASK
I-O-AREA
ITEM-SSA.

“ - “ COMMAND CODE

Page 41 of 55
IMS DB MATERIAL
 When the value of a command code field is a hyphen (-), it’s considered to be a null
command code. In other words, although the command code Position is present, DL/I
Ignores it.
 This can be partially useful if you’d like to be able to use the same SSA with and without
command codes.

Ex: 01 UNQUL-INVC-SSA PIC X (11) VALUE ‘INVCSEGM*- ’

CALL ‘CBLTDLI’ USING DLI-GN


INVC-PCB-MASK
INVC-IO-AREA
UNQUL-INVC-SSA

In the above example hyphen (-) command code is used in the 10th position, which means that it
ignores the use of command code, i.e. there is no importance to this Command code & the result
is it retrieves all the occurrences from the INVCSEGM segment.

01 UNQUL-INVC-SSA PIC X (9) VALUE ‘INVCSEGM ’

Here in this example there is no command code, which is being used. The result for this example
is it retrieves all the occurrences from the INVCSEGM segment.

If I want use same SSA with command code F, then we MOVE the command code “ F “ before
the call statement

MOVE F TO UNQUL-INVC-SSA(10:1)
CALL ‘CBLTDLI’ USING DLI-GN
INVC-PCB-MASK
INVC-IO-AREA
UNQUL-INVC-SSA
Like this we can override the command code at the time of execution.

Ex: in case of QUAL-SSA.

01 QUAL-INVC-SSA.
05 FILLER PIC X(11) VALUE ‘INVCSEGM*-(‘
05 FILLER PIC X(10) VALUE ‘INVC NO:’
05 WS-INVCNO PIC S9(7) COMP-3 VALUE 1003.
05 FILLER PIC X(1) VALUE ‘)’.

MOVE L TO QUAL-INVC-SSA(10:1)
CALL ‘CBLTDLI’ USING DLI-GN
INVC-PCB-MASK
INVC-IO-AREA

Page 42 of 55
IMS DB MATERIAL
QUAL-INVC-SSA
 It is most useful command code used in the real time… why because the same SSA’s are
used different programmers with different command codes. It is the best way declaring
the SSA’s with NULL command code.
 Whenever we are using the SSA we moves required command code to that SSA.

INSERT

In three ways we can insert the data.


1. Sequential - Insert into particular segment.
- Insert entire data (INVC, CUST, ITEM and PRICE) into
individual data base.
2. Random - Insert only particular customer’s entire database record.
3. Dynamic - Insert multiple child occurrences to particular patent.

INSETTION RULES:

 Load / Insert the segment occurrences in Hierarchy.


 In which segment we want to insert data, that segment should declare as Unqualified SSA
i.e., in case we are inserting the data in only one segment.
 In case we are inserting data using command code “ D “ there is no need to declare
Unqualified SSA.
 IO-AREA acts as from function in INSERT.
 IO-AREA acts as into function in READ.
 Root segment should never have any duplicate data.

PROG 10…. Write a program that reads the data form INVC file, check the data is
existing in database or not…… If not exists then insert the data into INVC database.

ID DIVISION.
PROGRAM.ID. ISRTPGM1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT INVCFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD INVCFILE.
01 INVCREC. PIC X(14)
WORKING-STORAGE SECTION.
01 DLI-ISRT PIC X(4) VALUE ‘ISRT ‘.
01 INVC-IO-AREA PIC X(8).
01 EOF PIC X(1) VALUE ‘N’.
01 UNQUL-INVC-SSA PIC X(9) VALUE ‘INVCSEGM ‘.
LINKAGE SECTION.

Page 43 of 55
IMS DB MATERIAL
01 INVC-PCB-MASK
05 -------------
--------------
---------------
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK.
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA UNTIL EOF = ‘Y’.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN INPUT INVCFILE.
2000-PROCESS-PARA.
INITIALIZE INVC-IO-AREA
READ INVCFILE INTO INVC-IO-AREA
AT END MOVE ‘Y’ TO EOF
IF EOF = ‘Y’
CONTINUE
ELSE
PERFORM 2100-INSERT-DATA
END-IF.
2100-INSERT-DATA
CALL ‘CBLTDLI’ USING DLI-ISRT
INVC-PCB-MASK
INVC-IO-AREA
UNQUL-INVC-SSA.

IF INVC-STATUS-CODE = SPACES
DISPLAY ‘ RECORD INSERTED’ INVC-IO-AREA
ELSE
IF INVC-STATUS-CODE = ‘II’
DISPLAY ‘ DUPLICATE RECORD’ INVC-IO-AREA
END-IF.

3000-CLOSE-PARA
CLOSE PRICFILE.

If you want to insert the new database record i.e., inserting the new INVC, CUST, ITEM, PRIC
details it can be done in two ways….
1. By using command code “D” i.e., declare all Qualified SSA’s with command code
“D”.
2. By declaring 4 Qualified & 4 Unqualified SSA’s and 4 CALL statements.

Ex: declaring the 1st way

Page 44 of 55
IMS DB MATERIAL
PROG 11…. Write a program that reads the data form INVC file, check the data is
existing in database or not…… If not exists then insert entire data into INVC database.
ID DIVISION.
PROGRAM.ID. ISRTPGM2.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 DLI-ISRT PIC X(4) VALUE ‘ISRT ‘.
01 INVC-IO-AREA PIC X(14).
01 QUAL-INVC-SSA.
05 FILLER PIC X (11) VALUE ‘INVCSEGM*D (‘.
05 FILLER PIC X (10) VALUE ‘INVCNO = ‘.
05 SSA-INVCNO PIC S9 (7) COMP-3.
05 FILLER PIC X (1) VALUE ‘)’.
01 QUAL-CUST-SSA.
05 FILLER PIC X (11) VALUE ‘CUSTSEGM*D (‘.
05 FILLER PIC X (10) VALUE ‘FISTNAME = ‘.
05 SSA-FSTNAME PIC X (5).
05 FILLER PIC X (1) VALUE ‘)’.
01 QUAL-ITEM-SSA.
05 FILLER PIC X (11)VALUE ‘ITEMSEGM*D (‘.
05 FILLR PIC X (10) VALUE ‘ITEMNO = ‘.
05 SSA-ITEMNO PIC X (5).
05 FILLR PIC X (1) VALUE ‘)’.
01 QUAL-PRIC-SSA.
05 FILLER PIC X (11) VALUE ‘PRICSEGM*D (‘.
05 FILLER PIC X (10) VALUE ‘ITEMQTY = ‘.
05 SSA-ITEMQTY PIC X (5).
05 FILLER PIC X (1) VALUE ‘)’.
01 WS-INVC-DATABASE
05 WS-INVC-DATA
10 WS-INVCNO PIC S9(7) COMP-3 VALUE 1003
10 WS-INVCDATE PIC X(10) VALUE ‘10/10/2008’
05 WS-CUST-DATA
10 WS-FNAME PIC X(5) VALUE ‘ HARI’.
10 WS-LNAME PIC X(5) VALUE ‘KUMAR’.
05 WS-ITEM-DATA
10 WS-ITEMNO PIC X(5)VALUE ‘IT004’.
10 WS-ITEMNAME PIC X(5) VALUE ‘CLOCK’.
05 WS-PRIC-DATA
10 WS-ITEMQTY PIC S9(7) COMP-3 VALUE 10.
10 WS-TOTPRICE PIC S9(7) COMP-3 VALUE 900.00.
LINKAGE SECTION.
01 INVC-PCB-MASK.
05 ---------------

Page 45 of 55
IMS DB MATERIAL
-----------------
-----------------
PROCUDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK
PERFORM 1000-PROCESS-PARA
GOBACK.
1000-PROCESS-PARA.
MOVE WS-INVCNO TO SSA-INVCNO.
MOVE WS-FNAME TO SSA-FSTNAME.
MOVE WS-ITEMNO TO SSA-ITEMNO.
MOVE WS-ITEMQTY TO SSA-ITEMQTY

CALL ‘ CBLTDLI’ USING DLI-ISRT


INVC-PCB-MASK
INVC-IO-AREA
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA
QUAL-PRIC-SSA
IF INVC-STATUS-CODE = SPACES
DISPLAY ‘ RECORD INSETED SUCCESSFULLY’ INVC-IO-AREA
ELSE
IF INVC-STAUS-CODE = ‘II’
DISPLAY ‘ DUPLICATE RECORD’ INVC-IO-AREA
END-IF.

If I want to insert ITEM & PRICE then both must be an unqualified SSA.
 In first call use Unqualified SSA for ITEM segment.
 In second call use Unqualified SSA for PRIC segment.
To insert multiple child occurrences for a particular parent….

Ex: insert multiple prices (600.00, 530.00,6 40.00) for IT001 in price segment.

CALL ‘ CBLTDLI’ USING DLI-ISRT


INVC-PCB-MASK
INVC-IO-AREA
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA
UNQUL-PRIC-SSA
Put this statement in loop and no need to change the call statement….

REPLACE CALL & DELETE CALL

Replace & Delete are 3 types

Page 46 of 55
IMS DB MATERIAL
1. Sequential
2. Random
3. Dynamic

To make changes / delete / Replace we can use HOLD call.


To Replace / Delete there should be always 2 call statements. First one is HOLD call and
second one is REPL / DLET call.

There are 3 types of HOLD calls.

1. GHU - For particular occurrence in the segment REPL / DLET.


2. GHN - For all the occurrences in the segment REPL / DLET.
3. GHNP - For multiple child occurrences particular parent REPL / DLET.

RULES FOR REPLACE

 Replacing the existing data in a database should be done by using any of the HOLD
CALL
 HOLD CALL retrieves the data which needs to be changed and places in the IO-Area
 The new data which we want to replace in the database should be passed to the IO-Area
without changing i). key field value
ii). Segment length.
 Once the replace call is given, the changed data which we passed to the IO-AREA will be
updated in the database once the REPL CALL is success.
 We cannot code any SSA in a REPL / DLET call
 There should be a preceding hold call before the replace call and the hold call should be
success in order to execute the replace call.
 We can’t code any other DLI call referring to same database in between HOLD call and
REPLACE call
 If we want to code any other DLI call statement in between HOLD call and REPL call
(its PCB-MASK should be changed / differ) there should be a different database.

STATUS CODES IN REPLACE CALL

AJ - if SSA’s are coded in a replace call.


DJ - if no HOLD call executed before REPLACE call.
DA - if I try to change sequence key field value.

PROG 12…..read the file; replace all the price details of customers…

ID DIVISION.
PROGRAM.ID. REPLPGM.
ENVIRONMENT DIVISION.

Page 47 of 55
IMS DB MATERIAL
INPUT-OUTPUT SECTION.
FILE CONTROL.
SELECT PRICFILE ASSIGN TO INVC.
DATA DIVISION.
FILE SECTION.
FD PRICFILE.
01 PRICREC PIC X(42)
WORKING-STORAGE SECTION.
01 DLI-GHU PIC X(4) VALUE ‘GHU ‘.
01 DLI-REPL PIC X(4) VALUE ‘REPL’.
01 PRIC-IO-AREA
05 ITEMQTY PIC S9 (7) COMP-3.
05 TOTPRICE PIC S9(7) COMP-3.
01 EOF PIC X(1) VALUE ‘N’.
01 WS-INVC-REC
05 WS-INVC-DATA
10 WS-INVCNO PIC S9(7) COMP-3.
10 WS-INVCDATE PIC X(10).
05 WS-CUST-DATA
10 WS-FNAME PIC X(5).
10 WS-LNAME PIC X(5).
05 WS-ITEM-DATA
10 WS-ITEMNO PIC X(5).
10 WS-ITEMNAME PIC X(5).
05 WS-PRIC-DATA
10 WS-ITEMQTY PIC S9(7) COMP-3.
10 WS-TOTPRICE PIC S9(7) COMP-3.
01 QUAL-INVC-SSA
05 FILLER PIC X(9) VALUE ‘INVCSEGM(‘
05 FILLER PIC X(10) VALUE ‘INVC NO:’
05 SSA-INVCNO PIC S9(7) COMP-3
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-CUST-SSA
05 FILLER PIC X(9) VALUE ‘CUSTSEGM(‘
05 FILLER PIC X(10) VALUE ‘FNAME :’
05 SSA-FNAME PIC S9(7) COMP-3.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-ITEM-SSA
05 FILLER PIC X(9) VALUE ‘ITEMSEGM(‘
05 FILLER PIC X(10) VALUE ‘ITEM NO:’
05 SSA-ITEMNO PIC S9(7) COMP-3.
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-PRIC-SSA
05 FILLER PIC X(9) VALUE ‘PRICSEGM(‘
05 FILLER PIC X(10) VALUE ‘ITEMQTY:’

Page 48 of 55
IMS DB MATERIAL
05 SSA-ITEMQTY PIC S9(7) COMP-3.
05 FILLER PIC X(1) VALUE ‘)’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 -----------------
-----------------
-----------------
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK
PERFORM 1000-OPEN-PARA.
PERFORM 2000-PROCESS-PARA UNTIL EOF = ‘Y’.
PERFORM 3000-CLOSE-PARA.
GOBACK.
1000-OPEN-PARA.
OPEN INPUT PRICFILE.
2000-PROCESS-PARA.
INITIALIZE WS-INVC-REC
READ PRICFILE INTO WS-INVC-REC
AT END
MOVE ‘Y’ TO EOF
NOT AT END
PERFORM 2100-HOLD- DATA
END-IF.
2100-HOLD-DATA
MOVE WS-INVCNO TO SSA-INVCNO.
MOVE WS-FNAME TO SSA-FNAME.
MOVE WS-ITEMNO TO SSA-ITEMNO.
MOVE WS-ITEMQTY TO SSA-ITEMQTY.
CALL ‘CBLTDLI’ USING DLI-GHU
INVC-PCB-MASK
PRIC-IO-AREA
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA
QUAL-PRIC-SSA.
IF INVC-SATAUS-CODE = SPACES
PERFORM 2200-REPL-PARA
ELSE
IF INVC-STATUS-CODE = ‘GE’
DISPLAY ‘KEY VALUE NOT FOUND ‘
END-IF
END-IF.
2200-REPL-PARA.
MOVE WS-PRICE-DATA TO TOTPRICE.
CALL ‘ CBLTDLI’ USING DLI-REPL

Page 49 of 55
IMS DB MATERIAL
INVC-PCB-MASK
PRICE-IO-AREA.
IF INVC-STATUS-CODE = SPACES
DISPLAY ‘ DATA FOR PRICE REPLACED SUCCESSFULLY’
ELSE
IF INVC-STATUS-CODE = ‘AJ ‘
DISPLAY ‘ REPLACE CALL VIOLATION USE OF SSA’
ELSE
IF INVC-STATUS-CODE = ‘DJ ‘
DISPLAY ‘HOLD CALL MISSING ‘
ELSE
IF INVC-STATUS-CODE = ‘DA’
DISPLAY ‘CHANGE IN KDY FIELD ‘
END-IF
END-IF
END-IF
END-IF.

3000-CLOSE-PARA.
CLOSE PRICFILE.

 The data which is in IO-AREA as always on HOLD (under lock state). No other user can
update same record at a time.
 If we want to replace in all segments, then code “ D “ command code in all SSA’s.
 Only two segment like ITEM & PRICE then code “ D “ command code for ITEM &
PRIC SSA’s.
 When ITEMQTY is not present the call status fails and it places a ‘?’ and gives the ‘GE’
as status code.
 When ‘GE’ is thrown, always we get ‘?’ in all the key values that doesn’t exist.
 In real time 99% use ‘GHU’ call to replace. GHN and GHNP are never used in real time.

PROG 13…. Write a program that deletes the price details of particular item for cust3.

ID DIVISION.
PROGRAM.ID. REPLPGM.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 DLI-GHU PIC X(4) VALUE ‘GHU ‘.
01 DLI-REPL PIC X(4) VALUE ‘DLET’.
01 PRIC-IO-AREA
05 ITEMQTY PIC S9 (7) COMP-3.
05 TOTPRICE PIC S9(7) COMP-3.
01 WS-INVC-REC

Page 50 of 55
IMS DB MATERIAL
05 WS-INVC-DATA
10 WS-INVCNO PIC S9(7) COMP-3.
10 WS-INVCDATE PIC X(10).
05 WS-CUST-DATA
10 WS-FNAME PIC X(5).
10 WS-LNAME PIC X(5).
05 WS-ITEM-DATA
10 WS-ITEMNO PIC X(5).
10 WS-ITEMNAME PIC X(5).
05 WS-PRIC-DATA
10 WS-ITEMQTY PIC S9(7) COMP-3.
10 WS-TOTPRICE PIC S9(7) COMP-3.
01 QUAL-INVC-SSA
05 FILLER PIC X(9) VALUE ‘INVCSEGM(‘
05 FILLER PIC X(10) VALUE ‘INVC NO:’
05 SSA-INVCNO PIC S9(7) COMP-3 VALUE 1003
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-CUST-SSA
05 FILLER PIC X(9) VALUE ‘CUSTSEGM(‘
05 FILLER PIC X(10) VALUE ‘FNAME :’
05 SSA-FNAME PIC S9(7) COMP-3 VALUE ‘LALITH’
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-ITEM-SSA
05 FILLER PIC X(9) VALUE ‘ITEMSEGM(‘
05 FILLER PIC X(10) VALUE ‘ITEM NO:’
05 SSA-ITEMNO PIC S9(7) COMP-3 VALUE ‘IT003’
05 FILLER PIC X(1) VALUE ‘)’.
01 QUAL-PRIC-SSA
05 FILLER PIC X(9) VALUE ‘PRICSEGM(‘
05 FILLER PIC X(10) VALUE ‘ITEMQTY:’
05 SSA-ITEMQTY PIC S9(7) COMP-3 VALUE 20.
05 FILLER PIC X(1) VALUE ‘)’.
LINKAGE SECTION.
01 INVC-PCB-MASK
05 ---------------
---------------
---------------
PROCEDURE DIVISION.
ENTRY ‘DLITCBL’ USING INVC-PCB-MASK
CALL ‘CBLTDLI’ USING DLI-GHU
INVC-PCB-MASK
PRIC-IO-AREA
QUAL-INVC-SSA
QUAL-CUST-SSA
QUAL-ITEM-SSA

Page 51 of 55
IMS DB MATERIAL
QUAL-PRIC-SSA.
IF INVC-SATAUS-CODE = SPACES
PERFORM 2000-DELETE-PARA
ELSE
IF INVC-STATUS-CODE = ‘GE’
DISPLAY ‘KEY VALUE NOT FOUND ‘
END-IF
END-IF.
GOBACK.
2000-DELETE-PARA.
CALL ‘ CBLTDLI’ USING DLI-DLET
INVC-PCB-MASK
PRICE-IO-AREA.
IF INVC-STATUS-CODE = SPACES
DISPLAY ‘ PRICE DATA OF IT003 DELETED SUCCESSFULLY’
ELSE
IF INVC-STATUS-CODE = ‘AJ ‘
DISPLAY ‘ DELETE CALL VIOLATION USE OF SSA’
ELSE
IF INVC-STATUS-CODE = ‘DJ ‘
DISPLAY ‘HOLD CALL MISSING ‘
END-IF.

3000-CLOSE-PARA.
CLOSE PRICFILE.
STATUS CODES
************************ STATUS CODES *******************************
The following are the common status codes may be returned after processing an IMS call.
Blank Call completed successfully
AB Segment I/O area is missing from call statement
AD Function argument is not coded correctly
AH Invalid SSA encountered on insert call
AI Error opening database
AJ SSA specified for the call is invalid
AK Field name specified for qualified SSA is incorrectly coded
AM Function specified is not compatible with one of segment
sensitivity, program type, or PCB processing i.e., the procopt and
DLI function does not matched
AT I/O area specified is too small
AU Length for SSAs specified exceeds the maximum allowed
DA REPL or DLET attempted to change segment key field
DJ Get hold issued after REPL or DLET
DX DLET violated delete rule for segment
FA Arithmetic overflow error
FD resource deadlock
Page 52 of 55
IMS DB MATERIAL
FN Field name of FSA undefined in DBD and FLD function issued
FT Number of SSAs exceeds limit of 15 for DEDB or 1 for MSDB
GA Call completed successfully but higher level crossed for GN or
GNP call
GB End of database reached on GN call
GE Segment not found
GG Processing with procopt of GON or GOT and concurrent update
activity is occurring
GK Call completed successfully but different segment type on same
level retrieved for GN or GNP call i.e., you r decleared one
segment and accessing the other segment
GP GNP issued but parentage was not previously established
II Attempt to insert a segment with a duplicate key
IX Insert rule violation
LB Attempt to load a segment that already exists
LC Attempt to load a segment out of sequence
LD Attempt to load a segment whose parent does not exist
LE Hierarchical sequence in DBD does not match that in the segment
to be loaded

****************************IMS RUN JCL *******************************

//CY11791R JOB (TTQAA06350),'RAMANADHAM',


// MSGLEVEL=(1,1),MSGCLASS=X,NOTIFY=CY11791,
// REGION=0M,CLASS=U
//*
//JOBLIB DD DISP=SHR,DSN=ENDEV.FDCP.BATCH.LOADLIB
//***************************************************
//* STEP PS020 PGM BPBP029P COM LETTER PRINT
//***************************************************
//PS020 EXEC PGM=DFSRRC00,
// COND=(0,LT),
// REGION=5120K,
// PARM='DLI,BPBP029P,BP029T00'
//STEPLIB DD DSN=ENDEV.FDCP.BATCH.LOADLIB,DISP=SHR
//DFSRESLB DD DSN=IMD1.RESLIB,DISP=SHR
// DD DSN=IMD1.USEREXIT,DISP=SHR
//IMS DD DSN=WLDB.IMSTEST.PSBLIB,DISP=SHR
// DD DSN=WLDB.IMSTEST.DBDLIB,DISP=SHR
//*Is used if the Database Access type is VSAM then its DD is mentioned in jcl
//*DFSVSAMP DD DSN=TICP.PROD.SYSIN (DFSVS200), DISP=SHR
//*Input file for the program
//BPBP029R DD DSN=CY11791.SOURCE.CM.SORTED.BILLING,
// DISP=SHR
//Output file for the program
Page 53 of 55
IMS DB MATERIAL
//BPBP029S DD DSN=CY11791.SOURCE.CM.PRINT.LINES,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(20,5),RLSE),
// DCB=(MODELDCB,RECFM=FBA,LRECL=156,BLKSIZE=0)
//SYSOUT DD SYSOUT=*
//SYSABOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=U

****************JCL SAMPLE FOR BATCH IMS PROGRAM******************

PGM=DFSRRC00
PARM = (DL/I, PROGRAMNAME, PSBNAME)

 The program executed in an IMS batch job is not your application program. It is the IMS
batch IMS batch control region. DFSRRC00.
 Many parameters are passed to DFSRRC00, but the following three are the most often
used.

1. DL/I - THIS PARAMETER IS REQUIRED. iT TELLS ims that it will be


responsible for the application control block(ACB) building process. Other
possible values are DBD and BMP.
2. PGMNAME - This parameter is required. It must be the load module name your
application linked under.
3. PSBNAME - This parameter is optional. It is where you specify the PSB name
that your application program was linked under.
 The STEPLIB DDNAME specifies IMS resident libraries concatenated with load library
to which your program has been linked (optional, depending on system setup).
 The IMS DDNAME is required. It specifies the concatenation of the DBD and PSB
control block libraries. These two libraries are used by IMS to dynamically build the
ACB.
 The DFSRESLB DDNAME is optional and required at others (dependent on system
setup). It is the library that contains the IMS modules. If you do not include this
DDNAME in your execution JCL and it abends with a S306, then you will be required o
include this DDNAME before your rerun the job.
 The DFSVSAMP DDNAME is only required if the execution JCL contains DDNAMES
for IMS databases that use the VSAM access method. If used, it specifies the database
buffer information to IMS. Typically, this is a data set predefined by the DBA.
 The DDNAME used here reflects the DDNAME. Defined in the DBD for the database.
There is at least one DDNAME forever database defined in the PSB in the PARM = on
the EXEC statement.
 IN your application program uses any non-IMS data sets, you must include a DDNAME
for each of those as indicated by the FILE declaration of the FD in Cobol.

DIFFERENCES BETWEEN MPP, BMP & DLI

Page 54 of 55
IMS DB MATERIAL
These are different parameters using when we are executing the COBOL+IMS program.

DL/I
 It can be used as Interface between MPP and Database OR BMP and Database.
 For batch DL/I job it can access database directly.
 PSB of DL/I job can be used by another jobs simultaneously.
 It can run on Individual partitions.
BMP (Batch message processing)
 For batch programs only
 PSB used by a BMP program cannot be used by other programs simultaneously.
 All partitions specified in PSB will be allocated whether used by program or not.
 Cannot run on Individual partitions.
MPP (Message Processing Program)
 For Online programs (IMSDC) only.
 PSB used by a MPP program cannot be used by other programs simultaneously.
 Cannot run on Individual partitions.

Page 55 of 55

You might also like