ISPF & TSO Refresher
ISPF & TSO Refresher
ISPF
They are:
1. Primary Commands that can be entered in the Command Line.
2. Line Commands that can be entered in the line(s).
30.
The above commands will do the find from the current cursor position
and place the cursor over the string found.
F ‘Musa’ ALL Independent of cursor position, this will count all the ‘Musa’ and displays
the total count in the upper right corner and place the cursor over the
first occurrence from top.
F ‘Musa’ WORD Look for ‘ Musa ‘. Word is a string followed and prefixed by space.
Note: Change command is nothing but find and replace. So from string
can be qualified with other keywords available in FIND command. Ex C
‘st1’ ‘str2’ 1 replaces only the str1 that are in first position to str2.
DEL ALL X/NX Delete all the excluded/Not excluded lines. DEL .A .B deletes all the lines
between .A and .B
; Represents Enter key. So multiple commands can be given in one shot
with ‘;’ separation.
SORT 5 15 A Sorts in 5-15 in ascending sequence. Maximum 5 fields can be given. D
for descending.
Special String Characters that can be used with FIND and CHANGE:
Primary commands prefixed with & (ampersand) is left in the command line after execution. This way the
same command can be entered multiple times without retyping it in each time.
Mainframe Refresher Part-1 Page:4
Any of the line commands can be mapped to a PF key and invoked by pressing that key. Example
if you map ‘X ALL’ commands with PF4, then every time PF4 is pressed, all the lines are excluded. Mapping
can be done by the line command KEYS. In this way, 24 keys PF1-PF24 can be mapped. PF13-PF24 is
nothing but Shift + PF1- PF12.
PF1 Help
PF2 SPLIT - Split the screen at the cursor’s location
PF3 Exit
PF4 Exit or RETURN
PF5 RFIND - Find next occurrence of the last F command
PF6 RCHANGE – Change next occurrence of the last C command
PF7 UP
PF8 DOWN
PF9 SWAP
PF10 LEFT
PF11 RIGHT
PF12 RETRIEVE - repeats the previous command line command
LINE Commands:
)n Shift the line content by n columns to ))n Shift the block of lines by n columns to
the right side.(outside). >n is same as )n the right side.
but in case of data truncation, operation >>n is same as ))n but in case of data
will be error out. truncation, operation will be error out.
(n Shift the line content by n columns to ((n Shift the block of lines by n columns to
the left side.(inside) the left side.
<n is same as (n but in case of data <<n is same as ((n but in case of data
truncation, operation will be error out. truncation, operation will be error out.
TS n To split text in two at the point of cursor TF n To flow fragments of sentences into
to allow a word, phrase or sentence to paragraph. N defines the width.
be inserted. N number of lines are
inserted between the two parts of text.
TE Text Entry mode is used for bulk entry of BNDS To process only over a column of data,
text and allows power typing techniques define the range of columns using BNDS
to be used at the terminal. (Type data line command.
without bothering about end of line, line
numbers etc .The FINAL enter will re
flow the data.)
MASK It allows to put fixed data into the new O Overlay command indicates the target
lines being entered. (over line(s) when merging lines. Overlay is
Type MASK over a line number and press lay) used in conjunction with M or C line
enter. Overtype the mask with whatever commands.
we want. Now every time we enter new C 0300 *
lines with I, TE, TS – mask lines will be O 0400 MVSQuest
displayed rather than empty lines. Result:
0300 *
0400 * MVSQuest
O10 overlaid the first 10 lines. OO-OO
overlaid the block of lines.
TSO
Frequently used TSO commands are listed in the table. They can be issued from any ISPF panel
with TSO prefix. TSO prefix is not required if you execute them in TSO panel. (Option 6 of ISPF)
LISTCAT It is used to list entries in MVS catalog. The syntax and the available options
are explained in VSAM - IDCAMS section.
LISTCAT ENTRIES’SMSXL86.TEST.SOURCE’ ALL
LISTDS It is used get the information about one or more datasets.
LISTDS ‘dataset-name’ MEMBERS|HISTORY|STATUS|LEVEL
MEMBERS list all the members of a PDS. This command is useful in REXX to
process all the members of a PDS.
RENAME It is used to rename a dataset. Generic datasets are allowed.
RENAME ‘BPAMAIN.TEST.*’ ‘BPMAIN.UNIT.*’ renames all the datasets start
with BPMAIN.TEST to BPMAIN.UNIT.
TSO Commands can be executed in batch (JCL) using terminal monitor program IKJEFT01.
The above step renames two datasets from MVSQUEST qualifier to LEADSOFT qualifier. Any high volume
manual job can be completed in matter of minutes if you have good knowledge in ISPF and TSO
commands with little exposure to REXX.
Mainframe Refresher Part-1 Page:8
JCL
Mainframe Refresher Part-1 Page:9
JCL
Any business application is divided into logical modules and these modules are developed using
programming languages. These programs should be executed in a pre-defined sequence to achieve the
business functionality.
JCL (Job Control Language) is used to DEFINE and CONTROL the JOB to the operating system.
Definition involves definition of the programs need to be executed, the data for the programs and the
sequence of programs. CONTROL involves controlling the execution or bypassing of a program in the
sequence based on the result of the prior program execution.
123 11 16 73 80
NAME OPERATION OPERANDS
JCL statements should have // in column 1 and 2. STAR (‘*‘) in the third column, indicates that the line is a
comment line.
NAME is optional field. If coded, it should start at column3 and can have maximum 8 characters. The first
character should be an alphabet or national character (@, # or $). Remaining characters can be any
alphanumeric or national characters.
OPERATION follows NAME field. There should be at least one space between NAME and OPERATION. If
NAME is not coded then OPERATION can start at fourth column itself. Typical OPERATION keywords are
JOB, EXEC and DD.
OPERANDS are the parameters for the operation. OPERANDS follow OPERATION and there should be at
least one space between them. A comma separates parameters and there should not any space between
parameters. If the OPERANDS are more, then they can be continued in the next line. To continue the
current line, end the current line before column 72 with ‘,’ and start the next line anywhere between
columns 4-16. Columns 1-3 should be ‘// ‘.
COMMENT FIELD – Comment field optionally follows OPERAND FIELD, preceded by at least one blank.
End of Job is identified by NULL statement. NULL statement has // in column 1 and 2 with no NAME,
OPERATION or OPERAND fields. The statements coded after NULL statement will not be processed.
DELIMITER – Some times we pass the data in the JCL itself. This is called in-stream data. The starting of
data is identified by ‘*’ in the operand field of DD operation. DELIMITER indicates the end of data. /* in
column 1 and 2 is the default delimiter.
Mainframe Refresher Part-1 Page:10
Job Entry Subsystem (JES) is the job processor of MVS operating system.
MVS installation can have either JES2 or JES3. The submitted jobs are taken by JES for processing.
JES2 JES3
Decentralized Environment. Every processor Centralized Environment. There is a global
processes the incoming jobs individually. processor that controls all the other processors and
assigns the jobs to them.
Datasets are allocated before the step execution. Datasets are allocated before the job execution.
JCL Statements
JOB. It should be the first statement in the JCL. It indicates accounting information and JOB related
information to the system. If the member being submitted contains multiple job cards, then multiple jobs
will be submitted. These jobs will run concurrently or one after other based on job name, class and
initiator availability.
EXEC. The name of the program or procedure to be executed is coded here. Every EXEC statement in a
JOB identifies one step. Maximum of 255 EXEC statements can be coded in a JOB.
DD. Data Descriptor. The dataset details are coded here. Dataset contains the data that need to be
processed by the program or data that is produced by the program. Maximum 3273 DD statements can be
coded in a step.
JCL ERROR:
1. Errors before job starts execution: If there are syntax errors, then the whole job is rejected with
error message in JES MESSAGES. Typically this needs correction and resubmission of the whole
JOB.
2. Errors before step starts execution: If there is any allocation issues in a particular (like dataset
not found, duplicate dataset), then also the job will be error out but in this case there might be
already n steps got executed. Typically this needs correction and restart in the JOB.
ABEND:
Unlike JCL Errors, ABEND happens during the execution of a program in a step. ABENDS are
classified into 2 categories.
System ABEND(Snnn): System abend occurs when the system is not able to execute a statement that is
instructed in the program. Divide by ZERO results SOCB system abend. The OS throws it.
User ABEND(Unnnn): When some unexpected condition occurs in the data passed, the program will call
an abend routine and abend the step with proper displays. This is thrown by application based on the
requirement.
JOB Statement
Sample Syntax:
//JOBNAME JOB (ACCOUNTING INFO), (PROGRAMMER NAME),
// TIME=(MINUTES,SECONDS), CLASS=A,MSGCLASS=A,PRTY=14,ADDR=VIRT,
Mainframe Refresher Part-1 Page:11
// REGION=nK,MSGLEVEL=(A,B),COND=(N,OPERATOR), TYPRUN=SCAN
JOBNAME
It identifies name of the job. The job is identified in the JES SPOOL using this name. Naming rules
are already mentioned in the coding sheet section.
PROGRAMMER NAME
Programmer name or program functionality or group can be mentioned. It is used for
documentation (Max 20 chars)
PRTY
Syntax: PRTY=N (N can be 0 –15).
1. While selecting the jobs with same class for execution, JES schedules the high priority jobs first. The
job coded with PRTY=15 has the highest priority and PRTY=0 has the lowest priority.
2. PRTY works within the JOBCLASS. If there are 2 jobs with CLASS A is submitted and one with PRTY 3
and other with PRTY 4 then PRTY 4 will get into execution queue first.
3. PRTY function is disabled in most of the installations.
MSGLEVEL
Syntax: MSGLEVEL=(X,Y) (X can be 0-2 & Y can be 0-1)
1. It is used to control the lists of information appear in the Job log. To get maximum information in the
listing, code MSGLEVEL as MSGLEVEL(1,1)
2. The first parameter controls the statements. (0-Only job statement, 1-JCL, JES statements with
expanded procedures, 2-Only JCL and JES statement).
3. The second parameter controls the messages. (0- Only Step execution messages, 1-All JCL, JES,
operator and allocation messages).
Mainframe Refresher Part-1 Page:12
ADDRSPC
It is used to specify whether the job will run in the Real storage or Virtual storage.
Syntax: ADDRSPC={REAL|VIRT}
REAL – Allocation is done in REAL storage and the program is not page-able.
VIRT – Allocation is done in VIRTUAL storage and the program is page-able.
REGION
Syntax: REGION={xK | yM} (x can be 1-2096128 & y can be 1-2047).
1. It is used to specify the amount of central /virtual storage the job requires.
It can be requested in the units of kilobytes (xK) or megabytes (yM). If requested in terms of
kilobytes, then x should be multiple of 4 or the system will round it to nearest 4K allocates for your
job.
2. REGION can be coded in EXEC statement also. REGION parameter coded on JOB card overrides the
parameter coded on EXEC card.
3. Maximum virtual memory available is 2GB.
4. Region=0M allocate all the available memory in the address space to this job.
5. Region related ABENDS: When the requested region is not available, the JOB will ABEND with S822.
When the requested region is not enough for the program to run, you will get ABEND S80A or S804.
RESTART
RESTART parameter allows restarting from any particular step in the job.
Syntax: RESTART = Step-name in the job
RESTART = * means restart from the beginning.
To restart from any procedure steps, code RESTART=PROCSTEP.STEPNAME
Whereas PROCSTEP=name of the JCL step that invoked the PROC &
STEPNAME=name of the proc step where you want execution to start.
RESTART ignores any condition in the step being restarted and it can also be step
that is in the ELSE part of the IF..ELSE..ENDIF.
TYPRUN
It is used to request special job processing.
1. TYPRUN=SCAN checks the syntax errors without actual execution.
2. TYPRUN=HOLD checks the syntax error and if there is any error, it is notified and if there are no
errors, the job is kept in awaiting execution queue and it should be released by user for execution.
Release can be done by typing ‘A’ against the job name in SDSF.
3. TYPRUN=JCLHOLD Function is same as HOLD but the syntax check starts only after the release of the
job.
Mainframe Refresher Part-1 Page:13
TIME
It defines the maximum allowable CPU time for the JOB. The parameter can be coded at EXEC card also.
On EXEC, it defines CPU limit of step.
Syntax: TIME = (MINUTES, SECONDS), MINUTES <= 1440 and SECONDS < 60
TIME=NOLIMIT/1440/MAXIMUM means the job can use CPU for unlimited time
TIME=0 will produce unpredictable results.
If TIME is coded on both JOB as well as EXEC, then EXEC Time limit or the time left out in the job
Time limit – whichever is smaller will be the time permitted for the step to complete.
If a JOB runs more than allowed time, then it will ABEND with system ABEND code S322. If there
is no TIME parameter, then the CPU time limit pre-defined with CLASS Parameter will be effective.
NOTIFY
TSO User-id to whom the job END / ABEND / ERROR status should be notified. NOTIFY=&SYSUID
will send the notification to the user who submitted the job.
COND
1. It is used for conditional execution of JOB based on return code of JOB steps.
2. The return code of every step is checked against the condition coded on JOB card. If the condition is
found TRUE, then all the steps following it are bypassed.
3. Maximum eight conditions can be coded in the COND parameter. In case of multiple conditions, if
ANY of the condition is found TRUE then the JOB stops proceeding further.
Syntax: COND=(CODE,OPERATOR,STEPNAME)
STEPNAME is optional. If you code it, then that particular step-name return code is checked
against the CODE with the OPERATOR. If omitted, then the return codes of all the steps are checked. On
comparison, if the condition found to be true, then all the following steps are bypassed.
CODE can be 0-4095
OPERATOR can be GT, LT, GE, LE, EQ
It can be coded on EXEC statement. STEP level control is popular then JOB level control. On EXEC
statement, you may find ONLY, EVEN keywords against COND parameter.
COND=ONLY allows the step execution only if any prior step is ABENDED.
COND=EVEN allows the step execution independent of any prior ABENDS.
EXEC Statement
It defines the Step and Step level information to the system.
Syntax: //STEPNAME EXEC {PGM=program-name |
PROC=proc-name |
proc-name}
STEPNAME
It is an OPTIONAL field but it is needed if you want to restart a job from this step and for the
same reason, it should be unique within the job.
PGM or PROC
Code the Program name or PROC name to be executed. (1-8 characters)
Mainframe Refresher Part-1 Page:14
PARM
1. It is used to pass variable information to the processing program, executed by this job step.
2. If there is more than one sub parameter or if there is any special character then enclose them in
parentheses/quotes.
3. Maximum 100 characters can be passed in this way. Quotes and brackets are not included in this
100.To pass a quote to the program, indicate that with two quotes one followed by other.
4. The program can receive them using linkage section. Linkage section must be coded with half word
binary field as first field. This field is populated with length of the PARM passed from the JCL.
Example:
//STEP3 EXEC PGM=WORK,PARM=(DECK,LIST,'LINECNT=80',
// '12+80',NOMAP)
th
5. To continue the PARM in the second line, start the second line from 16 position.
DPRTY
PRTY assigns priority to a job and DPRTY assigns dispatching priority to job step. Syntax:
DPRTY=(value1, value2). Value1 and value2 can be 0-15. D-Priority is calculated using the formula
(value1*16 + value)
IF /THEN/ELSE/END-IF
It is used for conditionally executing one or more steps. Nesting is possible up to 15 levels. The
meaning is same as programming IF. If the coded condition is true, the following steps till ELSE will be
executed. If the condition is false, then the steps coded on ELSE part will be executed.
Syntax:
//name IF (relational operation) THEN
//…Steps..
// ELSE
//…Steps..
// ENDIF.
PROC PEND INCLUDE ‘/*’ ‘// ‘ ‘//*’ are executed irrespective of their place.
Don’t specify JOBLIB, JCLLIB, JOBCAT, STEPCAT, JOB, SYSCHK within the THEN or ELSE Scope of IF
statement.
Relational condition can be also coded as follows:
STEPNAME.ABEND=TRUE, STEPNAME.RUN=TRUE, STEPNAME NOT RUN
STEPNAME.ABENDCC = any-abend-code or
DD Statement
It defines the data requirements of the program. It is coded for every file used in the program. If
the employee details are stored in a file and catalogued with the name ‘SMSXL86.EMPLOYEE.DETAILS’,
one of the programs (EMPPGM) in the application reads this file, then JCL card for the DD looks like.
FOPEN(EMPFILE,mode) (C )
DSNAME(DSN)
The name of the dataset is coded in the DSN parameter. Dataset name can contain 44 characters
including the periods in between qualifier. Each qualifier can have 8 characters and there can be 22
qualifiers. But usually we don’t code more than 4 qualifiers.
DSN=XXXX.YYYY.ZZZZ,DISP=SHR
Temporary datasets are indicated by && in the DSN (DSN=&&temp).
If DSN is not specified, then the system assigns the specific name to dataset.
If DSN=NULLFILE or DUMMY is coded, then all the I/O s against this file are bypassed.
DISP
It is used to describe the status of a dataset to the system and instructs the system what to do
with that dataset after successful/unsuccessful termination of the step or job.
DISP=(current-status, normal-termination-status, abnormal-termination-status)
CATLG System is to place an entry, pointing to the dataset in the system/user catalog
DELETE Dataset is no longer required. Space available for use by another dataset but existing
dataset not physically erased until overwritten by another dataset.
PASS Dataset is passed to subsequent steps in the same job and each step can use the dataset
only once.
KEEP Dataset is to be kept on the volume
UNCATLG System is to delete the catalog entry corresponding to this dataset and keep this dataset.
Abnormal-termination-status:
PASS is not allowed. Meaning of CATLG, UNCATLG, KEEP, DELETE are same as normal-termination status.
Absence of any parameter should be mentioned with ‘,’ as they are positional parameters. Ex:
DISP=(,,CATLG). If the dataset is a new dataset and DISP is not coded, then the default in effect would be
DISP=(NEW,DELETE,DELETE).
RECFM
It specifies format of the dataset. It can be Fixed, Variable, Undefined, Fixed Blocked, variable
Blocked. (F, V, U, FB, VB). Other special record formats are VBS, FBS, VT, FT, FBA.
LRECL
It specifies logical record length. The length of the record is as in the program for fixed length
records, length of the longest record with four more bytes for variable length records.
Mainframe Refresher Part-1 Page:16
BLKSIZE
It contains physical record length. That is the length of the record in the storage medium. One
block contains one or more logical records. It is suggested to code BLKSIZE as 0 so that the best size is
chosen by the system, based on device.
If you explicitly code it, then it should multiple of LRECL for FB datasets and should not be less
than length of the longest records with eight more bytes for VB dataset. In the extra eight bytes, four
bytes are used for length of the record and four bytes are used for length of the block.
DSORG.
PS (Physical sequential) PO (Partitioned organization)
BUFNO.
The number of buffers to be allocated for the dataset is coded with BUFNO parameter.
Maximum of 255 buffers can be coded. The performance of sequential processing will increase if more
buffers are allocated. The default buffers are enough for most of the cases.
Source of DCB:
We don’t always have to write the DCB parameter for a dataset. Writing DCB parameter is one of
the three ways, the information can be supplied. The other two ways are:
1. Coded in the program. In COBOL, RECORD CONTAINS clause specifies the LRECL, BLOCK CONTAINS
clause specifies the BLKSIZE, RECORDING MODE clause specifies RECFM and RESERVE clause specifies
BUFNO. DSORG can be assumed from the name of the dataset and the directory space allocation of SPACE
parameter.
2. Usually for an existing dataset, we don’t have to code DCB parameters. It will be available in the dataset
label. The dataset label is STORED in the VTOC (DASD) or along with dataset (TAPE) during the dataset
creation.
LABEL
Syntax: LABEL = (Dataset-sequence-number
,label-type
,PASSWORD | NOPWREAD
,IN | OUT
,RETPD=nnn |EXPDT = (yyddd|yyyy/ddd))
Dataset Sequence number - identifies the relative position of a dataset on a tape/cart volume. Should be 1
through 4 decimal digits. Omit this parameter if access is being made to the first dataset on the tape
volume.
PASSWORD - indicates that a dataset cannot be read, changed, deleted or written to unless the correct
password is specified.
NOPWREAD - indicates that a dataset cannot be changed, deleted or written, unless the correct password
is specified. No password is necessary for reading the dataset.
Mainframe Refresher Part-1 Page:17
RETPD / EXPDT - indicates the retention period and the expiration date for a dataset.
st
Ex: LABEL=EXPDT=04121 (Dataset expires on 121 day of 2004)
LABEL=RETPD=200 (Dataset is retained for 200 days)
SPACE
It is used to request space for the new dataset. It is mandatory for all the NEW datasets.
Primary-qty - Specifies the amount of primary space required in terms of the space unit
(tracks/cylinders/number of data blocks). One volume must have enough space for the primary quantity.
If a particular volume is requested and it does not have enough space available for the request, the job
step is terminated.
Second-qty - Specifies the number of additional tracks, cylinders, blocks to be allocated, if additional
space is required.
Directory - Specifies the number of 256-byte records needed in the directory of a PDS. (In every block we
can store 5-6 members)
RLSE - requests that space allocated to an output dataset, but not used, is to be released when the
dataset is closed. Release occurs only if dataset is open for output and the last operation was a write.
CONTIG - requests that space allocated to the dataset must be contiguous. It affects only primary space
allocation.
MIXIG – It is used to specify that space requested should be allocated to the largest contiguous area of
space available on the volume. It affects only primary allocation.
ROUND - When the first parameter specifies the average block length, this parameter requests that
allocated space must be equal to an integral number of cylinders. Else ignored.
Extents
Extent is contiguous memory location. Only 16 extents are possible for a physical sequential
dataset in a volume. In loose terms, only 16 pointers can be stored for a PS dataset in one volume. For a
VSAM dataset it can be 123. In addition to this, the primary (first) or secondary (consecutive) space
request has to be met within 5 extents.
If any of the above is not met, then there will be space ABEND. So for a PS dataset, even though
you request 1600 tracks (using the space parameter (SPACE=TRKS,(100,100)), the system may not allocate
you 1600 tracks always.
If all the contiguous available spaces are of size 20 tracks, then 5 extents are used for satisfying
every primary or secondary. So 15 extents are used for providing just 300 tracks. If the system could find
th
any 100 tracks for the 16 extent, it would offer it and if not, there will be space ABEND. So in the best
case you will get 1600 tracks and in the worst case you will get 400 tracks for the space parameter
mentioned.
Mainframe Refresher Part-1 Page:18
Space ABENDS:
The most frequent ABEND in any production system is space abend.
SB37: End of volume. If the program tries to write more than the allocated space or if the system could
not find the requested primary or secondary space even by joining 5 extents, then the step abnormally
ends with SB37.
To solve this abend, increase the primary/secondary reasonably and if the job again comes down,
create the dataset as multi-volume by coding VOL=(,,,3). As every volume will offer 16 extents, 48 extents
in this case should be more than enough.
SD37: If the primary space is filled and the program tries to write more but no secondary is mentioned in
the SPACE parameter, then the step will come down with SD37.To solve this abend, provide secondary
allocation in the SPACE parameter.
SE37: End of Volume. This is same as SB37. You will get this ABEND usually for a partitioned dataset. To
solve this, compress the PDS by typing ‘Z’ in ISPF 3.4 panel against the dataset or use IEBGENER. If again
the job comes down, rename the old one, reallocate the new dataset with more space and copy the old
members to here and delete the renamed dataset and restart the job.
UNIT
It is used to request the system to place the dataset on a specific device/a certain type or group
of devices or the same device as another dataset.
UNIT=((device-number | device-type | group-name)
(,unit-count | P)
(,DEFER))
OR
UNIT=AFF=ddname
device-type - Requests a device by its IBM supplied generic name. (Eg. 3380)
group-name - Requests a group of devices by its symbolic name. Installation must have assigned the
name to the device(s) during system initialization.
The group-name is 1 through 8 alphanumeric characters (Eg. TEMPDA)
DEFER - Asks the system to assign the dataset to the device but requests that the volume(s) not be
mounted until the dataset is opened. DEFER is ignored for a new dataset on direct access.
AFF=ddname - Requests that system to allocate different datasets residing on different removable
volumes to the same device during step execution. The ddname is that of an earlier DD statement in the
same step. It reduces number of devices used in a job step.
VOLUME
A reel of TAPE or a disk pack is called as one volume. VOLUME parameter is used to identify the
volume(s) on which a dataset resides or will reside.
Mainframe Refresher Part-1 Page:19
VOLUME = ((PRIVATE)
(,RETAIN)
(,volume-sequence-number)
(,volume-count))
(SER=serial-number1,
serial number2......)
PRIVATE - Requests a private volume, that is exclusive use of volume for the dataset specified. Only one
job can access it at a time. TAPES are PRIVATE by default.
RETAIN - Requests that volume is not to be demounted or rewound after the dataset is closed or at the
end of this step. It is used when a following step is to use the same volume.
volume-count - Specifies the maximum number of volumes that an output dataset requires. (1-255)
SER=serial-number - Identifies by serial number the volume(s) on which the dataset resides or will reside.
1 through 6 alphanumeric or national(@,#,$) characters.
You can code a maximum of 255 volume serials.
Ex : VOLUME=SER=DEV001 VOL=(,,,3,SER=(PAGE01,PAGE02,PAGE03))
SYSOUT=class | *
It is used to identify this dataset as a system output dataset. The SYSOUT dataset is assigned to
an output class. The attributes for each class are defined during JES initialization, including device or
devices for the output class. ’*’ refer-backs to MSGCLASS character of JOB CARD.
In-stream data
The data passed in the JCL stream along with JCL statements is called in-stream data.
&&&& Meaning
* The data follows from the next line and ends when any // or /* appears at column 1& 2. So
‘//’ and ‘/*’ cannot be passed to the program.
//EMPFILE DD *
2052MUTHU
1099DEV
/*
DATA The data follows from the next line and ends when any /* appears at column 1 & 2. So ‘/*’
cannot be passed to the program.
//SYSUT1 DD DATA
Mainframe Refresher Part-1 Page:20
OTHER Statements
OUTLIM
It limits the number of print lines. The limit ranges from 1 to 16777215. The job is terminated
if the limit is reached.
//name DD SYSOUT=*,OUTLIM=3000
st
If the program tries to write 3001 line, JOB will ABEND with S722.
DEST
The DEST parameter is used in conjunction with the SYSOUT parameter where the output is to be
sent. This might be used where a job is run on several MVS systems and the output is directed to a single
system for the convenience of the end-user.
Syntax: //name DD SYSOUT=*,DEST=destination-ID
OUTPUT
OUTPUT statement is used to specify SYSOUT parameters for several DD statements with a single
JCL statement. It allows printing the output from single DD statement several times, each with different
SYSOUT parameters.
COPIES, OUTLIM, CLASS, DEST, FORMS, GROUPID can be coded in OUTPUT.
DEFAULT=Y can be coded on JOB and STEP level. STEP level default overrides JOBLEVEL default.
FORMS
Specify the type of forms on which the SYSOUT datasets should be printed.
It is 1-8 alphanumeric or national character. SYSOUT DD FORMS parameter overrides OUTPUT PARMS
parameter.
//name OUTPUT FORMS=form-name
Mainframe Refresher Part-1 Page:21
FREE
The datasets are allocated just before the execution of step and de-allocated after the execution
of step. FREE parameter de-allocates the file as soon as the file is closed. //ddname DD
SYSOUT=X,FREE=CLOSE
INCLUDE
The purpose of INCLUDE statement is same as COPY statement of COBOL program. This is used
to specify a PDS member that will be copied into the JCL at job submission time. It is used to specify a
standard list of DDNAMES, which would otherwise be duplicated in many similar PROCS. This also has the
advantage that amendments need only be made in one place. But it makes JCL unnecessarily fragmented
or difficult to read/maintain in a live environment.
// INCLUDE MEMBER1
MEMBER1 should exist in the procedure library. Procedure libraries are coded using
JCLLIB statement. Include must not be used to execute a PROC. It is possible to nest up to 15 levels of
INCLUDE statements.
Concatenation Rules
Concatenation allows naming of more than one dataset in a single input file without physically
combining them:
//STEPLIB DD DSN=PROD.LIBRARY,DISP=SHR
// DD DSN=TEST.LIBRARY,DISP=SHR
// DD DSN=USR.LIBRARY,DISP=SHR
REFERBACK
The backward reference or refer back permits you to obtain information from a previous JCL
statement in the job stream. STAR (*) is the refer-back operator.
It improves consistency and makes the coding easier.
DCB, DSN, VOL=SER, OUTPUT, PGM can be referred-back.
Refer-back example:
//STEP1 EXEC PGM=TRANS
//TRANFILE DD DSNAME=AR.TRANS.FILE,DISP=(NEW,KEEP),
// UNIT=SYSDA,VOL=SER=MPS800,
// SPACE=(CYL,(5,1)),
Mainframe Refresher Part-1 Page:22
// DCB=(DSORG=PS,RECFM=FB,LRECL=80)
//TRANERR DD DSNAME=AR.TRANS.ERR,DISP=(NEW,KEEP),
// UNIT=SYSDA,VOL=SER=MPS801,
// SPACE=(CYL,(2,1)),
// DCB=*.TRANFILE
//STEP2 EXEC PGM=TRANSEP
//TRANIN DD DSNAME=*.STEP1.TRANFILE,DISP=SHR
//TRANOUT DD DSNAME=AR.TRANS.A.FILE,DISP=(NEW,KEEP),
// UNIT=SYSDA,VOL=REF=*.STEP1.TRANFILE,
// SPACE=(CYL,(5,1)),
// DCB=*.STEP1.TRANFILE
.
//STEP5 EXEC PGM=*.STEP3.LOADMOD
Special DD names
STEPLIB
It follows EXEC statement. Load modules will be checked first in this library and then in the
system libraries. If it is not found in both places, then the JOB would ABEND with S806 code.
JOBLIB
It follows the job statement. Load modules of any steps (EXEC) that don’t have respective
STEPLIB will be looked into this PDS. If not found, it will be checked against system libraries. If it is not
found there also, then the JOB would ABEND with S806.
JCLLIB
It follows JOB statement. Catalogued procedures in the JOB are searched in this PDS. If they are
not found, they will be checked in system procedure libraries.
If they are not there, then there will be JCLERROR with ‘Proc not found’ message.
Syntax: //PROCLIB JCLLIB ORDER(PDS1,PDS2)
INCLUDE members are also kept in procedure libraries. (JCLLIB)
ABEND DATASETS
In case of ABEND, one of the following three datasets will be useful. If more than one of the
three datasets is coded, then the last coded DD will be effective.
SYSUDUMP
Prints the program area, contents of registers, and gives a trace back of subroutines called. It will
be in hexadecimal format.
SYSABEND
Same as SYSUDUMP, but also prints the system nucleus. Don't use unless you need the nucleus.
It will be in hexadecimal format.
SYSMDUMP
Same information as SYSABEND, but dump will be in machine language.
Used to store dumps in a data set to be processed by an application program.
SYSIN
In-stream data can be coded in SYSIN DD *. Using ACCEPT statement, these records are read into
the program. Every accept will read one line into working storage (80 column).
Mainframe Refresher Part-1 Page:23
Procedures
Set of Job control statements that are frequently used are defined separately as a procedure and
it can be invoked as many times as we need from the job. The use of procedures helps in minimizing
duplication of code and probability of error.
If a procedure is defined in the same job stream, then it is called In-stream procedure. They are
coded before the first EXEC statement in the job. The definition starts with PROC statement and ends with
PEND. Instead procedures can be saved in a PDS and invoked from job and they are called as catalogued
procedures. One procedure can call other. This is called nesting and nesting is possible up to 15 levels.
Procedure Modification
Procedure should be generic so that it can easily be used by the multiple JOBS by simple
overrides. During the invoking of procedures in the JOB, one can do the following.
1. Override: Change the dataset names or parameters that are already coded in the procedure
2. Addition: Add new datasets or parameters in the already existing steps of the procedure.
3. Nullify: Omit the datasets or parameters that are already coded in procedure.
When you override a cataloged procedure, the override applies just to that execution of the job. The
cataloged procedure itself isn't changed.
Other Rules:
1. Multiple overrides are allowed but they should follow the order. That is first you should override the
parameters of step1, then step2 and then step3. Any overrides in the wrong order are IGNORED.
2. If the STEPNAME is not coded during override, then the system applies the override to first step alone.
//EXEC COBCLG,REGION=512K
Mainframe Refresher Part-1 Page:24
1. DD statement overrides should be done in the same order they appear in procedure. Within a DD
statement, the order of parameters does not matter.
2.Any additions should follow modifications. In a step, if you want to override the dataset attribute of one
existing dataset and add another dataset, you should override the old one before adding the new one.
3. To omit a parameter from a DD statement in a procedure, just name it but don’t pass any value for it.
Ex: If you want to override UNIT Parameter value of all the DD statements, define this as symbolic
parameter in proc.
//STEP1 EXEC PROC1,UNIT=TEMPDA will set &UNIT as TEMPDA for this run of procedure.
Procedure Example
SMSXL86.TEST.PROCLIB(EMPPROC)
//EMPPROC PROC CLASS='*',SPACE='1,1' Default values defined for CLASS
//STEP1A EXEC PGM=EMPPGM and SPACE symbolic parameters.
//SYSOUT DD SYSOUT=&CLASS
//EMPMAST DD DSN=&HLQ..EMPLOYEE.EDS,DISP=SHR
// DD DSN=&HLQ..EMPLOYEE.IMR,DISP=SHR
// DD DSN=&HLQ..EMPLOYEE.VZ,DISP=SHR
Mainframe Refresher Part-1 Page:25
SMSXL86.TEST.JCLLIB(EMPJCL)
//EMPJCLA JOB (1000,200),CLASS=A,MSGCLASS=Q,NOTIFY=&SYSUID
//PROCLIB JCLLIB ORDER=(SMSXL86.TEST.PROCLIB)
// SET SPACE=‘1,1’ Value is given for symbolic parameter SPACE.
//*STEP1A PARM is added and value for symbolic parameter HLQ is supplied.
//STEP01 EXEC EMPPROC,PARM.STEP1A=’02/11/1979’,HLQ=PROD
//STEP1A.EMPMAST DD
// DD DSN=PROD.EMPLOYEE.CTS,DISP=SHR
//*Instead of PROD.EMPLOYEE.IMR, PROD.EMPLOYEE.TCS dataset is used whereas
//*other two datasets PROD.EMPLOYEE.EDS and PROD.EMPLOYEE.VZ retains their
//*position in concatenation.
//STEP1A.EMPOUT DD UNIT=TEMPDA
//*UNIT parameter of EMPOUT file is modified
//STEP1A.EMPCNTL DD *
DESIG=SSE
/*
//*EMPCNTL control card value is passed.
//STEP1A.EMPOUT2 DD DSN=PROD.EMPLOYEE.CONCAT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(10,10))
//*EMPOUT2 file is added to the step STEP1A.
In the above example, CLASS retains the default value coded on the PROC definition
Statement (CLASS='*').
IEBCOPY
It is used to copy one or more members from an existing dataset to a new or existing PDS data
set. It can be also used for compressing PDS, Loading PDS to TAPE and unloading from TAPE to disk. This
utility needs two work files SYSUT3 and SYSUT4 in addition to SYSIN and SYSPRINT.
FIELD Meaning
COPY Function is COPY
SELECT Specifies the members to be copied/replaced
Syntax: (NAME-IN-OUTPUT,NAME-IN-OUTPUT,REPLACE-IF-EXISTS)
EXCLUDE Specifies the members to be excluded from copy
LIST=YES Displays the copied members in the SYSPRINT.
INDD Points to input dataset
OUTDD Points to output dataset. Should exist on the same line of COPY.
IEBGENER
In addition to SYSIN and SYSPRINT datasets, it needs SYSUT1 and SYSUT2 datasets. SYSUT1 is
coded with input dataset and SYSUT2 is coded with output dataset. If attributes were not given for
SYSUT2, then the program would assume SYSUT1 attributes for SYSUT2.
It is primarily used as COPY utility. If you want to copy any TAPE file to DISK or DISK to TAPE, then
no SYSIN is needed.
If you want to reformat your input file or if you want to create members out of your PS file, then
you need control card (SYSIN) and the first statement should be GENERATE.
FIELD Meaning
GENERATE First Statement which sets the values for MAXNAME,MAXGPS, MAXLITS, MAXFLDS
MAXNAME Maximum MEMBER statements that can follow.(During member generation)
Syntax: MAXNAME=3
MAXGPS Maximum IDENT statement that can follow. (During member generation)
MAXFLD Maximum FILED statements that can follow. (During reformatting)
Syntax: MAXFLDS=10
MAXLITS Maximum size of literal during reformatting.
MEMBER It identifies the name of the member to be created.
Syntax: MEMBER NAME=MEM1
RECORD It usually follows MEMBER statement to identify the last record to be copied from the
IDENT input dataset.
RECORD IDENT= (Length,’Literal’,Start-Column)
Example: RECORD IDENT=(3,’MVS’,1), then the last record to be copied into the
member from the input dataset, has MVS in column 1-3.
RECORD It is used for reformatting the records in the input file.
FIELD RECORD FIELD=(Length, ’literal’ or input column, conversion, output column)
Mainframe Refresher Part-1 Page:27
Output column says where the field should be placed in the output file. Conversion
can be ZP or PZ. PZ means the input packed decimal field is being converted into
zoned format and ZP is the reverse.
IEBGENER- SYSIN CARD FOR CREATING THREE MEMBERS FROM INPUT PS FILE
//SYSIN DD *
GENERATE MAXNAME=3,MAXGPS=2
MEMBER NAME= MEMB1
RECORD IDENT=(8,'11111111'.1)
MEMBER NAME=MEMB2
RECORD IDENT=(8,'22222222',1)
MEMBER NAME=MEMB3
//
IEBGENER creates three members. It reads input file writes into memb1 until it finds 11111111 in column
1. In the same way it reads and writes the records into memb2 until it finds 22222222 in column 1. The
remaining records in the input dataset are copied into MEMB3.
IEHLIST
It is used to list
1. The entries in the catalog. (SYSIN KEYWORD- LISTCTLG)
2. Directory(s) of 1-10 PDS (SYSIN KEYWORD- LISTPDS)
3. The entries in VTOC. (SYSIN KEYWORD-LISTVTOC)
Code SYSIN, SYSPRINT and one more DD that will mount the volume queried in SYSIN.
IEHMOVE
It is used to move one dataset from one volume to another volume.
IEBCOMPR
It is used to compare two PS or PDS datasets. Two PS are same, if the number of records is same
and all the records are identical. SYSIN is not needed for PS comparison. If they are not identical, then the
following will be listed in the SYSPRINT.
DD statements that define the dataset, Record and Block numbers, the unequal records and
maximum of 10 unequal records found.
Two PDS are same, if the corresponding members contain same number of records and all the
records are identical. SYSIN should have COMPARE TYPE=PO for PDS.
//SYSUT1 INPUT DATASET 1
//SYSUT2 INPUT DATASET 2
//SYSPRINT
//SYSIN DD *
IEBBTPCH
IEBEDIT:
One typical interview question is how to run the selected steps. For example, how to execute step4 and
step9 of 10 steps JCL. The typical answer is to restart the job from step4 and include a ‘ALWAYS TRUE’
condition (like COND=(0,LE) or COND=(4096,GT)) in steps 5,6,7,8 and 10. If the interviewer said COND
should not used, then only way is IEBEDIT.
In the above JCL, JCLINP is the 10 steps JCL. M665235C is the job-name in the JCL.
Mainframe Refresher Part-1 Page:29
DFSORT
If you do a global search of your JCL inventory, you will find the program that is used very
frequently is SORT. There are two famous SORT products are available in the market. One is DFSORT and
the other is SYNCSORT. The basic commands in both the products are same.
ICETOOL provides a lot more than what SORT can offer and it comes with DFSORT product.
SYNCTOOL comes with SYNCSORT product. PGM=SORT can point to DFSORT or SYNCSORT. It is actually an
alias to SORT product in your installation.
DFSORT is IBM product and it needs the following datasets for its operation.
SORTIN (Input dataset), SORTOUT (Output dataset), SYSIN (Control Card) and SYSOUT (Message dataset).
Message dataset can be altered using MSGDDN= parameter of SYSIN.
SORT card to skip first 100 records and then copy 20 records
SORT FIELDS=COPY SKIPREC=100 STOPAFT=20
SORT card to create multiple files from single input file (Maximum 32 files)
OUTFIL FILES=1 INCLUDE=(1,6,CH,EQ,C’MUMBAI’)
OUTFIL FILES=2 INCLUDE=(1,6,CH,EQ,C’TRICHY’)
Code output files as SORTOF1 and SORTOF2.
OPTION COPY
INCLUDE FORMAT=SS,COND=(1,81,EQ,C'EXEC',AND,1,81,NE,C'PGM=)
ICETOOL
DD statements in ICETOOL:
TOOLMSG FOR ICETOOL MESSAGES
DFSMSG FOR SORT MESSAGES
TOOLIN FOR ICETOOL-CONTROL-CARD
XXXXCNTL FOR SORT-CONTROL-CARD USED BY ICETOOL
XXXX is coded in USING clause of TOOLIN.
TOOLIN Card to get all the values for a particular field – With Occurrence constraint
OCCURS FROM(INDD) ON(STARTPOS,LENGTH,TYPE) LIST(LISTDD) OPTION
OPTION = > HIGHER(n) LOWER(n) EQUAL(n) ALLDUPS NODUPS
HIGHER(2) means only the values that are repeated more than 2 times is reported at LISTDD dataset.
TOOLIN Card to get number of records fell into the range mentioned
RANGE FROM(INDD) ON(START,LENGTH,FORMAT) LIST(OUTDD) options
//IN2 DD *
3456789012
7890123456
8901234567
//T1 DD DSN=&T1,SPACE=(CYL,(5,5),RLSE),DISP=(,PASS)
//T2 DD DSN=&T2,SPACE=(CYL,(5,5),RLSE),DISP=(,PASS)
//INT DD DSN=*.T1,DISP=(OLD,PASS),VOL=REF=*.T1
// DD DSN=*.T2,DISP=(OLD,PASS),VOL=REF=*.T2
//FILEA DD SYSOUT=*
//FILEB DD SYSOUT=*
//OUT DD SYSOUT=*
//TOOLIN DD *
SORT FROM(IN1) USING(CTL1)
SORT FROM(IN2) USING(CTL2)
SORT FROM(INT) USING(CTL3)
//CTL1CNTL DD *
SORT FIELDS=(1,10,CH,A)
OUTFIL FNAMES=T1,OUTREC=(1,80,C'1')
//CTL2CNTL DD *
SORT FIELDS=(1,10,CH,A)
OUTFIL FNAMES=T2,OUTREC=(1,80,C'2')
//CTL3CNTL DD *
SORT FIELDS=(1,10,CH,A)
SUM FIELDS=(81,1,ZD)
OUTFIL FNAMES=OUT,INCLUDE=(81,1,ZD,EQ,3),OUTREC=(1,80)
OUTFIL FNAMES=FILEA,INCLUDE=(81,1,CH,EQ,C'1'),OUTREC=(1,80)
OUTFIL FNAMES=FILEB,INCLUDE=(81,1,CH,EQ,C'2'),OUTREC=(1,80)
/*
Explanation:
th
CTL1 – Add 1 to all the records of the first file at 80 column
th
CTL2 – Add 2 to all the records of the second file at 80 column
st
CTL3 – Concatenate both files and sort the file on key if duplicates found, sum on 81 column. So if any
record exists in both the file, it will have 3 after summing.
st
So now extract records with ‘1’ , ‘2’ and ‘3’ into three files. While writing the records, remove the 81
byte added for our temporary purpose.
‘1’ – Records only in first file
‘2’ – Records only in second file.
‘3’ – Records exist in both the files.
IEHPROGM
It is used to
1.Catalog a dataset (CATLG DSNAME=A.B.C, VOL=SER=nnnn)
2.Uncatalog a dataset (UNCATLG DSNAME=A.B.C)
3.Rename a dataset (RENAME DSNAME=A.B.C,VOL=SER=nnnn,NEWNAME=D.E.F)
4.Create an index for GDG (BLDG INDEX=gdg-name, LIMIT=n, [,EMPTY][,DELETE])
5.Deleting the index for GDG (DLTX INDEX=index-name)
The SYSIN cards are given in bracket. The utility needs two work datasets and SYSPRINT for
nd
messages. Continuation of control card needs to be indicated by ‘X’ in 72 column.
If your shop installed SMS, then uncatalog wont work it out because SMS handles the catalog.
IEHINITT
It is used to initialize a tape. It will write the volume serial number to the tape.
Mainframe Refresher Part-1 Page:33
If the GDG Base is MM01.PAYROLL.MASTER, then their generations are identified using the
generic name “MM01.PAYROLL.MASTER.GnnnnVxx.”
nnnn is generation number (01-9999) and xx is version number (00-99).
GENERATIONS ARE UPDATED ONLY AT THE END OF THE JOB. It means, if the
first step creates one generation, code it as GDGBASE(+1) and if the second step creates another
generation, then it SHOULD be coded as GDGBASE(+2) as the (+1) version is not yet promoted to current
version. Similarly to refer the GDG created in the second step, refer it by GDGBASE(+2).
GDG datasets can be also referenced with their generation number like
‘MM01.PAYROLL.MASTER.G001V00’
Advantage of GDG
1. GDG datasets are referred in the JCL using GDG base and relative number. So the same JCL can be used
again and again without changing the dataset name and this is the biggest advantage of GDG.
2.GDG Base has pointers to all its generations. When you want to read all the transactions done till today,
you can easily do it by reading the GDG base if it is available. Otherwise you have to concatenate all the
transaction files before reading.
Creation of GDG
1.GDG Base is created using IDCAMS. The parameters given while creating the GDG are:
Parameter Purpose
NAME Base of the GDG is given here.
LIMIT The maximum number of GDG version that can exist at any point of time. It is a
number and should be less than 256.
EMPTY/NOEMPTY When the LIMIT is exceeded,
EMPTY keeps ONLY the most recent generation.
NOEMPTY keeps the LIMIT number of newest generation.
SCRATCH/ SCRATCH un-catalogue and deletes the versions that are not kept.
NOSCRATCH NOSCRATCH just does un-cataloguing and it is not physically deleted from the
volume.
OWNER Owner of the GDG.
FOR DAYS (n) / Expiry date. Can be coded either in the unit of days or till particular date.
TO (DATE)
Mainframe Refresher Part-1 Page:34
2. Model dataset is defined after or along with the creation of base. Once model DCB is defined, then
during the allocation of new versions, we no need to code DCB parameter. Model DCB parameter can be
overridden by coding new parameter while creating the GDG version. It is worth to note that two GDG
version can exist in two different formats.
1.Refer the SYSOUT of the job and get the next sequential instruction to be executed (Offset).
2.Compile the program with LIST option if the compiled one is not with either LIST or OFFSET option.
3.Check for the offset in the compilation list and Get the respective statement number.
4.Identify the statement. This would be a numeric operation on non-numeric data.
Mainframe Refresher Part-1 Page:35
Though the process looks simple and this will work 90 percent of the cases, the questions are:
In case offset and the abending module is not displayed in the sysout, how to proceed?
In case of data-exception kind of abend, if the particular statement referred more than one field,
how do you conclude which field have problem without display and rerun?
If the source for the field in problem is in file, how do you know which record of this field in the
file?
Dump Reading exposure will help you in all these cases. As dump reading knowledge is important for any
maintenance / support project, let us study with a simple example:
Simple Program
CBL LIST
IDENTIFICATION DIVISION.
PROGRAM-ID.SANSOFT.
*
ENVIRONMENT DIVISION.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 WS-EMP-NAME PIC X(10).
05 WS-EMP-AGE PIC 9(02).
05 WS-EMP-CITY PIC X(10).
05 WS-EMP-SAL PIC S9(08).
05 WS-EMP-BONUS PIC S9(08).
05 WS-EMP-CTC PIC S9(08).
*
PROCEDURE DIVISION.
*
MOVE 'MUTHU' TO WS-EMP-NAME
MOVE 29 TO WS-EMP-AGE
MOVE 'TRICHY' TO WS-EMP-CITY
MOVE 60000 TO WS-EMP-SAL
COMPUTE WS-EMP-CTC = (WS-EMP-SAL * 12) + WS-EMP-BONUS
DISPLAY 'SANSOFT COMPLETED'
DISPLAY 'EMPLOYEE DETAIL:' WS-EMP-NAME ','
WS-EMP-AGE ','
WS-EMP-CITY ','
WS-EMP-SAL ','
WS-EMP-CTC
STOP RUN.
From compile unit SANSOFT at entry point SANSOFT at compile unit offset +0000036A at entry offset
+0000036A
at address 2790117A.
The instruction at the Offset 36A is failed. So look into the compilation listing for the statement that is in
the offset 36A.
000021 MOVE
000358 D207 2016 A0BD MVC 22(8,2),189(10) (BLW=0)+22 PGMLIT AT +185
000022 COMPUTE
00035E F247 D0F8 201E PACK 248(5,13),30(8,2) TS2=0 WS-EMP-BONUS
000364 D20F D0E8 A08D MVC 232(16,13),141(10) TS1=0 PGMLIT AT +137
00036A FA54 D0F2 D0F8 AP 242(6,13),248(5,13) TS1=10 TS2=0
000370 940F D0F3 NI 243(13),X'0F' TS1=11
000374 F844 D0F3 D0F3 ZAP 243(5,13),243(5,13) TS1=11 TS1=11
00037A F374 2026 D0F3 UNPK 38(8,2),243(5,13) WS-EMP-CTC TS1=11
000023 DISPLAY
So one of this field referred in this statement has junk in it. Just before compute we populated WS-EMP-
SAL and so there is a problem with WS-EMP-BONUS. If you go thru the code, you will find the developer
missed to populate/initialize WS-EMP-BONUS and that has caused data exception.
If these fields are from file, we cannot easily confirm like above. So we have to give display for these two
fields in the program and rerun the program or look for junks in the source file for these two fields using
FILE AID/ INSYNC. The other approach will be look into data division map in the compilation listing.
In the dump, look for working-storage dump. BLW-0 maps to 279890B8 address.
In the dump, in every line there will be twenty bytes hexa decimal content will be followed by
character content. Due to the column limit, I have the one line dump in three lines.
So if there are million records in a file and during the processing it abended after ‘n’ number of
records, to identify the record caused problem, read the dump for the file section unique variable(s)
values and look for the respective record in the file and analyse/correct/delete.
We have taken offset directly from sysout. If it is not available, then refer the PSW. Based on
AMODE 24/31, the last 24/31 bits contain the next sequential instruction to be executed. From this value,
subtract the entry point of the program being abended and that will give you offset. One instruction
above this offset is the one that caused the abend. Entry point of all the programs executed be found in
trace back or save trace section of the dump. You can directly found the offset in the traceback also. (last
31 bits of A7901180 is 27901180, 27901180-27900E10 = 370 is the offset, from the compilation listing
one instruction just before 370 is 36A.)
Traceback:
PROGRAM:MAINPGM
SELECT JCLFILE ASSIGN TO JCLDD…. (Environment Division)
FD JCLFILE.
01 JCL-REC PIC X(80). (File Section)
OPEN OUTPUT JCLFILE. (Open in output and write JCL statements)
MOVE '//TESTJOB JOB 1111' TO JCL-REC.
MOVE '//STEP01 EXEC PGM=IEFBR14' TO JCL- REC
CLOSE JCLFILE (TESTJOB will be submitted automatically)
Mainframe Refresher Part-1 Page:38
The following data classes establish various default values for catalogued datasets. An
administrator assigns a name to each group of default values, and then you reference this name on your
DD statements to use the values.
If you want to override any one of the values of default, you can do that.
//PDS DD DSN=BPMAIN.MUTHU.SOURCE,DISP=(NEW,CATLG),
// STORCLAS=DASDONE,SPACE=(,(,,50)),DATACLAS=COB2
Overrides the directory space defined for COB2 data class.
To load the complete log (JOB PRODBKUP of generation 4941) into a dataset named as LOADDD,
use the following card:
/LOAD DDNAME=LOADDD ID=PRODBKUP GEN=4941
To get run-date, run-time, return code and generation of all the prior runs of a job, use the
following card. The result will be stored in the dataset named as REPORT.
/LIST ID=JOBNAME
//UCC7CMDS DD DISP=SHR,DSN=CAI.CA7.COMMDS
//SYSPRINT DD SYSOUT=*,DCB=BLKSIZE=133
//ERRORS DD SYSOUT=*,DCB=BLKSIZE=133
//SYSUDUMP DD SYSOUT=*
//SYSIN DD*
Code the CA7 commands
/*
COBOL
Mainframe Refresher Part-1 Page:41
History.
Developed in 1959 by a group called COnference on DAta Systems Language (CODASYL). First
COBOL compiler was released in 1960.
Speciality.
1. First language developed for commercial application development, which can efficiently handle
millions of data.
2. Procedure Oriented Language - Problem is segmented into several tasks. Each task is written
as a Paragraph in Procedure Division and executed in a logical sequence as mentioned.
3. English Like language – Easy to learn, code and maintain.
Coding Sheet.
1 7 12 72 80
COL-A COLUMN-B
Language Structure.
Divisions in COBOL.
There are four divisions in a COBOL program and the data division is an optional one.
1.Identification Division.
2.Environment Division.
3.Data Division.
4.Procedure Division.
Identification Division.
This is the first division and the program is identified here. Paragraph PROGRAM-ID followed by user-
defined name is mandatory. Though 30 characters can be entered for the program ID, compiler will
consider only the first EIGHT characters and the remaining characters will be ignored. All other paragraphs
are optional and used for documentation.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM NAME.
AUTHOR. COMMENT ENTRY.
INSTALLATION. COMMENT ENTRY.
DATE-WRITTEN. COMMENT ENTRY.
DATE-COMPILED. COMMENT ENTRY.
SECURITY. COMMENT ENTRY.
Security does not pertain to the operating system security, but the information that is passed to
the user of the program about the security features of the program.
Environment Division.
This is the only machine dependant division of COBOL program. It supplies information about the
hardware or computer equipment to be used on the program. When a program is moved from one
computer to another computer, the only section that may need to be changed is ENVIRONMENT division.
Configuration Section.
It supplies information about the computer on which the program will be compiled (SOURCE-COMPUTER)
and executed (OBJECT-COMPUTER). It consists of three paragraphs – SOURCE COMPUTER, OBJECT-
COMPUTER and SPECIAL-NAMES.
This is OPTIONAL section from COBOL 85.
SPECIAL-NAMES. This paragraph is used to relate hardware names to user-specified mnemonic names.
1. Substitute character for currency sign. (CURRENCY SIGN IS litearal-1)
2. Comma can be used as decimal point. (DECIMAL-POINT IS COMMA)
3. Default collating sequence can be changed. It will be explained later.
4. New class can be defined using CLASS keyword. (CLASS DIGIT is “0” thru “9”)
Input-Output Section.
It contains information regarding the files to be used in the program and
consists of two paragraphs FILE-CONTROL & I-O CONTROL.
Mainframe Refresher Part-1 Page:43
FILE CONTROL. Files used in the program are identified in this paragraph.
I-O CONTROL. It specifies when check points to be taken and storage areas that are shared by different
files.
Data Division.
Data division is used to define the data that need to be accessed by the program.
It has three sections.
FILE SECTION describes the record structure of the files.
WORKING-STORAGE SECTION is used to for define intermediate variables.
LINKAGE SECTION is used to access the external data.
Ex: Data passed from other programs or from PARM of JCL.
Declaration of variable
Level# $ Variable $ Picture clause $ Usage Clause $ Sync clause $ Value clause.
FILLER
Level#
It specifies the hierarchy of data within a record. It can take a value from the set of integers
between 01-49 or from one of the special level-numbers 66 77 88
FILLER
When the program is not intended to use selected fields in a record structure, define them as FILLER.
FILLER items cannot be initialized or used in any operation of the procedure division.
Mainframe Refresher Part-1 Page:44
PICTURE Clause
Describes the attributes of variable.
Numeric 9 (Digit), V (Implied decimal point), S (Sign), P(Assumed decimal point when the
point lies outside the data item)
Numeric Edited + (Plus Sign), - (Minus Sign), CR DB (Credit Debit Sign)
. (Period), b (Blank), ‘,’(comma), 0 (Zero), / (Slash)
BLANK WHEN ZERO (Insert blank when data value is 0),
Z (ZERO suppression), * (ASTERISK), $(Currency Sign)
Non Numeric A (alphabet), B (Blank insertion Character), X(Alpha numeric), G(DBCS)
Exclusive sets 1. + - CR DB
2. V ‘.’
3. $ + - Z * (But $ Can appear as first place and * as floating. $***.**)
DBCS (Double Byte Character Set) is used in the applications that support large character sets. 16 bits are
used for one character. Ex: Japanese language applications.
VALUE Clause
It is used for initializing data items in the working storage section. Value of item must not exceed picture
size. It cannot be specified for the items whose size is variable.
Syntax: VALUE IS literal.
VALUES ARE literal-1 THRU | THROUGH literal-2
VALUES ARE literal-1, literal-2
Literal can be numeric without quotes OR non-numeric within quotes OR figurative constant.
SIGN Clause
Syntax SIGN IS (LEADING) SEPARATE CHARACTER (TRAILING).
It is applicable when the picture string contain ‘S’. Default is TRAILING WITH NO SEPARATE CHARACTER.
So ‘S’ doesn’t take any space. It is stored along with last digit.
Refreshing Basics
Nibble. 04 Bits is one nibble. In packed decimal, each nibble stores one digit.
Byte. 08 Bits is one byte. By default, every character is stored in one byte.
Half word. 16 Bits or 2 bytes is one half word. (MVS)
Full word. 32 Bits or 4 bytes is one full word. (MVS)
Double word. 64 Bits or 8 bytes is one double word. (MVS)
Usage Clause
DISPLAY Default. Number of bytes required equals to the size of the data item.
COMP Binary representation of data item.
PIC clause can contain S and 9 only.
S9(01) – S9(04) Half word.
S9(05) – S9(09) Full word.
S9(10) - S9(18) Double word.
Most significant bit is ON if the number is negative.
COMP-1: Single word floating point item. PIC Clause should not be specified.
The sign is contained in the first bit of the of the leftmost byte and the
exponent is contained in the remaining 7 bits of the first byte. The last
3 bytes contain the mantissa.
COMP-2: Double word floating-point item. PIC Clause should not be specified.
7 bytes are used for mantissa and hence used for high precision
calculation.
COMP-3: Packed Decimal representation. One digit takes half byte.
PIC 9 (N) comp-3 data item would require (N + 1)/2 bytes. The sign is stored separately
in the rightmost half-byte regardless of whether S is specified in the PICTURE or not.
C – Signed Positive D – Signed Negative F-Unsigned Positive.
INDEX It is used for preserve the index value of an array. It takes 4 bytes.
PIC Clause should not be specified. When the clause is specified for a group item, it
applies to all elementary items contained in it. However, the group itself is not an index
data item.
POINTER4 Byte elementary item that can be used to accomplish limited base
addressing. It can be used only in – SET statement, Relation condition,
USING phrase of a CALL statement, an ENTRY statement or the
procedure division statement. A value clause for a pointer data item
can contain only NULL or NULLS.
The Starting address of Full-word should end with 0,4,8 or C and that of half-word should end with
0,2,4,6,8,A,C,E. If DATA-ONE starts at 0, it will occupy 0-5 bytes in memory. DATA-TWO - a sync item of
th th th
full word cannot start at 6. So by SYNC rule, it starts at 8 position. 6 & 7 bytes are unused. So MY-
DATA occupies 16 bytes.
REDEFINES
The REDEFINES clause allows you to use different data description entries to describe the same computer
storage area. Redefining declaration should immediately follow the redefined item and should be done at
the same level. Multiple redefinitions are possible. Size of redefined and redefining need not be the same.
It cannot be done at 66 and 88 levels.
Example:
01 WS-DATE PIC 9(06).
01 WS-REDEF-DATE REDEFINES WS-DATE.
05 WS-YEAR PIC 9(02).
05 WS-MON PIC 9(02).
05 WS-DAY PIC 9(02).
RENAMES
It is used for regrouping of elementary data items in a record. It should be declared at 66 level. It need not
immediately follows the data item, which is being renamed. But all RENAMES entries associated with one
logical record must immediately follow that record's last data description entry. RENAMES cannot be
done for a 01, 77, 88 or another 66 entry. It cannot be done for occurrences of an array.
01 WS-REPSONSE.
05 WS-CHAR143 PIC X(03).
05 WS-CHAR4 PIC X(04).
66 ADD-REPSONSE RENAMES WS-CHAR143.
CONDITION name
It is identified with special level ‘88’. A condition name specifies the value that a field can contain and
used as abbreviation in condition checking.
01 SEX PIC X.
88 MALE VALUE ‘1’
88 FEMALE VALUE ‘2’ ‘3’.
IF SEX=1 can also be verified as IF MALE in Procedure division.
‘SET FEMALE TO TRUE ‘ moves value 2 to SEX. If multiple values are coded on VALUE clause, the
first value will be moved when it is set to true.
JUSTIFIED RIGHT
This clause can be specified with alphanumeric and alphabetic items for right justification. It
cannot be used with 66 and 88 level items.
Mainframe Refresher Part-1 Page:47
OCCURS Clause
OCCURS Clause is used to allocate physically contiguous memory locations to store the table
values and access them with subscript or index. Detail explanation is given in Table Handling section.
LINKAGE SECTION
It is used to access the data that are external to the program. JCL can send maximum 100
characters to a program thru PARM. Linkage section MUST be coded with a half word binary field, prior to
actual field. If length field is not coded, the first two bytes of the field coded in the linkage section will be
filled with length and so there will be last 2 bytes data truncation in the actual field.
01 LK-DATA.
05 LK-LENGTH PIC S9(04) COMP.
05 LK-VARIABLE PIC X(08).
LINKAGE section of sub-programs will be explained later.
Procedure Division.
This is the last division and business logic is coded here. It has user-defined sections and paragraphs.
Section name should be unique within the program and paragraph name should be unique within the
section.
Mainframe Refresher Part-1 Page:48
MOVE Statement
It is used to transfer data between internal storage areas defined in either file section or working storage
section.
Syntax:
MOVE identifier1/literal1/figurative-constant TO identifier2 (identifier3)
Multiple move statements can be separated using comma, semicolons, blanks or the keyword THEN.
ARITHMETIC VERBS
All the possible arithmetic operations in COBOL using ADD, SUBTRACT, MULTIPLY and DIVIDE are
given below:
Arithmetic Operation A B C D
ADD A TO B A A+B
ADD A B C TO D A B C A+B+C+D
ADD A B C GIVING D A B C A+B+C
ADD A TO B C A A+B A+C
SUBTRACT A FROM B A B-A
SUBTRACT A B FROM C A B C-(A+B)
SUBTRACT A B FROM C A B C C-(A+B)
GIVING D
MULTIPLY A BY B A A*B
MULTIPLY A BY B GIVING C A B A*B
DIVIDE A INTO B A B/A
DIVIDE A INTO B GIVING C A B B/A
DIVIDE A BY B GIVING C A B A/B
DIVIDE A INTO B GIVING C A B Integer (B/A) Integer remainder
REMAINDER D
ROUNDED option
With ROUNDED option, the computer will always round the result to the PICTURE clause
specification of the receiving field. It is usually coded after the field to be rounded. It is prefixed with
REMAINDER keyword ONLY in DIVIDE operation.
ADD A B GIVING C ROUNDED.
DIVIDE..ROUNDED REMAINDER
Caution: Don’t use for intermediate computation.
ON SIZE ERROR
If A=20 (PIC 9(02)) and B=90 (PIC 9(02)), ADD A TO B will result 10 in B where the expected value
in B is 110. ON SIZE ERROR clause is coded to trap such size errors in arithmetic operation.
If this is coded with arithmetic statement, any operation that ended with SIZE error will not be
carried out but the statement follows ON SIZE ERROR will be executed.
Mainframe Refresher Part-1 Page:50
COMPUTE
COMPUTE statement assigns the value of an arithmetic operation (on the right hand side) to a
data item (on the left hand side).
Rule: Left to right – 1.Parentheses (‘(‘ ‘)’)
2.Exponentiation (**)
3.Multiplication and Division (* and /)
4.Addition and Subtraction (+ and -)
Caution: When ROUNDED is coded with COMPUTE, some compiler will do rounding for every arithmetic
operation and so the final result would not be precise.
All arithmetic operators have their own explicit scope terminators. (END-ADD, END-SUBTRACT,
END-MULTIPLY, END-DIVIDE, END-COMPUTE). It is suggested to use them.
CORRESPONDING is available for ADD and SUBTRACT only.
INITIALIZE
VALUE clause is used to initialize the data items in the working storage section whereas
INITIALIZE is used to initialize the data items in the procedure division.
INITIALIZE sets the alphabetic, alphanumeric and alphanumeric-edited items to SPACES and
numeric and numeric-edited items to ZERO. This can be overridden by REPLACING option of INITIALIZE.
FILLER, OCCURS DEPENDING ON items are not affected.
Syntax: INITIALIZE identifier-1
REPLACING (ALPHABETIC/ALPHANUMERIC/ALPHA-NUMERIC-EDITED
NUMERIC/NUMERIC-EDITED)
DATA BY (identifier-2 /Literal-2)
Example: 01 A.
05 A1 PIC 9(5).
05 A2 PIC X(4).
INITIALIZE A REPLACING NUMERIC DATA BY 50. will initialize only A1 by 50.
ACCEPT
ACCEPT can transfer data from input device or system information contain in the reserved data
items like DATE, TIME, DAY.
ACCEPT WS-VAR1 (FROM DATE/TIME/DAY/OTHER SYSTEM VARS).
If FROM Clause is not coded, then the data is read from terminal. At the time of execution, batch
program will ABEND if there is no in-stream data from JCL and there is no FROM clause in the ACCEPT
clause.
DISPLAY
It is used to display data. By default display messages are routed to SYSOUT.
Syntax: DISPLAY identifier1| literal1 (UPON mnemonic name)
EXIT PROGRAM is the last executable statement of sub-program. It returns control back to main
program.
GOBACK can be coded in main program as well as sub-program as the last statement. It just gives
the control back from where it received the control.
ALTER statement
The alter statement is used to modify the targets of GO TO statements written elsewhere in the
procedure division.
Collating Sequence
There are two famous Collating Sequence available in computers. IBM and IBM Compatible
machine use EBCDIC collating sequence whereas most micro and many mainframe systems use ASCII
collating sequence. The result of arithmetic and alphabetic comparison would be same in both collating
sequences whereas the same is not true for alphanumeric comparison.
Default collating sequence can be overridden by an entry in OBJECT-COMPUTER and SPECIAL NAMES
paragraphs.
1. Code the PROGRAM COLLATING SEQUENCE Clause in the Object computer paragraph.
PROGRAM COLLATING SEQUENCE IS alphabet-name
2. Map the alphabet-name in the SPECIAL-NAMES paragraph as follows:
ALPHABET alphabet-name is STANDARD-1 | NATIVE
NATIVE stands for computer’s own collating sequence whereas STANDARD-1 stands for ASCII collating
sequence.
IF/THEN/ELSE/END-IF
The most famous decision making statement in all language is ‘IF’. The syntax of IF statement is
given below: IF can be coded without any ELSE statement. THEN is a noise word and it is optional.
If ORs & ANDs are used in the same sentence, ANDs are evaluated first from left to right,
followed by ORs. This rule can be overridden by using parentheses.
The permitted relation conditions are =, <, >, <=, >=, <>
CONTINUE is no operation statement. The control is just passed to next STATEMENT. NEXT
SENTENCE passes the control to the next SENTENCE. Referring to first page, Sentence is defined as
statement(s) ended with full-stop.
It is advised to use END-IF, explicit scope terminator for the IF statements than period, implicit
scope terminator.
Mainframe Refresher Part-1 Page:52
Statement-Block-2 will be executed only when condition 1, 2 and 4 are TRUE and condition 3 is
FALSE.
Implied operand: In compound conditions, it is not always necessary to specify both operands for
each condition. IF TOTAL=7 or 8 is acceptable. Here TOTAL=8 is implied operation.
CLASS test is used to check the content of data item against pre-defined range of values. It can be done as
follows -
IF identifier is NUMERIC/ALPHABETIC/ALPHABETIC-HIGHER/
ALPHABETIC-LOWER
We can define our own classes in the special names paragraph. We have defined a class DIGIT in our
special names paragraph. It can be used in the following way.
IF identifier is DIGIT
Negated conditions.
Any simple, relational, class, sign test can be negated using NOT.
But it is not always true that NOT NEGATIVE is equal to POSITIVE. (Example ZERO)
EVALUATE
With COBOL85, we use the EVALUATE verb to implement the case structure of other languages.
Multiple IF statements can be efficiently and effectively replaced with EVALUATE statement. After the
execution of one of the when clauses, the control automatically comes to the statement following END-
EVALUATE. Any complex condition can be given in the WHEN clause. Break statement is not needed, as it
is so in other languages.
General Syntax
EVALUATE subject-1 (ALSO subject2..)
WHEN object-1 (ALSO object2..)
WHEN object-3 (ALSO object4..)
WHEN OTHER imperative statement
END-EVALUATE
1.Number of Subjects in EVALUATE clause should be equal to number of objects in every WHEN
clause.
Mainframe Refresher Part-1 Page:53
2.Subject can be variable, expression or the keyword TRUE/ FLASE and respectively objects can
be values, TRUE/FALSE or any condition.
3.If none of the WHEN condition is satisfied, then WHEN OTHER path will be executed.
Sample
EVALUATE SQLCODE ALSO TRUE
WHEN 100 ALSO A=B
WHEN -305 ALSO (A/C=4)
DISPLAY ‘ALLOWED SQLCODE..PROCEEDING..’
WHEN OTHER imperative statement
END-EVALUATE
In the above example, display will be thrown when one of the first two WHEN clauses are true.
PERFORM STATEMENTS
PERFORM will be useful when you want to execute a set of statements in multiple places of the
program. Write all the statements in one paragraph and invoke it using PERFORM wherever needed. Once
the paragraph is executed, the control comes back to next statement following the PERFORM.
1.SIMPLE PERFORM.
PERFORM PARA-1.
DISPLAY ‘PARA-1 executed’
STOP RUN.
PARA-1.
Statement1
Statement2.
It executes all the instructions coded in PARA-1 and then transfers the control to the next
instruction in sequence.
2.INLINE PERFORM.
When sets of statements are used only in one place then we can group all of them within
PERFORM END-PERFORM structure. This is called INLINE PERFORM.
This is equal to DO..END structure of other languages.
PERFORM
ADD A TO B
MULTIPLE B BY C
DISPLAY ‘VALUE OF A+B*C ‘ C
END-PERFORM
Mainframe Refresher Part-1 Page:54
GO TO Usage:
In a structured top-down programming GO TO is not preferable. It offers permanent control
transfer to another paragraph and the chances of logic errors is much greater with GO TO than PERFORM.
The readability of the program will also be badly affected.
But still GO TO can be used within the paragraphs being performed. i.e. When using the THRU
option of PERFORM statement, branches or GO TO statements, are permitted as long as they are within
the range of named paragraphs.
PERFORM 100-STEP1 THRU STEP-4
..
100-STEP-1.
ADD A TO B GIVING C.
IF D = ZERO DISPLAY ‘MULTIPLICATION NOT DONE’
GO TO 300-STEP3
END-IF.
200-STEP-2.
MULTIPLY C BY D.
300-STEP-3.
DISPLAY ‘VALUE OF C:’ C.
Here GO TO used within the range of PERFORM. This kind of Controlled GO TO is fine with structured
programming also!
Mainframe Refresher Part-1 Page:55
TABLES
An OCCURS clause is used to indicate the repeated occurrences of items of the same format in a
structure. OCCURS clause is not valid for 01, 77, 88 levels.
It can be defined as elementary or group item. Initialization of large table occurrences with specific values
are usually done using perform loops in procedure division. Simple tables can be initialized in the
following way.
01 WEEK-ARRAY VALUE ‘MONTUEWEDTHUFRISATSUN’.
05 WS-WEEK-DAYS OCCURS 7 TIMES PIC X(03).
Dynamic array is the array whose size is decided during runtime just before the access of first element of
the array.
01 WS-MONTH-DAY-CAL.
05 WS-DAYS OCCURS 31 TIMES DEPENDING ON WS-OCCURENCE.
Array Items can be accessed using INDEX or subscript and the difference between them are listed
in the table. Relative subscripts and relative indexes are supported only in COBOL85. Literals used in
relative subscripting/indexing must be an unsigned integer.
ADD WS-SAL(SUB) WS-SAL(SUB + 1) TO WS-SAL(SUB + 2).
Sl # Subscript Index
1 Working Storage item Internal Item – No need to declare it.
2 It means occurrence It means displacement
3 Occurrence, in turn translated to Faster and efficient.
displacement to access elements and so
slower than INDEX access.
Mainframe Refresher Part-1 Page:56
4 It can be used in any arithmetic operations It cannot be used for arithmetic operation or for
or for display. display purpose.
5 Subscripts can be modified by any INDEX can only be modified with SET, SEARCH and
arithmetic statement. PERFORM statements.
SEARCH
When the requirement is to randomly access sequential information, the only possible way is to load the
information in an array and look up in the array for the information requested.
This table look up can be done in two ways: 1. Sequential Search (SEARCH)
2. Binary Search (SEARCH ALL)
To use SEARCH/SEARCH ALL, table should have an index. To use SEARCH ALL the table should be in a
sorted order.
Mainframe Refresher Part-1 Page:57
If you want access any working storage variable of PGMA in PGMB, then declare them with the
clause ‘IS GLOBAL’ in PGMA. If you want to access any working storage variable of PGMB in PGMA,
declare them with the clause ‘IS EXTERNAL’ in PGMB. Nested Programs are supported only in COBOL85.
If there is a program PGMC inside PGMB, it cannot be called from PGMA unless it’s program id is
qualified with keyword COMMON.
Syntax:
SORT SORTFILE ON ASCENDING /DESCENDING KEY sd-key-1 sd-key2
USING file1 file2 / INPUT PROCEDURE IS section-1
GIVING file3 / OUTPUT PROCEDURE is section-2
END-SORT
File1, File2 are to-be-sorted input files and File3 is sorted-output file and all
of them are defined in FD.SORTFILE is Disk SORT Work file that is defined at SD. It should not be explicitly
opened or closed.
INPUT PROCEDURE and USING are mutually exclusive. If USING is used, then file1 and file2
should not be opened or READ explicitly. If INPUT PROCEDURE is used then File1 and file2 need to be
OPENed and READ the records one by one until end of the file and pass the required records to sort-work-
file using the command RELEASE.
Syntax: RELEASE sort-work-record from input-file-record.
OUTPUT PROCEDURE and GIVING are mutually exclusive. If GIVING is used, then file3 should not
be opened or WRITE explicitly. If OUTPUT procedure is used, then File3 should be OPENed and the
required records from sort work file should be RETURNed to it. Once AT END is reached for sort-work-file,
close the output file.
Syntax: RETURN sort-work-file-name AT END imperative statement.
MERGE
It is same as sort. USING is mandatory. There should be minimum two files in USING.
MERGE Sort-work-file ON ASCENDING KEY dataname1 dataname2
USING file1 file2
GIVING file3 / OUTPUT PROCEDURE is section-1
END-MERGE
STRING MANIPULATION
A string refers to a sequence of characters. String manipulation operations include finding a
particular character/sub-string in a string, replacing particular character/sub-string in a string,
concatenating strings and segmenting strings.
All these functions are handled by three verbs INSPECT, STRING and UNSTRING in COBOL. EXAMINE is the
obsolete version of INSPECT supported in COBOL74.
Main String is identifier-1 and count is stored in identifier-2. Literal-1 or Identifier-3 is a character
or group-of-characters you are looking in the main-string.
INSPECT further qualifies the search with BEFORE and AFTER of the initial occurrence of identifier-4 or
literal-2.
Example:
WS-NAME – ‘MUTHU SARAVANA SURYA CHANDRA DEVI’
STRING
STRING command is used to concatenate one or more strings.
Mainframe Refresher Part-1 Page:61
Syntax:
STRING identifier-1 / literal-1, identifier-2/ literal-2
DELIMITED BY (identifier-3/literal-3/SIZE)
INTO identifier-4
END-STRING.
Syntax: String(Starting-Position:Length)
MOVE ‘18’ TO AGE-OUT(1:2) does the same as what we did with STRING command.
When it is used in array elements, the syntax is
Array-element (occurrence) (Starting-Position:Length)
UNSTRING
UNSTRING command is used to split one string to many strings.
Syntax:
UNSTRING identifier-1
[DELIMITED BY (ALL/) identifier2/literal1 [,OR (ALL/) (identifier-3/literal-2),..]]
INTO identifier-4 [,DELIMITER IN identifier-5, COUNT IN identifier-6]
[,identifier-7 [,DELIMITER IN identifier-8, COUNT IN identifier-9]
COPY Statement
A COPY statement is used to bring a series of prewritten COBOL entries that have been stored in
library, into a program.
1.Common routines like error routine, date validation routine are coded in a library and bring into the
program by COPY.
2. Master files are used in multiple programs. Their layout can be placed in one copybook and be placed
wherever the files are used. It promotes program standardization since all the programs share the same
layout and the same data names.
This reduces coding and debugging time. Change in layout needs change in copybook only. It is
enough if we just recompile the program for making the new copy effective.
Syntax:
COPY copybook-name [(OF/IN) library name]
[REPLACING string-to-be-replaced BY replacing-string]
Copybooks are stored as members in PDS library and during compilation time, they are included into the
program. By default, the copybook library is SYSLIB and it can be changed using IN or OF of COPY
statement.
If the same copybook is used more than once in the program, then there will be “duplicate data
declaration” error during compilation, as all the fields are declared twice. In this case, one copybook can
be used with REPLACING verb to replace high-level qualifier of the all the variables with another qualifier.
Delimiter ‘= =’ should be used for replacing pseudo texts. The replacing option does not alter the
prewritten entries in the library; the changes are made to the user’s source program only.
Sub-Program Changes:
WS-VAR1 and WS-VAR2 are working storage items of main program.
Mainframe Refresher Part-1 Page:63
As we have already mentioned, the linkage section is used for accessing external elements. As these
working storage items are owned by main program, to access them in the sub-program, we need to
define them in the linkage section.
LINKAGE SECTION.
01 LNK-ITEMS.
05 LK-VAR1 PIC 9(04).
05 LK-VAR2 PIC 9(04).
In addition to define them in linkage section, the procedure division should be coded with these data
items for address-ability.
The name of the identifiers in the called and calling program need not be the same (WS-VAR1 &
LK-VAR1).
The last statement of your sub-program should be EXIT PROGRAM. This returns the control back
to main program. GOBACK can also be coded instead of EXIT PROGRAM but not STOP RUN. EXIT
PROGRAM should be the only statement in a paragraph in COBOL74 whereas it can be coded along with
other statements in a paragraph in COBOL85.
If the sub program is modified then it needs to be recompiled. The need for main program
recompilation is decided by the compiler option used for the main program. If the DYNAM compiler is
used, then there is no need to recompile the main program. The modified subroutine will be in effect
during the run. NODYNAM is default that expects the main program recompilation.
INTRINSIC FUNCTIONS:
LENGTH Returns the length of the PIC clause. Used for finding length of group
item that spanned across multiple levels.
MAX Returns the content of the argument that contains the maximum value
MIN Returns the content of the argument that contains the minimum value
NUMVAL Returns the numeric value represented by an alphanumeric character
string specified in the argument.
NUMVAL-C Same as NUMVAL but currency and decimal points are ignored during conversion.
CURRENT Returns 21 Chars alphanumeric value – YYYYMMDDHHMMSSnnnnnn
DATE
INTEGER OF DATE Returns INTEGER equivalent of Gregorian date passed.
INTEGER OF DAY Returns INTEGER equivalent of Julian date passed.
DATE OF INTEGER Returns Gregorian date for the integer passed.
DAY OF INTEGER Returns Julian date for the integer passed.
FILE HANDLING
A data file is collection of relevant records and a record is collection of relevant fields. The file
handling in COBOL program involves five steps.
Steps in file-handing
1.Allocation: The files used in the program should be declared in FILE-CONTROL paragraph of
environment division. The mapping with JCL DDNAME is done here. The file is allocated to your program
by this statement.
2.Definition. The layout of the file and its attributes are defined in the FILE SECTION of DATA
DIVISION.
3.Open: Dataset is connected/readied to your program using OPEN statement. The mode of
OPEN decides the operation allowed and the initial pointer in the dataset. For example, EXTEND mode
allows only write access and the pointer is kept on the end of file to append.
4.Process: Process the file as per requirement, using the I-O statements
provided by COBOL. (READ, WRITE, REWRITE and DELETE)
5. Close: After the processing, close the file to disconnect it from the program.
JCL Step executing the program should have a dataset with DDNAME as label
//DDNAME DD DSN=BPMAIN.EMPLOYEE.DATA,DISP=SHR
Mainframe Refresher Part-1 Page:66
SELECT Statement-ORGANIZATION
It can be SEQUENTIAL (PS or VSAM ESDS), INDEXED (VSAM KSDS), RELATIVE (VSAM RRDS).
Default is Sequential.
RANDOM.
Records can be randomly accessed in the program using the primary/alternate key of indexed file
th
organization or relative record number of relative organization.100 record can directly be read after
th
getting the address of the record from the INDEX part for INDEXED files.100 record can directly be read
for RELATIVE files even without any index.
DYNAMIC.
It is mixed access mode where the file can be accessed in random as well as sequential mode in
the program.
th
Example: Reading the details of all the employees between 1000-2000. First randomly access 1000
th
employee record, then read sequentially till 2000 employee record. START and READ NEXT commands
are used for this purpose in the procedure division.
RESERVE Clause.
RESERVE clause [RESERVE integer AREA ] can be coded in the SELECT statement. The number of
buffers to be allocated for the file is coded here.
By default two buffers will be allocated if the clause is not coded. Since similar option is available in JCL,
this is not coded in program.
RESERVE 1 AREA allocates one buffer, for the file in the SELECT statement.
FD FILENAME
RECORDING MODE IS V/VB/F/FB
RECORD CONTAINS M CHARACTERS (TO N CHARACTERS)
BLOCK CONTAINS X CHARACTERS/RECORDS (TO Y CHARACTERS/RECORDS)
LABEL RECORDS ARE OMITTED/STANDARD
DATA RECORD IS FILE-RECORD.
01 FILE-RECORD PIC X(nnn).
FD-RECORD CONTAINS
It specifies the length of the record in terms of bytes. (It will be RECORD contains m to n
CHARACTERS for variable format files)
FD-BLOCK CONTAINS
It specifies the physical record size. It can be mentioned as number of logical records OR number
of characters, that is multiple of logical record length. It is suggested to code BLOCK CONTAINS 0
RECORDS so that system will decide the optimum size for the file based on the device used for storing the
file. BLOCK CONTAINS clause is treated as comments for VSAM files.
Advantage of Blocking:
1.I-O time is reduced as n numbers of records are read into main memory buffer during an I-O.
2.Inter record gap is removed and the gap exist only between blocks. So memory wastage due to IRG is
avoided.
FD-RECORDING MODE IS
It can be F (FIXED) V(VARIABLE) FB(FIXED BLOCK) VB(VARIABLE BLOCKED)
Variable record file identification:
If there is no recording mode/record contains clause, it is still possible to identify variable length
records. If there is an OCCURS depending on clause or there are multiple 01 levels and every 01 level is of
different size, then the file would be of variable length. Multiple 01 levels in File section is an example for
implicit redefinition.
OPEN STATEMENT
Syntax: OPEN OPENMODE FILENAME
OPENMODE can be INPUT OUTPUT I-O EXTEND
INPUT - File can be used ONLY-FOR-READ purpose.
OUTPUT - File can be used ONLY-FOR-WRITE purpose.
I-O - File can be used FOR READ, WRITE and REWRITE purpose.
EXTEND - File can be used FOR appending records using WRITE.
CLOSE statement.
The used files are closed using CLOSE statement. If you don’t close the files, the completion of
the program closes all the files used in the program.
Syntax: CLOSE FILENAME
Mainframe Refresher Part-1 Page:68
When you close the file, the tape is normally rewound. The NO REWIND clause specifies that the
TAPE should be left in its current position.
CLOSE statement with REEL option closes the current reel alone. So the next READ will get the
first record of next REEL. This will be useful when you want skip all the records in the first reel after n
number of records processing.
Since TAPE is sequential device, if you create multiple files in the same TAPE, then before
opening the second file, first file should be closed. At any point of time, you can have only one file is active
in the program. In addition to this, you have to code MULTIPLE FILE clause in the I-O control paragraph of
environment division.
MULTIPLE FILE TAPE CONTAINS OUT-FILE1 POSITION 1
OUT-FILE3 POSITION 3.
The files OUT-FILE1 and OUT-FILE3 used in the program are part of a same TAPE and they exist in
first and third position in the tape. Alternatively, this information can be passed from JCL using LABEL
parameter.
READ statement
READ statement is used to read the record from the file.
Syntax: READ FILENAME [INTO ws-record] [KEY IS FILE-KEY1]
[AT END/INVALID KEY imperative statement1]
[NOT AT END/NOT INVALID KEY imperative statement2]
Mainframe Refresher Part-1 Page:69
END-READ
If INTO clause is coded, then the file is directly read into working storage section record. It is
preferred as it avoids another move of file-section-record to working-storage-record followed by simple
READ. READ-INTO is not preferred for variable size records where the length of the record being read is
not known.
KEY IS clause is used while accessing a record randomly using primary/alternate record key.
AT END and NOT AT END are used during sequential READ of the file.
INVALID KEY and NOT INVALID KEY are used during random read of the file.
Before accessing the file randomly, the key field should have a value before READ.
WRITE Statement
Write statement is used to write a new record in the file. If the file is opened in EXTEND mode,
the record will be appended. If the file is opened in OUTPUT mode, the record will be added at the current
position.
FROM clause avoids the explicit move of working storage record to file section record before WRITE.
REWRITE Statement
REWRITE is used to update an already read record. To update a record in a file, the file should be
opened in I-O mode.
Syntax: REWRITE FILE-RECORD [FROM ws-record]
[INVALID KEY imperative statement1]
END-REWRITE
START Statement
START is used with dynamic access mode of indexed files. It establishes the current location in
the cluster for READ NEXT statement. START itself does not retrieve any record.
Syntax: START FILENAME
KEY is EQUAL TO/NOT LESS THAN/GREATER THAN key-name
[INVALID KEY imperative statement1]
END-START.
DELETE Statement
DELETE is used to delete the most recently read record in the file. To delete a record, the file
should be opened in I-O mode.
Syntax: DELETE FILENAME RECORD
[INVALID KEY imperative statement1]
END-DELETE
Reports – FBA:
Reports contain the printing control character in the first byte. The record format will be FBA and
the LRECL will be 133 in the JCL. The program can define printing control character and populate it
manually or can define the layout with 132 bytes and by means of program supported WRITE verbs like
AFTER/BEFORE/ADVANCING. In the second case printing control character will be automatically added at
the time of compilation by the default ADV compiler option.
PROCEDURE DIVISION.
DECLARATIVES.
USE-PROCEDURE SECTION.
USE AFTER EXCEPTION PROCEDURE ON INPUT
ERROR-PROCEDURE.
Check the file-status code for validity.
END-DECLARATIVES.
Whenever there is an error in the processing of ANY FILE opened in INPUT mode, then the
control comes to ERROR-PROCEDURE. The validity of error should be checked in this paragraph and allow
or restrict the process down, based on severity of error code.
If file name (file-1) is coded in the USE statement, then all the input-output operation of that
specific file will be checked.
ERROR and EXCEPTION are synonyms.
The Procedure written in a DECLARATIVE section should not refer to any non-declarative
procedure written after the end procedure and vice-versa.
If SAME RECORD AREA is coded, then the buffer is not shared but only the record area is shared.
So more than one file can be in open state. We should be careful while filling in the record area of the
output file. This may destroy the record read most recently.
Syntax: SAME RECORD AREA FOR file-1 file-2 file-3.
SAME SORT AREA allows more than one sort/merge work files to use the same area. The sort
work files are automatically allocated when file is opened and de-allocated when file is closed. As the sort
file is automatically opened and closed during a SORT and two sort files cannot be opened at a time, this
clause may not be useful.
Syntax: SAME SORT|SORT-MERGE AREA for file-1 file-2.
File-1 or file-2 should be a SD file.
ENTRY statement
ENTRY statement establishes an alternate ENTRY point in a COBOL called
sub-program. When a CALL statement naming the alternate entry point is executed in a calling
program, control is transferred to the next executable statement following the entry statement. Except
when a CALL statement refers to an entry name, the ENTRY statements are ignored at run-time.
Mainframe Refresher Part-1 Page:72
It is a two-byte working storage item. The first byte denotes the general category whereas
second byte denotes the particular type of error message under that category.
COBOL COMPILATION
Mainframe Refresher Part-1 Page:73
SYSPRINT
PARM (Compiler listing)
(Compiler
Options)
SYSLIB PARM
(Copybook Library) (Link
edit Options)
IEWL
(Link Editor)
SYSLMOD
(Load Module)
SYSPRINT SYSLIB
(Link edit messages) (Subroutine Library)
COMPILATION JCL:
//SMSXL86B JOB ,'COMPILATION JCL', MSGCLASS=Q,MSGLEVEL=(1,1),CLASS=C
//COMPILE1 EXEC PGM=IGYCRCTL, PARM=’XREF,APO,ADV,MAP,LIST),REGION=0M
//STEPLIB DD DSN=SYS1.COB2LIB,DISP=SHR
//SYSIN DD DSN=SMSXL86.TEST.COBOL(SAMPGM01),DISP=SHR
//SYSLIB DD DSN=SMSXL86.COPYLIB,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSLIN DD DSN=&&LOADSET, DCB=(RECFM=FB,LRECL=80,BLKSIZE=3200),
// DISP=(NEW,PASS),UNIT=SYSDA,SPACE=(CYL,(5,10),RLSE),
//SYSUT1 DD UNIT=&SYSDA,SPACE=(CYL,(1,10)) => Code SYSUT2 to UT7
//LINKEDT1 EXEC PGM=IEWL,COND=(4,LT)
//SYSLIN DD DSN=&&LOADSET, DISP=(OLD,DELETE)
//SYSLMOD DD DSN=&&GOSET(SAMPGM01),DISP=(NEW,PASS),UNIT=SYSDA
// SPACE=(CYL,1,1,1))
//SYSLIB DD DSN=SMSXL86.LOADLIB,DISP=SHR
//SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(1,10))
//SYSPRINT DD SYSOUT=*
Compiler Options
The default options that were set up when your compiler was installed are in effect for your
program unless you override them with other options. To check the default compiler options of your
installation, do a compile and check in the compilation listing.
1.Compiler options can be passed to COBOL Compiler Program (IGYCRCTL) through the PARM in JCL.
2.PROCESS or CBL statement with compiler options, can be placed before the identification division.
3.If the organization uses any third party product or its own utility then these options can be coded in the
pre-defined line of the utility panel.
ADV: It is meaningful if your program has any printer files with WRITE..ADVANCING keyword. The
compiler adds one byte prefix to the original LRECL of printer files for printing control purpose. If you are
manually populating printing control character in the program, then you can compile your program with
NOADV.
DYNAM: Use DYNAM to cause separately compiled programs invoked through the CALL literal statement
to be loaded dynamically at run time. DYNAM causes dynamic loads (for CALL) and deletes (for CANCEL)
of separately compiled programs at object time. Any CALL identifier statements that cannot be resolved in
your program are also treated as dynamic calls. When you specify DYNAM, RESIDENT is also put into
effect.
LIST/OFFSET: LIST and OFFSET are mutually exclusive. If you use both, LIST will be ignored. LIST is used to
produce listing a listing of the assembler language expansion of your code. OFFSET is used to produce a
condensed Procedure Division listing.
Mainframe Refresher Part-1 Page:75
With OFFSET, the procedure portion of the listing will contain line numbers, statement references, and
the location of the first instruction generated for each statement. These options are useful for solving
system ABENDS. Refer JCL session for more details.
MAP: Use MAP to produce a listing of the items you defined in the Data Division.
SSRANGE: If the program is compiled with SSRANGE option, then any attempt to refer an area outside
the region of the table will abnormally terminate with protection exception, usually S0C4.It also avoids
any meaningless operation on reference modification like negative number in the starting position of
reference modification expression. If the program is compiled with NOSSRANGE, then the program may
proceed further with junk or irrelevant data. So usually the programs are compiled with SSRANGE during
development and testing.
RENT: A program compiled as RENT is generated as a reentrant object module. CICS programs should be
compiled with RENT option to share the same copy of the program by multiple transactions
(Multithreading)
RESIDENT: Use the RESIDENT option to request the COBOL Library Management Feature. (The COBOL
Library Management Feature causes most COBOL library routines to be located dynamically at run time,
instead of being link-edited with the COBOL program.).CICS Programs should be compiled with RESIENT
option.
XREF: Use XREF to get a sorted cross-reference listing. EBCDIC data-names and procedure-names will be
listed in alphanumeric order. It also includes listing, where all the data-names that are referenced within
your program and the line number where they are defined. This is useful for identifying the fields that are
defined but not used anywhere after the development of new program.
VSAM
Mainframe Refresher Part-1 Page:78
History
Access Method is an interface between the application program and physical operation of
storage devices. It is a component of operating system. VSAM is the first access method that efficiently
uses the virtual storage of MVS. It can manipulate only the data that resides on a DASD. (Direct access
storage device)
IBM introduced VSAM in 1973 as a replacement for several existing access methods designed by
it earlier.
KSDS (Key Sequenced Data Set) replaced ISAM (Indexed Sequential Access Method)
RRDS (Relative Record Data Set) replaced BDAM (Basic Direct Access Method)
ESDS (Entry Sequence Data Set) provide same function as normal sequential QSAM. (Queued Sequential
Access Method).
Initially VSAM had only ESDS and KSDS. RRDS and Alternate Index to KSDS are introduced in
1979. DF/ EF (Data Facility extended Function) VSAM was introduced in 1979 with Integrated Catalog
Facility (ICF) to replace the old VSAM catalog of the previous versions.
The latest version of DFP/ VSAM released in 1991 called DFP/VSAM 3.3 contains enhancements
like variable record length support for RRDS and added DFSMS facilities.
1.Data retrieval will be faster because of an efficiently organized index. The index is small because it uses
a key compression algorithm.
2.Insertion of records is easy due to embedded free space in the cluster.
3.Records can be physically deleted and the spaces used by them can be used for storing other records
without reorganization.
4.VSAM datasets can be shared across the regions and systems.
5.Datasets can be physically distributed over various volumes based on key ranges.
6.VSAM is independent of storage device types.
7.Information about VSAM datasets is centrally stored in VSAM catalog.
So referencing of any VSAM dataset need not be detailed in JCL.
Disadvantages of VSAM
1.To allow easy manipulation of records, free space should be left in the dataset and this increases the
spaces required.
2.Integrity of the dataset across the region and system need to be controlled by user.
CLUSTER
A cluster can be thought of as a logical dataset consisting of two separate physical datasets:
1 The data component (contains the actual data).
Mainframe Refresher Part-1 Page:79
Data Component.
RDF – Record Definition Field – 3 bytes field. For fixed length records, there will be 2 RDF, first
contains the number of records in the control interval and the second contains record length. For
variable length records, the number of RDF can vary depending on how many adjacent records
have the same length in the CI. If no two adjacent records are of the same length, then one RDF
is needed to describe each record.
Example
1. In the example below, there are four control areas and every control area contains two control
intervals. Control fields are not shown in the diagram. There should be one sequence for every control
area. So there are four sequence sets. There are two levels of index set. The second level of index set
contains pointers to sequence set.
2. Control Interval Split: When a record with key 22 is added in the program, it should physically be stored
between the existing records 21 and 23. 21 and 23 are in the first control interval of control area-3. There
is no more space available to store this record. So control split will occurs. Record 20 and 21 continue to
exist in the current control interval. Records 22 and 23 will be moved to any of the free control intervals.
In our case control interval 2 is free. So they are moved there and index set is accordingly updated.
3. Control Area Split: When a record with key 3 in the program, it should be placed between 2 and 4.
These records are in first control interval of first control area and there is no free space. So control
interval split is expected. But there is no free control interval in the control area-1. So control area split
occur. New control area is allocated and half the records of control area-1 will be moved there and
indexes are properly updated.
To answer this question, you should know how indexes are organized and read. We have already
th
seen how they are organized. In the example below, to read the 50 record, first root index is read and
identified that the record should be in the right hand side. In the second I-O, I will get the sequence and in
third I-O, I will get the location of the record. I will get my record in the fourth I-O instead 51 I-O. (50 IO in
index and 1 I-O for getting the data)
If I am accessing the first record, then sequential read needs only one I-O but obviously my
random read needs more. So we prefer indexed organization only when the number of records is
significant.
First Level
*8 *17 * 23 *50
Index
1 2 4 12 14 20 21 23 33 35
Data Component
5 7 8 17 50
Mainframe Refresher Part-1 Page:81
VSAM LDS Properties: Linear datasets have no records. They are just long strings of bytes. Since it is a
long string of bytes an LDS has no FSPC, US, CIDF and RDF. The CISZ is always 4k bytes. The main use of
LDS is to implement other data access organizations especially a relational database system like DB2.
As the data in an LDS is manipulated the operating system automatically pages in and out the
portions of the dataset being worked on. The dataset is addressed by the RBA as if it were in memory and
the system pages the needed pages in and out. Thus the process is very simple and fast.
changed.
Free Space Exist at the end of the Distributed free space Free slots are available
dataset to add records. for inserting records in for adding records at
between or change the their location.
length of existing
record.
Deletion Cannot be deleted. DELETE is possible. DELETE is possible.
REWRITE of same length is
possible.
Record Size Fixed or Variable Fixed or Variable Fixed.
SPANNED records Possible Possible Not possible
Speciality Occupies less Space Easy RANDOM access Fastest access method.
and most popular
method
Preference Application that require Applications that Applications that
sequential access only. require each record to require only direct
Ex: PAYROLL have a key field and access. There should be
PROCESSING. require both direct and a field in the record that
sequential access. can be easily mapped to
Ex: Banking application RRN.
2. Keyword ‘DATASET’ should directly point to the physical dataset and IDCAMS allocates this file
dynamically for operation.
DEFINE CLUSTER
This command is used to create and name a VSAM Cluster.
DEFINE CLUSTER-NAME
This parameter specifies name to the VSAM cluster. The cluster name becomes the dataset name
in any JCL that invokes the cluster
When the data and index parameters are coded to create the data and index components, the
name parameter is coded for them as well. If the name parameter is omitted for the data and index VSAM
tries to append part of .DATA or .INDEX as appropriate as the low level qualifier depending on how many
characters the dataset name contains already and still staying within the 44 character limit.
If data and index components are named, parameter values can be applied separately. This gives
performance advantages for large datasets.
VSAM calculates the control area size internally. Control area can of one cylinder, the largest
permitted by VSAM, usually yields the best performance. So it is always better to allocate space in
cylinders because this ensures a CA size of one cylinder.
The RECORDS parameter is used to allocate space in units of records for small datasets. When
this is done the RECORDSIZE parameter must be specified.
If allocation is specified in units of KILOBYTES or MEGABYTES VSAM reserves space on the minimum
number of tracks it needs to satisfy the request.
For an ESDS (since it is processed sequentially) the CISZ should be relatively large depending on the size of
the record.
FREESPACE(ci% ca%)
FREESPACE(ci% ) control interval only
FREESPACE(0 ca%) control area only
FREESPACE(0 0) is the default.
FREESPACE(100 100) means only one record will be loaded in every control interval and only one control
interval will be loaded in every control area.
In order to effectively allocate FREESPACE the following factors have to be taken into consideration.
1. The expected rate of growth: If even growth is expected apply FREESPACE to both CI and CA. If uneven
growth is expected apply FREESPACE only to the CA.
Mainframe Refresher Part-1 Page:86
The CI FREESPACE allocation should be enough to cover the length of one record plus any
additional RDFs that may result from a variable record length.
DEFINE CLUSTER -
(NAME(NTCI.V.UE4.W20000.T30.AV.DW200006) -
CYL(5 1) -
KEYS(8 0) -
RECSZ(80 80) -
KEYRANGES ((00000001 2999999) -
(30000000 4700000) -
(47000001 9999999)) -
VOLUMES (NTTSOB -
NTTSOJ -
NTTSO5) -
ORDERED -
NOREUSE -
INDEXED
_ _ _ more parameters
When the ORDERED parameter is coded the number of VOLUMES and KEYRANGES must be the same.
Password Protection
VSAM datasets can be password protected at four different levels. Each level gives a different
access capability to the dataset. The levels are
1. READPW- provides read only capability.
2. UPDATEPW- records may be read, updated , added or deleted at this level.
3. CONTROLPW- provides the programmer with the access capabilities of READPW and UPDATEPW.
4. MASTERPW- all the above operations plus the authority to delete the dataset is provided.
Passwords provided at the cluster level protect only if access requires using the cluster’s name as
dataset name. Therefore it is advisable to protect the data and index components using passwords
because someone could otherwise access them by name. Another feature of MVS called Resource Access
Control Facility (RACF) ignores VSAM passwords and imposes its own security and for most VSAM datasets
RACF security is sufficient.
The ATTEMPTS parameter coded with the password parameters specifies the number of
attempts permitted for the operator to enter the password before abending the step.
The CODE parameter allows for the specification of a code to display to the operator in place of
the entry name prompt.
The AUTHORIZATION parameter provides for additional security by naming an assembler User
Security Verification Routine (USVR). The sub parameter for this enclosed in parenthesis is the entry point
of the routine.
Command Syntax
REPRO -
INFILE(DDNAME) | INDATASET(DATASET-NAME) -
OUTFILE(DDNAME) | OUTDATASET(DATASET-NAME) -
optional parameters
When loading a KSDS using REPRO, the input data should be first sorted in ascending sequence
by the field that will become the primary key in the output dataset. When loading an ESDS the sort step
can be eliminated since the records are loaded in entry sequence. For an RRDS, the records are loaded in
relative record sequence starting with 1. The dataset should be sorted on the field that correlates to the
relative record number.
The REPRO command can be used for merging two datasets into one. The target dataset can be a
non-empty KSDS, ESDS or RRDS.
The input dataset can be any organization if the target dataset is a KSDS or ESDS. However if the
target dataset is an RRDS the source dataset has to be an RRDS. KSDS to KSDS is the most common
application of this merge technique.
If the REPLACE option is specified as part of the REPRO command then records with duplicate
primary keys (for a KSDS) and duplicate relative record numbers (in the case of an RRDS) will be replaced.
HEX format prints each character in the dataset as two hexadecimal digits.
A maximum of 120 hexadecimal digits are printed on each line, an equivalent of 60 characters.
DUMP format is a combination of the character and hex formats. Each character is printed both
as a character and as the corresponding hex representation. Each print line consists of 64 hex digits and
the 32 related characters. If the record length is greater than 32 characters the rest of the record is
printed in blocks of 64 hex digits and 32 corresponding characters per line.
PRINT INDATASET(MM01.CUSTOMER.MASTER) -
CHARACTER -
SKIP(28) -
COUNT(3)
DELETE - FORCE(FRC)/NOFORCE(NFRC)
It specifies whether objects that are not empty should be deleted.
FORCE allows you to delete data spaces, generation data groups, and user catalogs without first
ensuring that these objects are empty.
NOFORCE causes the DELETE command to terminate when you request the deletion of a data
space, generation data group, or catalog that is not empty.
DELTE - FILE(DDNAME)
It specifies the name of the DD statement that identifies:
1. The volume that contains a unique data set to be deleted.
2. The partitioned data set from which a member (or members) is to be deleted.
3. The data set to be deleted if ERASE is specified.
4. The volume that contains the data space to be deleted.
5. The catalog recovery volume(s) when the entry being deleted is in a recoverable catalog. If the volumes
are of a different device type, concatenated DD statements must be used. The catalog recovery volume is
the volume whose recovery space contains a copy of the entry being deleted.
Mainframe Refresher Part-1 Page:93
LISTCAT stands for LISTing a CATalog entry. It is useful for listing attributes and characteristics of
all VSAM and non-VSAM objects cataloged in a VSAM or ICF catalog. Such objects can be the catalog itself,
its aliases, the volumes it owns, clusters, alternate indexes, paths, GDG’s, non-VSAM files etc. The listing
also provides statistics about a VSAM object from the time of its allocation, namely the number of CI and
CA splits, the number of I/O on index and data components, the number of records added, deleted and
retrieved besides other useful information.
Syntax:
LISTCAT ENTRIES(OBJECT-NAME) ALL|ALLOCATION|VOLUME|HISTORY|NAME
Parameter Meaning
NAME List the name and type of entry.
HISTORY Lists reference information for the object including name, type of entry, creation
and expiration date and the release of VSAM under which it was created.
VOLUME Lists the device type and one or more volume serial number of the storage
volumes where the dataset resides. HISTORY information is also listed.
ALLOCATION Lists information that has been specified for space allocation including the
unit(cylinders, tracks etc.), number of allocated units of primary and secondary
space and actual extents. This is displayed only for data and index component
entries. If ALLOCATION is specified VOLUME and HISTORY are included.
ALL All the above details are listed
Example
//SMSXL861 JOB (36512),'MUTHU',NOTIFY=&SYSUID
// LISTCAT EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
LISTCAT ENTRIES(SMSXL86.PAYROLL.MASTER) -
GDG -
ALL
/*
Entry-name is the name of the object that need to be exported. OUTFILE mention exported into what
name.
EXPORT - INHIBITSOURCE|NOINHIBITSOURCE
It specifies whether the original data records (the data records of the source cluster or alternate
index) can be accessed for any operation other than retrieval after a copy is exported. This specification
can later be altered through the ALTER command.
INHIBITSOURCE (INHS) - cannot be accessed for any operation other than retrieval.
NOINHIBITSOURCE - original data records in the original system can be accessed for any kind of operation.
EXPORT - TEMPORARY|PERMANENT
It specifies whether the cluster or alternate index to be exported is to
be deleted from the original system.
TEMPORARY specifies that the cluster or alternate index is not to be deleted from the original
system. The object in the original system is marked as temporary to indicate that another copy exists and
that the original copy can be replaced.
PERMANENT specifies that the cluster or alternate index is to be deleted from the original
system. Its storage space is freed. If its retention period has not yet expired, you must also code PURGE.
PERMANENT is the default.
EXPORT - ERASE|NOERASE
This specifies whether the data component of the cluster or alternate index to be exported is to
be erased or not (overwritten with binary zeros).
With ERASE specification, the data component is overwritten with binary zeros when the cluster
or alternate index is deleted.
Mainframe Refresher Part-1 Page:95
With NOERASE specification, the data component is not overwritten with binary zeros when the
cluster or alternate index is deleted.
Example:
//EXPORT EXEC PGM=IDCAMS
//DD2 DD DSN=SMSXL86.LIB.KSDS.BACKUP(+!),
// DISP=(NEW,CATLG,DELETE),UNIT=TAPE,
// VOL=SER=121212,LABEL=(1,SL),
// DCB=(RECFM=FB,LRECL=80)
//SYSIN DD *
EXPORT A2000.LIB.KSDS.CLUSTER -
OUTFILE (DD2)
/*
IMPORT - OBJECTS
When the OBJECTS parameter is coded the attributes of the new target dataset can be changed.
These attributes include VOLUMES and KEYRANGES.
IDCAMS-VERIFY Command
If a job terminates abnormally and a VSAM dataset is not closed, the catalog entry for the
dataset is flagged to indicate that the dataset may be corrupt(as the end of file or last key is not updated
in the index properly). In such case you would get VSAM status code of ‘97’ in the open of the file in the
program. Before the dataset can be opened again, the VERIFY command must be used to correctly
identify the end of the dataset and reset the catalog entry. Alternate solution is open the file in File-aid in
edit mode and just save it. It would update the index with end of file.
Base cluster and alternate index can be verified. The verification of base cluster does not verify its
alternate indexes so each one of them must be treated separately.
It is important to note that all the attributes cannot be changed with ALTER.
Few parameters that can’t be altered are: CISZ, Type of Cluster, IMBED/REPLICATE,
REUSE/NOREUSE
Frequently ALTER is used for renaming (NEWNAME), altering free space (FREESPACE), temporarily
disabling updates over dataset (INHIBIT) and extend the generation limit of GDG (LIMIT).
Example
JCL for an AMS job with comments that runs an ALTER command
LASTCC contains the return-code of the last executed functional command and if more than one
functional command is executed in single IDCAMS step, then
MAXCC contains the maximum value of condition codes from the previously
executed functional commands. MAXCC is returned as step return code in JCL.
SET command is used to reset the MAXCC or LASTCC within AMS.
IF-THEN-ELSE statements are used to control the command execution sequence.
In the below example, REPRO command loads data from a sequential dataset on to a KSDS. Only
if the condition code of the REPRO step is zero, the next LISTCAT step will be executed. Otherwise the
KSDS will be deleted. MAXCC is set to zero at the end to avoid non-zero return code.
//SYSIN DD *
Mainframe Refresher Part-1 Page:97
REPRO INDATASET(SMSXL86.DATA.TEST) -
OUTDATASET(SMSXL86.TEST.KSDS) -
IF LASTCC = 0 -
THEN -
LISTCAT -
ENTRIES(SMSXL86.TEST.KSDS) ALL
ELSE -
DELETE SMSXL86.TEST.KSDS
END-IF
SET MAXCC=0
/*
ALTERNATE INDEX
1. KSDS dataset is currently accessed using a primary key. We want to access the dataset
RANDOMLY with another key.
2. We want to access ESDS file RANDOMLY based on key.
Steps Involved
Parameter Meaning
RELATE Relates AIX with base cluster
NONUNIQUE/ Duplicates are allowed / not allowed in alternate key.
Mainframe Refresher Part-1 Page:98
UNIQUE
KEYS Defines the length and offset of alternate key in base cluster
UPGRADE Adds the AIX cluster to the upgrade set of base cluster. Whenever base is modified, its
upgrade set is also modified. UPGRADE is default. NOUPGRADE didn’t add the AIX to
base cluster upgrade set.
RECORDSIZE Specifies the record size of alternate index record. It is calculated using the formula in
the next table.
Byte-1 Type of Cluster; X’00’ indicates ESDS and X’01’ indicates KSDS.
Byte-2 Length of base cluster pointers in alternate index; Primary key
length for KSDS and X’04’ for ESDS.
Byte-3 Half word binary indicates number of occurrences of primary key pointers in alternate index
Byte-4 record. X’0001’ for unique alternate key.
Byte-5 Length of alternate key.
Step2. BLDINDEX
Alternate index should have all the alternate keys with their corresponding primary key pointers.
After the AIX is defined, this information should be loaded from base cluster. Then only we can access the
records using AIX. BLDINDEX do this LOAD operation.
1. INFILE and OUTFILE points to Base Cluster and Alternate index Cluster.
If you want to give your own DDNAME files for sorting instead IDCUT1 and IDCUT2, inform it to
AMS by WORKFILE(DDNAME1, DDNAME2) parameter. Here, DDNAME1 and DDNAME2 are allocated
instead of IDCUT1 and IDCUT2.
Example:
PATHENTRY(MMA2.EMPMAST.SSN.AIX) -
UPDATE )
The order of build index and definition of PATH does not matter.
AMORG
This parameter, which stands for Access Method ORGanization, indicates that the particular DD
statement refers to a VSAM dataset.
BUFND
This parameter gives the number of I/O buffers needed for the data component of the cluster.
The size of each buffer is the size of the data CI.
The default value is two data buffers one of which is used only during CI/CA splits.
Therefore the number of data buffers left for normal processing is one.
If more data buffers are allocated, then performance of sequential processing will improve significantly.
BUFNI
This parameter gives the number of I/O buffers needed for the index component of the cluster.
Each buffer is the size of the index. This sub-parameter may be coded only for a KSDS because ESDS and
RRDS do not have index components. The default value is one index buffer.
If more index buffers are allocated, then performance of random processing will improve
significantly.
BUFSP
This parameter indicates the number of bytes for data and index component buffers. If this value
is more than the value given in the BUFFERSPACE parameter of the DEFINE CLUSTER, it overrides the
BUFFERSPACE. Otherwise BUFFERSPACE takes precedence. The value of BUFSP is calculated as
Mainframe Refresher Part-1 Page:101
However it is recommended not to code this parameter and let VSAM perform the calculations from the
BUFND and BUFNI values instead.
If SMS is active, then VSAM datasets can be created in JCL without using IDCAMS as below:
//KSDSFILE DD DSN=DEVI.CUST.MASTER,DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL,(10,10)),
// LRECL=100,KEYOFF=10,KEYLEN=12,RECORG=KS
RECORG can also be ES(for Entry Sequenced Datasets), RR(for Relative Record datasets) and LS(for Linear
Datasets). Other parameters of DEFINE CLUSTER will be assigned default values or you can additionally
mention SMS parameter, DATACLASS that is defined with predefined values.
DataBase 2
DB2
Mainframe Refresher Part-1 Page:102
Mainframe Refresher Part-1 Page:103
DB2 (Database 2)
History
IBM’s first database is IMS. This is a hierarchical database. IBM introduces its second base on relational
concepts in 1980s and it is called as Database 2 (DB2).
1.Increased Independency
If a new field is added to a file, the layout of the file should be changed in all the programs with
new field, though the programs do not use this field. But if a new column is added to a table, it does not
need any program change, as long as the programs do not need this field. Thus programs using Databases
are developed independent of physical structure.
2.Less Redundancy
In file system, the same data is stored in multiple files to meet the requirements of different
applications. In DB2, we can store the common information in one table and make all the applications to
share it. By means of centralized control and storing the fact at the right place and only once, data
redundancy is reduced.
4.Improved Security
In file system, all the records in the file are subjected to a specific access right. The access cannot
be controlled at field level or set level. But in DB2, we can restrict access on column level and set level.
Types of Database
Network Any entity can be associated with any other entity. So distinguishing between parent
and child is not possible. This is a linked structure model. Data stored in RECORD and different record
types are linked by SETS. Example: IDMS
Relational In mathematical terms, relation is TABLE. Data is stored in the form of tables consists of
Tuples (rows) and attributes (columns).
Example: DB2
DB2 Objects
There are two types of elements or objects in DB2.
Mainframe Refresher Part-1 Page:104
Data Objects: Objects that are created and used by the users.
Example: Tables, Indexes, Views, Table spaces, Databases, Storage Groups.
Storage
DASD001 DASD002 DASD003
Group 1
of columns and these columns cannot be updated. Individual partitions can be independently recovered
and reorganized. Different partitions can be stored in different groups.
DB2 Object-Database
It is not a physical object. It is a logical grouping consists of Table spaces,
Index spaces, Views, Tables etc. Whenever you create an object you have to explicitly say which Database
it belongs to or DB2 implicitly assigns the object to the right database.
In the creation of table, we should say in which database and in which table
Space we are housing the table (explicitly). In creating an index, we mention only the table name. DB2
decides the database from the base table name.
It can also be defined as a unit of start and stop. There can be a maximum of
65,279 databases in a DB2 Subsystem.
Physical hierarchy:
ROWID is a pointer to data record in the page.
It is a 4byte field. (3 bytes for page and 1 byte for line in the page)
Page consists of 1 to 127 data records. It is the unit of I-O.
Table space consists of pages and it is stored in STOGROUP.
Database consists of one or more table space and other related objects.
Leaf Pages
Data Pages
View of Non-clustered index – Diagram (non-leaf pages and data pages are shown)
SYNONYM ALIAS
Private object. Only the user who created it, Global object. Accessible by anyone.
can access it.
Used in local environment to hide the high Used in distributed environment to hide the location
level qualifier. qualifier.
When the base table is dropped, associated When base table is dropped, aliases are not dropped.
synonyms are automatically dropped.
SYSADM authority is not needed. To create an alias, we need SYSADM authority or
CREATEALIAS privilege.
DB2 Object-View
Views provide an alternative way of looking at the data in one or more tables.
A view is a named specification of a result table. For retrieval, all views can be used
like base tables. Maximum 15 base tables can be used in a view.
Advantages of view
1.Data security: Views allows to set-up different security levels for the same base
Table. Sensitive columns can be secured from the unauthorized Ids.
3.It can be used to hide complex queries. Developer can create a view that results
from a complex join on multiple tables. But the user can simply query on this view
as if it is a separate base table, without knowing the complexity behind the building.
4.It can be used for domain support. Domain identifies a valid range of values that a
column can contain. This is achieved in VIEW using WITH CHECK OPTION.
Program Preparation
SQL (Structured Query Language) is the language that is used to
Retrieve / update / delete DB2 data. SQL statements are embedded into COBOL
Program within the scope of ‘EXEC SQL and END-EXEC.’
DB2 Program is first feed to DB2 Pre compiler that extracts the DB2
statements into DBRM and replace the source program DB2 statements with COBOL CALL statements.
This modified source is passed to COBOL compiler and then link editor to generate load module. During
pre compilation, time stamp token is placed on modified source and DBRM.
Mainframe Refresher Part-1 Page:108
On the other side, DBRM undergoes binding process and DB2 Optimizes chooses the best access
path for the extracted SQL statements and store it in PLAN.
Advantages of Package:
1.When there is a change in sub program, it is enough to recompile
the subprogram and create the PACKAGE for that sub program. There is no need
for BIND PLAN.
2.Lck options and various bind options can be controlled at sub-program
level.
3.It avoids the cost of large bind.
4.It reduces Rebound time.
5.Versioning: Same package can be bounded with multiple programs with
different collection IDs.
COBOL-DB2 PROGRAM
DCLGEN Library (SYSIN) Pre-compiler Options
(SYSLIB) (PARM)
DSNHPC
Modified Source (SYSCIN)* Database Request
DB2 pre-compiler
Modules (DBRM)*
Mainframe Refresher Part-1 Page:109
COPYBOOK Library
(SYSLIB)
IGYCRCTL COMPILER Options IKJEFT01
COBOL COMPILER (PARM) (BIND PACKAGE)
Object Module
(SYSLIN) BIND
SUBROUTINE Library PARAMETERS
(SYSLIB) (SYSTSIN)
* Time Stamp token is passed from pre-compilation stage to Load module and Plan.
When first time the plan is accessed, the time stamp of plan is verified against the time stamp of
load module. If they match, then table will be accessed using the access path in PLAN and proceed
further. If they don’t match, then the program abnormally ends with SQLCODE of –818. It means the load
module and plan are out of sync. It usually occurs if we modify the program and pre-compile, compile and
link edit but did not bind the plan with latest DBRM produced in pre-compilation stage.
There is a modification in COBOL part. There is no change in any of the DB2 statements in the program. Is
binding necessary?
Yes. It is necessary. For COBOL changes, we have to compile and link edit.
For compilation we need pre-compiled source. So new time stamp is transferred to your load module
from the pre-compilation stage. If we don’t BIND it, timestamp mismatch is obvious and the program will
abnormally end.
Bind Card
BIND PACKAGE sub command is used to bind a DBRM to a package and BIND PLAN is used to
bind a DBRM to a plan or group of packages to a PLAN.
//SYSTSIN DD *
DSN
BIND PLAN(EMPPLAN)
MEMBER(EMPDBRM)
VALIDATE(BIND)
ISOLATION(CS)
RELEASE(COMMIT)
OWNER(SMSXL86)
LIB(‘SMSXL86.DB2.DBRMLIB’)
/*
VERSION. With packages, the pre-compiler option VERSION can be used to bind multiple versions of the
programs into package.
CURSOR STABILITY (CS)– As the cursor moves from the record in one page to the record in next page, the
lock over the first page is released (provided the record is not updated). It avoids concurrent updates or
deletion of row that is currently processing. It provides WRITE integrity.
Mainframe Refresher Part-1 Page:111
REPEATABLE READ (RR) – All the locks acquired are retained until commit point. Prefer this option when
your application has to retrieve the same rows several times and cannot tolerate different data each time.
It provides READ and WRITE integrity.
UNCOMMITTED READ (UR) – It is also known as DIRTY READ. It can be applied only for retrieval SQL. There
are no locks during READ and so it may read the data that is not committed. Highly dangerous and use it
when concurrency is your only requirement. It finds its great use in statistical calculation of the large table
and data-warehousing environment.
VALIDATE (BIND) – If there is any privilege or object-not-found issue, then produce ERROR message and
create the package only if SQLERROR(CONTINUE) is coded in bind card. The statement in error will not be
executable.
REBINDING
Mainframe Refresher Part-1 Page:112
When SQL statements are not changed but a new index is added or RUNSTATS is run, then it is
advisable to do a REBIND for the best possible access path. REBIND PLAN is cheaper than BIND with
ACTION (REPLACE).
Host Variables
DB2 is separate subsystem. As DB2 data are stored in external address space, you cannot directly
modify or read from your program. During read, the DB2 values are retrieved into your working storage
variables. During update, the DB2 columns are updated using your working storage variables. These
working storage variables used for retrieving or updating DB2 data should be of same size of DB2
columns. They are called as host variables as they are defined in the host language (COBOL). Host
variables are prefixed with colon ( : ) in the embedded SQL.
DCL generated host variable names are same as DB2 column names.
As underscore is not a valid character for variable names in COBOL, it is replaced by hyphen in host
variable generation of DCLGEN. Prefix and suffix can be added to all the variables while creating the
DCLGEN copybook.
Mainframe Refresher Part-1 Page:113
Host variables can be declared in working storage section. But they cannot be stored in
copybooks as other file layouts.
INCLUDE is expanded during pre-compilation time but COPY is expanded during compilation and
so declaration of host variable in copybook will produce errors during pre-compilation.
DECLARE TABLE, that is table structure of DCLGEN is NOT really needed for pre-compilation. But
if it is used, then any misspelled table name, column names are trapped in pre-compilation stage itself.
DB2 need not be up during pre-compilation. As pre-compiler just extracts the DB2 statements
and produce DBRM, it does not need DB2 connection. But DB2 region should be up for binding as the
optimizer builds access path in this stage from catalog information.
_______________________________________________________________________________
| |
| DSNEDP01 DCLGEN SSID: DSN |
| ===> |
| |
| Enter table name for which declarations are required: |
| 1 SOURCE TABLE NAME ===> DSN8410.EMPTABLE (Unqualified table name) |
| 2 TABLE OWNER ===> (Optional) |
| 3 AT LOCATION ..... ===> (Optional) |
| |
| Enter destination data set: (Can be sequential or partitioned) |
| 4 DATA SET NAME ... ===> ‘SMSXL86.DB2.INCLUDE(EMPTABLE)’ |
| 5 DATA SET PASSWORD ===> (If password protected) |
| |
| Enter options as desired: |
| 6 ACTION .......... ===> ADD (ADD new or REPLACE old declaration) |
| 7 COLUMN LABEL .... ===> NO (Enter YES for column label) |
| 8 STRUCTURE NAME .. ===> (Optional) |
| 9 FIELD NAME PREFIX ===> (Optional) |
| 10 DELIMIT DBCS .... ===> YES (Enter YES to delimit DBCS identifiers) |
| 11 COLUMN SUFFIX ... ===> NO (Enter YES to append column name) |
| 12 INDICATOR VARS .. ===> NO (Enter YES for indicator variables) |
| |
| |
| PRESS: ENTER to process END to exit HELP for more information |
| |
|__________________________________________________________________________________|
Mainframe Refresher Part-1 Page:114
st st
Limit of Date: Jan 1 1 ad – Dec 31 9999 AD
Limit of Time: 000000 – 240000
Limit of Time Stamp: 00010101000000000000 – 00001231240000000000
SQLCA
SQLCA is SQL Communication area. It is a DB2 copybook that should be included in all the DB2
programs. The fields declared in the copybook are updated for every DB2 query. The Length of SQLCA is
136. The most important field in this copybook is SQLCODE. The success or failure of DB2 query can be
checked in this field.
So it is common programming practice that the SQLCODE of every query must be verified for
valid values after the execution of the query. If the SQLCODE value is not acceptable, then the control is
transferred to ABEND routine that would end the program with proper error messages.
SQLERRD (3) contains the number of rows affected by a DB2 INSERT/DELETE operation. If the
operation is DELETE, this contains number of rows deleted after the execution of the query.
WHENEVER statement
WHENEVER is a error-trapping statement that directs the processing to continue or branch to an
error handling routine based on the SQLCODE returned for the statement. When it processed, it applies to
all the subsequent SQL statements issued by the application program.
EXEC SQL
WHENEVER condition action
Mainframe Refresher Part-1 Page:115
END-EXEC.
It is almost always safe to code specific SQLCODE checks after each SQL statement and process
accordingly. Avoid using WHENEVER.
01 ERROR-MESSAGE.
05 ERROR-LEN PIC S9(04) COMP VALUE +1320.
05 ERROR-TEXT PIC X(132) OCCURS 10 TIMES.
Components of DB2
DB2 internal structure is very complex and contains large number of components. But from a
high-level point of view, DB2 can be considered to have four major components.
System Services component: Supports system operation, operator communication, logging and similar
function.
Locking services component: Provides the necessary controls for managing concurrent access to data.
Database services component: Supports the definition, retrieval and update of user and system data.
Before get into SQL, let us briefly see the sub- components of Database services component.
Runtime supervisor:
It is resident in the main memory when the application program is executing. Its job is to oversee
that execution. When the program requests some database operation to be performed, control first goes
to the runtime supervisor, which uses the control information in the application plan to request the
appropriate on the part of the Data Manager.
Catalog and Directory are also part of Database services component only.
SQL
SQL is fourth generation language. The definition of fourth language is ‘Tell the need. System will
get it done for you ‘. There is no need to instruct the method to get it.
For example, I want list of employees working currently in Malaysia. If the data is in file, then I
have to declare, define, and Open the file. Then I should read all the records into my working storage one
by one and if their location is Malaysia, I display them. Finally I close the file.
If the data is in DB2, I would simply write a query (SELECT * FROM table where
location=’Malaysia’’) and DB2 optimizer do everything for me in identifying the best access path. No
worries of DECLARE, DEFINE, OPEN, READ and OMIT stuffs. That’s the power of fourth generation
language and that makes the programmer life easy!!
DDL-CREATE
This statement is used to create DB2 objects.
General Syntax CREATE object object-name parameters
Table creation Sample CREATE TABLE table-name
(Column definitions,
Primary Key definition,
Foreign Key definition,
Alternate Key definition,
LIKE table-name /View-name,
IN DATABASE-NAME.TABLESPACE-NAME)
DDL-Column Definition
Define all the columns using the syntax:
Column-name Data-type Length (NULL/NOT NULL/ NOT NULL WITH DEFAULT)
Column-name can be of maximum length 30. It should start with an alphabet and it can contain
numbers and underscore.
NULL means UNKNOWN, if the value is not supplied during an insertion of a row, then NULL will be
inserted into this column.
NOT NULL means, value for this column should be mentioned when inserting a row in the table. NOT
NULL with DEFAULT means, if the value for this column is not supplied during an insertion, then
based on type of the column default values will be moved into the table. Default values are listed in
the below table.
If the PRIMARY KEY is single column, then it can be coded along with column definition. If the
primary key is composite key (more than one column), then it can be defined after the column definition.
Primary key definition can be added or dropped later using ALTER table.
The definition of primary key is complete only after unique index is created on it. Until that time,
the table is unavailable for use. If the primary key is added using ALTER command, then unique index on
the key column(s) must already be available.
There must be a value in parent table (primary key) for every non-null value in child table
(foreign key). Foreign key can be defined along with column definition or separately after the definition of
all the columns.
Delete Rule
Delete rule defines what action needs to be taken on child table when there is a deletion in
primary table. The three possibilities are below:
CASCADE: Child table rows referencing parent table will also be deleted.
RESTRICT: Cannot delete any parent row when there is reference in child table.
SET NULL: SET the foreign key value as NULL when the respective primary row is deleted.
Mainframe Refresher Part-1 Page:118
Insert and Update rules cannot be defined. But they can be implemented using TRIGGERS.
CHECK clause and the optional clause CONSTRAINT (for named check constraints) are used to
define a check constraint on one or more columns of a table.
A check constraint can have a single predicate, or multiple predicates joined by AND or OR. The first
operand of each predicate must be a column name, the second operand can be a column name or a
constant, and the two operands must have compatible data types.
Although CHECK IS NOT NULL is functionally equivalent to NOT NULL, it wastes space and is not
useful as the only content of a check constraint. However, later if you want to remove the restriction that
the data be Non-null, you must define the restriction using the CHECK IS NOT NULL Clause.
DDL-Index creation
Table spaces should be created before creating the table. But index spaces are automatically
created with creation of index. So create index command provides optional parameters of USING
STOGROUP, PRIQTY, SECQTY, FREEPAGE and PCTFREE etc. for the allocation of index space. But usually we
don’t mention these parameters and allow the system to allocate it in the right place with respect to table
space.
Creating unique index on a NULL column is possible if there is only one NULL is available in that
column.
WITH CHECK OPTION ensures that all the inserts and updates made to the base table using this
view satisfies the limit imposed by the where condition of the sub-query. (Domain Integrity)
This view shows name and id of all the employees who knows DB2.
‘WITH CHECK OPTION’ ensures that all the inserts made to base table using the view DB2GROUP, must
have DB2 as SKILLSET. Any update-attempt to change the value of SKILLSET from DB2 to anything else
using the view DB2GROUP is restricted.
DDL-ALTER TABLE
When you create a table using model table, the columns are defined in the new table as in the
model table. But the PRIMARY, FOREIGN KEY definitions are not inherited. We have to define them using
ALTER TABLE. Before defining primary key using ALTER TABLE, there should be unique index.
Using ALTER statement, alternate keys cannot be defined. Other than that we can add columns,
constraints, checks & DROP primary key.
When a new column is added with NOT NULL WITH DEFAULT, then the value for the column for all
the rows already exist in the table is filled based on the type of column:
1. Numeric –Zero
2. Char, Varchar -Spaces
3. Date -01/01/0001
4. Time -00:00 AM
Using ALTER command, we can extend the length of VARCHAR/CHAR items, switch the data-type of a
column within character data-types (CHAR/VARCHAR);numeric data
types(SMALLINT,INTEGET,REAL,FLOAT,DOUBLE,DECIMAL) and within graphical
datatypes(GRAPHIC,VARGRAPHIC).
Mainframe Refresher Part-1 Page:121
DDL-DROP
DROP deletes the table definition in addition to all the rows in it. You also lose all synonyms,
views, indexes, referential and check constraints associated with that table. Plans and Packages are
deleted using the command FREE.
DML-SELECT
SELECT statement is the heart of all queries and it is specifically used for retrieving information.
As a primary statement to retrieve the data, it is the most complex and most complicated DML statement
used. Six different clauses can be used with a SELECT statement and each of these clauses has its own set
of predicates. They are FROM-WHERE-GROUPBY-HAVING-UNION and ORDER BY.
Syntax: SELECT columns FROM tables
WHERE conditions
GROUP BY columns
HAVING conditions
ORDERBY columns
Up to 750 columns can be selected. 15 sub-queries can be coded in addition to one main query.
WHERE Clause
It is always followed by a search condition that contains one or more predicates that define how
the DB2 DM is to choose the information that will be contained in the result dataset produced.
Any relational operator can be coded. (<>, >. < , = ,<=, >=)
DML-SELECT-WHERE-LIKE condition
LIKE is used for pattern search. ‘%’ is a wild card for any number of zero or more characters and
‘_’ is used to indicate single unknown character.
If you want to look for % in the string, then you should define ESCAPE character. Ex: WHERE col1
LIKE ‘MUTHU_+%SARA%’ ESCAPE ‘+’
This will look for a string that starts with ‘MUTHU_%SARA’ where _ can be any character.
DML-SELECT-WHERE-BETWEEN and IN
Use BETWEEN to check the value of column is within the range. The lower and upper boundaries
are INCLUSIVE. Use IN to check the value of column against a Values list.
Mainframe Refresher Part-1 Page:122
DML-SELECT-WHERE-ANY/SOME/ALL
SELECT…WHERE COLUMN1 > ANY|ALL|SOME (Sub-Query)
ALL - If the value of COLUMN1 is greater than all the values return by sub-query, then only the
outer table row will be selected. If no rows are returned by sub-query then all the rows of outer table will
be selected.
ANY and SOME – If COLUMN1 value is greater than one of the values return by sub-query, then
the outer table row will be selected.
DML-SELECT-WHERE-EXIST
This is useful when you want to just check whether one or more rows exist.
Syntax: WHERE EXISTS (sub-query)
Your main query will return result only if at least one row exists for your sub query. NOT EXISTS
check for unavailability of any rows for the search condition in the sub query.
DML-SELECT-GROUP BY
Use GROUP BY for grouping rows by values of one or more columns. You can then apply column
function for each group. Except for the columns named in the GROUP BY clause, the SELECT statement
must specify any other selected columns as an operand of one of the column functions.
If a column you specify in the GROUP BY clause contains null values, DB2 considers those null
values to be equal. Thus, all nulls form a single group.
You can also group the rows by the values of more than one column
DML-SELECT-ORDER BY
The ORDER BY clause is used to sort and order the rows of data in a result dataset by the values
contained in the column(s) specified. Default is ascending order (ASC). If the keyword DESC follows the
column name, then descending order is used. Integer can also be used in place of column name in the
ORDER BY clause.
DML-SELECT-CONCAT
CONCAT is used for concatenating two columns with the string you want in between.
To concatenate the last name and first name with comma in between,
FROM DSN8410.EMP;
Column function receives a set of values from group of rows and produces a single value. SCALAR function
receives one value and produces one value.
COLUMN FUNCTION:
1. DISTINCT can be used with the SUM, AVG, and COUNT functions. The selected function operates on
only the unique values in a column.
2. SUM and AVG cannot be used for non-numeric data types whereas MIN, MAX and COUNT can.
SCALAR FUNCTION:
CURSOR
CURSOR is useful when more than one row of a table to be processed. It can be loosely
compared with sequential read of file. Usage of cursor involves four steps.
1.DECLARE statement.
This statement DECLARES the cursor. This is not an executable statement.
Syntax: DECLARE cursor-name CURSOR [WITH HOLD] FOR your-query
[FOR UPDATE OF column1 column2 | FOR FETCH ONLY]
2.OPEN statement.
This statement just readies the cursor for retrieval. If the query has ORDER BY or GROUP BY
clause, then result table is built. However it does not assign values to the host variables.
Syntax: OPEN cursor-name
3.FETCH statement.
It returns data from the results table one row at a time and assigns the value to specific host
variables.
Syntax: FETCH cursor-name INTO
:WS-Column1
:WS-Column2
The number of INTO variables should be equal to SELECT columns of your DECLARE cursor statement. If
FOR UPDATE OF clause is coded, then while fetching the row, the exclusive lock is obtained over the page
of the row. FETCH Cursor is usually placed in the perform loop that will be executed until the SQLCODE is
100.SQLCODE will be set to 100 when end of cursor is reached.
If FOR UPDATE OF clause is given, then all the columns that are going to be updated using the
cursor should be mentioned in this clause. If you don’t mention FOR UPDATE OF clause, you can update
any number of columns using WHERE CURRENT OF cursor-name but you will be getting the exclusive lock
only during the UPDATE statement and there are chances for the row to be locked exclusively by another
task in between your READ and UPDATE.
So it is suggested to use FOR UPDATE OF clause when you are using the cursor for update
purpose.
4.CLOSE statement.
It releases all resources used by the cursor. If you don’t close the cursor, COMMIT statement will
close the cursor. To retain the cursor in OPEN stage during COMMIT, Use WITH HOLD option in the
DECLARE statement of the CURSOR. This option will be effective only in batch environment. ROLLBACK
close all the cursors including the cursors defined with ‘WITH HOLD’ option.
Syntax: CLOSE cursor-name.
DML-INSERT
INSERT statement is used to insert rows to the table. NOT NULL Column values should be
supplied during INSERT. Otherwise INSERT would fail.
Mainframe Refresher Part-1 Page:125
2.Mass Insert. Another table or view contains the data for the new row(s).
INSERT INTO TELE
SELECT LASTNAME, FIRSTNME, PHONENO
FROM DSN8410.EMP
WHERE WORKDEPT = 'D21';
If the INSERT statement is successful, SQLERRD(3) is set to the number of rows inserted.
DML-UPDATE
UPDATE statement is used to modify the data in a table. The SET clause names the columns you
want to update and provide the values you want them changed to. The condition in the WHERE clause
locates the row(s) to be updated. If you omit the WHERE clause, DB2 updates every row in the table or
view with the values you supply.
If DB2 finds an error while executing your UPDATE statement (for instance, an
update value that is too large for the column), it stops updating and returns error codes in the SQLCODE
and SQLSTATE host variables and related fields in the SQLCA. No rows in the table change (rows already
changed, if any, are restored to their previous values). If the UPDATE statement is successful, SQLERRD(3)
is set to the number of rows updated.
Syntax:
UPDATE table-name SET column1 =value1, column2 =value2 [WHERE condition];
DML-DELETE
DELETE statement is used to remove entire rows from a table. The DELETE statement removes
zero or more rows of a table, depending on how many rows satisfy the search condition you specified in
the WHERE clause. If you omit a WHERE clause from a DELETE statement, DB2 removes all the rows from
the table or view you have named. The DELETE statement does not remove specific columns from the
row. SQLERRD(3) in the SQLCA contains the number of deleted rows.
Syntax: DELETE FROM table-name [WHERE CONDITION]
DML – NULLS
One of the 12 CODD Rules for relation database system is ‘ NULL values are supported for
representing missing information in a systematic way irrespective of the data type’. DB2 supports NULL
values.
IS NULL is the right way of coding. If GROUPBY is done on a NULL column, then all the columns whose
value is unknown (NULL) forms one GROUP.
Example, If QUALIFICATION is a column defined with NULL attribute in EMPTABLE, then SQL for
retrieving all the employees whose QUALIFICATION is not yet known is:
SELECT EMPNAME,QUALIFICATION FROM EMPTABLE
WHERE QUALIFICATION IS NULL.
High-level languages don’t have any NULL concept. So if the column is NULL, then the host
variable corresponds to that column should be set to zero (numeric) or spaces (non-numeric). This can be
done in the programming. But for doing this we should know whether the column is NULL or NOT. NULL
indicators are used for this purpose. NULL indicator is a 2 byte field (S9(4) COMP). Negative value,–1 in
NULL indicator field indicate that the column is NULL.
EXEC SQL
SELECT QUALIFICATION
INTO :WS-QUALIFICATION :WS-QUALIFICATION-NULL
FROM EMPTABLE
WHERE EMPID=2052
END-EXEC
IF SQLCODE = 0
PERFORM 1000-CHECK-FOR-NULLS
….
100-CHECK-FOR-NULLS.
IF WS-QUALIFICATION-NULL < 0 THEN
MOVE SPACES TO WS-QUALIFICATION
END-IF.
If QUALIFICATION of EMPID = 2052 is NULL and if you didn’t code null indicator, then the query
will fail with SQLCODE –305 and the error message corresponding to this code is ‘THE NULL VALUE
CANNOT BE ASSIGNED TO OUTPUT HOST VARIABLE NUMER posit-num BECAUSE NO INDICATOR VARIABLE
IS SPECIFIED ‘
This kind of NULL check (100-CHECK-FOR-NULLS) is highly recommended for numeric fields.
Otherwise the program may abnormally end at some place down the line, when the field is used for some
arithmetic operation.
Instead of NULL indicator, VALUE function can also be used.
SELECT VALUE(QUALIFICATION,’ ‘)
INTO :WS-QUALIFICATION
FROM EMPTABLE
WHERE EMPID=2052
If QUALIFICATION is NULL, then ‘ ‘ will be moved to WS-QUALIFICATION.
Just before INSERT or UPDATE move –1 to NULL indicator variable and use this variable along
with host variable for the column to be inserted/updated.
Once –1 is moved to null indicator, then independent of value presence in the host variable, NULL will be
loaded. In the following query, though ‘B.E’ is moved to host variable, it will not be loaded into the table
as null indicator has –1. It should have been set to 0 before loading.
MOVE –1 TO WS-QUALIFICATION-NULL.
Mainframe Refresher Part-1 Page:127
It is common feeling that NULL provides more trouble than benefit. So it is always better to
specify NOT NULL or NOT NULL WITH DEFAULT for all the columns.
Syntax:
GRANT access ON object TO USER-ID | PUBLIC [WITH GRANT OPTION].
REVOKE access ON object FROM USER-ID | PUBLIC.
Example:
GRANT SELECT, UPDATE ON EMPTABLE TO SMSXL86.
GRANT ALL ON EMPTABLE TO SMSXL86.
REVOKE CREATE TABLE, CREATE VIEW FROM SMSXL86.
REVOKE INSERT ON EMTABLE FROM SMSXL86.
All the changes made to the database since the initiation of transaction, are made permanent by
COMMIT. ROLLBACK brings back the database to the last committed point.
Syntax:
EXEC SQL COMMIT END-EXEC
EXEC SQL ROLLBACK END-EXEC
If the program is updating one million records in the table space and it abnormally ends after
processing ninety thousand records, then the issued ‘ROLLBACK’ brought the database back to the point
of transaction initiation.
The restart of the program must have to process ninety thousand successful-but-not-committed updates
once again. The repeated cost occurred is due to Bad design of the application.
If the program is expected to do huge updates, then commit frequency has to be chosen
properly. Let us say, after careful analysis, we have designed our application COMMIT frequency as
th
thousand records. If the program abnormally ends while processing 1500 record, then the restart should
st
not start from first record but from 1001 record. This is done using restart logic.
Create one temporary table called RESTARTS with a dummy record and inserts one record into
the table for every commit with key and occurrence of commit. This insertion should happen, just BEFORE
the issue of COMMIT.
First paragraph of the procedure should read the last record of the table and skipped the records
that are already processed and committed (1000 in the previous case). After the processing of all the
records (one million), delete the entries in the table and issue one final COMMIT.
JOINS
Most of the times, the complete information about an entity is retrieved from more than one
table. Retrieving information from more than one table can be done in two ways. One method is JOIN
and the other method is UNION. We have already discussed about UNION. It is used to get information
about more entities. In other words, it returns more rows. JOIN is used to get detail information about
entities. In other words, it returns more columns.
There are two kinds of JOIN. Inner join returns rows from two or more tables based on matching
values. Outer join returns rows from tow or more tables independent of matching or non-matching.
JOIN: INNER
Two or more tables are joined together using the column having equal values among them.
EMPTABLE SALTABLE
EMP_ID EMP_NAME DESIG DESIG SALARY
100 MUTHU TL SSE 400000
101 DEVI SSE SE 300000
EMPTABLE.DESIGNATION = SALTABLE.DESIGNATION
Result
DEVI 400000
Since there is no TL designation in the SALTABLE, MUTHU will not appear in the output.
Result
DEVI 400000
---- 300000
Sub-queries
Sub-Queries are nested SELECT statements. Sub-query enables a user to base the search criteria
of one SELECT on the result of another SELECT statement.
It is always part of a predicate.
Mainframe Refresher Part-1 Page:130
Sub-queries can appear in the predicates of other sub-query. This is called nested sub-query and
the nesting is possible up to 15 levels.
Usually sub-query executes only once and it is executed first and the value returned by sub-query
will be used for main query. This kind of sub-query is called as un-correlated sub-query. When the sub-
query refers to the table referred in the main-query then the sub-query is executed for every execution of
main-query and this kind of query is called correlated sub-query. Correlated sub-queries cannot be used
for update/insert/delete purpose.
Example:
The following query lists the employees who get more than the average salary of their
department.
SELECT EMPNAME,DEPTNUM,SALARY
FROM EMPTABLE
WHERE SALARY > (SELECT AVG(SALARY)
FROM DEPTNUM
WHERE EMPTABLE.DEPTNUM=DEPT.DEPTNUM)
To use an index:
1. One of the predicates for the SQL statement must be index-able.
2. One of the columns (in any index-able predicate) must exist as column in an available index.
Example: The primary key of the table TASKTAB is a composite key with columns CLIENT_ID, PROJECT_ID,
MODULE_ID.
If only CLIENT_ID and MODULE_ID is given then direct index look-up is not possible. Index scan would
occur.
Mainframe Refresher Part-1 Page:131
Query Parallelism
This is another technique that can be applied by the optimizer is query parallelism. When
parallelism is invoked, an access path can be broken up into parallel groups. Each parallel group
represents a series of concurrent operations with the same degree of parallelism. Degree of parallelism
refers to the number of concurrent tasks used to satisfy the query.
Filter factor
Filter factor is a ratio that estimates I/O costs. The optimizer calculates the filter factor for a
query’s predicates based on the number of rows that will be filtered out by the predicates. That is, if the
predicate is most restrictive, the filter factor would be low, the I-O cost would be less and the query will
be more efficient.
For an indexed column, FIRSTKEYCARDF column of SYSIBM.SYSINDEXES consists of number of distinct
values in the column.
EXPLAIN
We have already seen that DB2 optimizer chooses the access path for the query. If we want to
know what access path DB2 chose during the plan preparation, then the request should be placed to DB2.
The request can be done two ways:
Method 2: Use the following command directly in the program or in SPUFI or QMF.
Syntax: EXPLAIN ALL SET QUERYNO=integer FOR SQL-statement.
Before posting the request, there should be a PLAN_TABLE under the user-id, based on model
SYSIBM.PLAN_TABLE. PLAN_TABLE is a standard table that must be defined with predetermined columns,
data types and lengths. During bind process, DB2 optimizer briefs the access path chose by it in the
PLAN_TABLE.
If you want to query the access path for single query then use the query below:
SELECT * FROM PLAN_TABLE WHERE QUERYNO=integer OREDERBY QBLOCKNO, PLANNO.
Mainframe Refresher Part-1 Page:133
Now the access path taken by the optimizer is loaded into PLAN_TABLE. One should know the
meaning of PLAN_TABLE columns and values to understand the access path. DB2V5 has 46 columns in
PLAN_TABLE.
DYNAMIC SQL
Static SQL is embedded in application program and the only values that can change are the
values of the host variables in the predicates. Dynamic SQL are characterized by the capability to change
columns, tables and predicates during a program’s execution.
Advantages: Flexibility and best access path (as the bind happens at the run time using latest
RUNSTATS information)
Disadvantage: Slow as the runtime is bind time + execution time.
1.EXECUTE IMMEDIATE:
Move the SQL statement to be executed into the host variable and issue execute immediate
command.
01 WS-HOST.
49 WS-HOST-LENGTH PIC S9(04) COMP.
49 WS-HOST-VAR PIC X(40).
MOVE +40 TO WS-HOST-LENGTH
MOVE “SET EMP_NAME = ‘MUTHU’ WHERE EMP_NO=2052” TO WS-HOST-TEXT.
EXEC SQL EXECUTE IMMEDIATE: WS-HOST-VAR END-EXEC.
Disadvantages:
1.It cannot be used for SELECT.
2.Executable form of the SQL will be deleted once it is executed.
Form: 1
MOVE +40 TO WS-HOST-LENGTH
MOVE “SET EMP_NAME = ‘MUTHU’ WHERE EMP_NO=2052” TO WS-HOST-TEXT.
EXEC SQL PREPARE RUNFORM FROM :WS-HOST END-EXEC.
EXEC SQL EXECUTE RUNFORM END-EXEC.
Form: 2
Parameter markers can be used in place of constant values. This acts like placeholder for the host
variables in the SQL.
MOVE +40 TO WS-HOST-LENGTH
MOVE “SET EMP_NAME = ‘MUTHU’ WHERE EMP_NO=?” TO WS-HOST-TEXT.
EXEC SQL PREPARE RUNFORM FROM :WS-HOST END-EXEC.
MOVE 2052 TO WS-EMP-NUM
EXEC SQL EXECUTE RUNFORM USING :WS-EMP-NUM END-EXEC.
Disadvantage:
Mainframe Refresher Part-1 Page:135
Disadvantage:
1.Table name cannot be changed. Number of columns cannot be modified during run time.
The fourth type of dynamic SQL known as ‘varying-list select’ provide hundred percent flexibility
where the number of columns and even the table we are accessing can be changed during run time. This
uses the copybook SQLDA for its purpose.
INTEGRITY
Integrity means the accuracy, correctness or validity of data contained in the database. Maintaining
integrity is not an easy task in a multi user environment. So the task of maintaining integrity is handled by
the system than the user.
Domain Integrity.
It ensures that a value in a column is a member of column’s domain or legal set of values. Simple
example is, alphabetic data on the integer column is restricted.
Entity Integrity.
It means every row in a table is unique. To ensure entity integrity, developer has to define a set
of column(s) as primary key.
Referential Integrity.
It ensures the data integrity between the tables related by Primary (Parent) and Foreign (Child)
keys.
Mainframe Refresher Part-1 Page:136
DB2 allows more than one application to access the same data at essentially the same time. This is
known as concurrency. Concurrency results the following problems.
It arises when a transaction is allowed to retrieve (update) a row that has been updated by
another transaction and has not yet been committed by the other transaction.
Time Transaction-A Transaction-B
T0 Update row R1.
T1 Read and Update row R1.
T2 Rollback
Transaction-B updates row R1 based on the uncommitted change done by Transaction-A.
Transaction-B rolled back its changes.
3.Data inconsistency.
Let us say there is 2 account A1,A2 and account A3 should have sum of amounts in A1 and A2.
Say A1 = 1000 A2 = 2000 A3=3000
Time Transaction-A Transaction-B
T0 Read row A1.(1000)
T1 Read row A1 and update to 2000.
T2 Update row A2.(3000)
T3 Calculate A3 and update. (4000)
T4 Commit Commit
Now the value of A1=2000, A2=3000 but A3=4000 == > Data inconsistent as A3 is expected to be
5000 as per design.
Mainframe Refresher Part-1 Page:137
Locking
Locking solves the concurrency issues described above. Locking prevent another transaction to
access the data that is being changed by the current transaction. Three main attributes of lock are mode,
size and duration.
Exclusive (X) – The lock owner can read or change the locked page. Concurrent processes cannot acquire
ANY lock on the page nor they access the locked page.
Update (U) – The lock owner can read but cannot change the locked page. However the owner can
promote the lock to ‘X’ and update. Processes concurrent with the U
lock can acquire ‘S’ lock and read the page but another ‘U’ lock is not possible.
Share (S) - The lock owner and any concurrent processes can read but not change the locked page.
Concurrent processes can acquire S or U locks on the page.
The above three are with respect to pages. Three more kind of locks are possible at table /table space
level. They are: Intent Share (IS), Intent Exclusive (IX) and Share/Intent Exclusive (SIX)
LOCK Issues
Locking is introduced to avoid concurrency issues. Locking resulted suspension, timeout and deadlock
problems. But LOCK is needed for data integrity.
Suspension.
IRLM suspends an application process if it requests a lock on an object that is already owned by
another application process and cannot be shared. The suspended process is said to be in ‘Wait Stage’ for
the lock. The process resumes when the lock is available.
Timeout.
When the object is in wait stage more than predefined time, then the process (program) is
terminated by DB2 with SQL return code –911 or –913 meant for TIMEOUT. The IRLMRWT of DSNZPARM
determines the duration of the wait time.
Deadlock.
Mainframe Refresher Part-1 Page:138
When two or more transactions are in simultaneous wait stage, each waiting for one of others to
release a lock before it can proceed, DEADLOCK occurs.
If deadlock occurs, transaction manager of DB2 breaks it by terminating one of the transactions
and allows the other to process. Later, the application programmer will restart the terminated
transaction.
Initially latches are used to lock only DB2 index pages and internal DB2 resources. DB2 V3 uses
latching more frequently for data pages also. Latches are preferred when a resource serialization is
required for a short time. Locks and Latches guarantee data integrity at the same level.
Lock Promotion
When lock is promoted from lower level to upper level, it is called lock promotion. DB2 acquire
‘U’ lock to update a row. But at the same concurrent processes can access the row in ‘S’ lock. During
update, it needs ‘X’ lock and to get the ‘X’ lock, it waits for concurrent processes to release ‘S’ locks. It
promotes the current lock from ‘U’ to ‘X’ and this is called LOCK PROMOTION ON MODE. (‘U’ – Update in
Pending and ‘X’ – Update in Progress)
When the number of page locks exceeds predefined limit, it is promoted to table or table space
level and this is LOCK PROMOTION ON SIZE.
Lock Strategy
DB2 decides the lock to be applied based on the following:
1. Lock size declared at the time of table space creation.
2. Type of SQL statement – SELECT or UPDATE
3. Explicit LOCK statement in the program.
4. ACQUIRE and RELEASE option chosen by user at the BIND time.
5. Isolation level specified at bind time.
6. The NUMLKTS and NULLKUS limit.
Mainframe Refresher Part-1 Page:139
Normalization
Data Normalization describes the process of designing a database and organizing data to take
best advantage of relational database principles. It is the process of putting one fact in one appropriate
place. This optimizes the updates at the expense of retrievals.
When a fact is stored in only one place, retrieving many different but related facts usually
requires going to many different places. This tends to slow the retrieval process but update is easy and
faster as the fact you are updating exists in only one place.
The process involves five levels. Tables are usually normalized till level three.
Un normalized Data
In the fourth level, multi-valued dependencies are removed and in the fifth level, remaining anomalies are
removed.
De-normalization
De-normalization is the process of putting one fact in more than one place. It is the reverse
process of normalization. This will speed up the retrieval process at the expense of data modification. De-
normalization is not a bad decision when a completely normalized design is not performing optimally.
Mainframe Refresher Part-1 Page:140
Prior to Version5, there was an additional database called Communication Database (CDB) was
used for establishing and documenting distributed DB2 connections. In the version 5, it has been renamed
and rolled into DB2 catalog.
Each and every table has its own importance. So explaining all the tables and the columns in it is
highly impossible. Refer the query section to know about some of the frequently used queries on SYSIBM
tables.
2. When a DBRM is bound to PLAN, all the SQL statements are placed into SYSSTMTDB2 table. When a
DBRM is bound to PACKAGE, all of its SQL statements are placed into SYSPACKSTMT table.
Information about the DBRMS that were bound to PLAN or PACKAGE, are stored in SYSDBRM table.
DBRM just created but not yet bound is not registered anywhere. (Remember, pre-compiler don’t use
DB2 at all and DBRM is an output of pre-compiler)
5. DB2 Catalog stores only information about the PLAN. The executable form of PLAN, called Skeleton
cursor table (SKCT), is stored in the DB2 directory in the SYSIBM.SCT02 table.
6. Information about Table space/ Table and Indexes are stored in the following
Tables.
SYSTABLESPACE
SYSTABLES SYSTABLEPART
SYSCOLDISTSTATS
SYSTABSTATS
SYSINEXSTATS
Triggers (Available in version 6)
Mainframe Refresher Part-1 Page:141
Nested Triggers
A trigger can also contain insert, update, and delete logic within itself. Therefore, a trigger is fired
by a data modification, but can also cause another data modification, thereby firing yet another trigger.
When a trigger contains insert, update, and/or delete logic, the trigger is said to be a nested trigger. Most
DBMSs, however, place a limit on the number of nested triggers that can be executed within a single firing
event. If this were not done, it could be quite possible to having triggers firing triggers ad infinitum until
all of the data was removed from an entire database!
Trigger in place of RI
Triggers can be coded, in lieu of declarative RI, to support ALL of the RI rules.
We can specify only ON DELETE rules in the DDL statement. UPDATE and INSERT rules of RI can be
implemented using triggers.
Sample Trigger:
The trigger executes once for each row. So if multiple rows are modified by a single update, the
trigger will run multiple times, once for each row modified. Also, the trigger will be run BEFORE the actual
modification occurs. Finally, take special notice how NEW and OLD are used to check values before and
after the update.
DB2 Utilities
Most of the time, application programmer doesn’t need any knowledge on DB2 utilities. Backup,
Reorganization, Recovery and maintenance of database are taken care by the DBA of the project.
DSNUPROC is the DB2 catalogued procedure that executes the program DSNUTILB.
DSNUTILB is a master program and it calls other programs based on the first word of control card. The
first word of control card should be utility that needs to be invoked.
Most of the DB2 Utility programs are divided into four major categories.
Utility Purpose
COPY It is used to create image copy backup dataset for a complete table space or a
(Backup and Recovery) single partition of a table space. It can be of type FULL or incremental. Based
on number of modified pages after the previous backup, prefer FULL or
incremental image copy. Successful copy details are loaded in
SYSIBM.SYSCOPY.
MERGECOPY It is used to create full image copy from incremental image copies.
(Backup and Recovery)
QUIESCE It is used to record a point of consistency for related application or system
(Backup and Recovery) tables. Usually done before image copy.
RECOVER It is used to restore DB2 table space and indexes to a specific point in time. It
(Backup and Recovery) uses image copy and DB2 logs information to roll back the table space content
to the old one. RECOVER INDEX generated new index data from current table
space data. It is actually regeneration than restoring. So it is followed by
RECOVERY TABLESPACE, which is restoring.
LOAD It is used to accomplish bulk inserts to DB2 tables. It can add rows to a table
(Data Organization) retaining the current data or it can replace the existing data with new data.
REORG It is used to re-clustering the data in table space and resetting the free space
(Data Organization) to the amount specified in the CREATE DDL and deletes and redefining VSAM
datasets for STOGROUP defined objects.
CHECK, REPAIR, These are data consistency utilities. They are used to monitor, control and
REPORT, DIAGNOSE administer data consistency errors.
RUNSTATS It collects statistical information for DB2 tables, table spaces, partitions,
(Catalog Manipulation indexes and columns. It places this information into DB2 catalog tables. The
Utility) DB2 optimizer uses the data in these tables to determine optimal access path
for the SQL queries.
CATMAINT, MODIFY and STOSPACE are the other catalog manipulation
utilities.
RESUME YES => Resumes all the records from first to last.
RESUME NO => Table should be empty.
REPLACE => It overrides the previous record set with current record set.
Mainframe Refresher Part-1 Page:143
1 25 50
XXXX XXXXXXXXXXXXXXXXXXXX XXXXX
YYYYY YYYYYYYYYYY YYYYY
LOAD Data statement describes the data to be loaded. In the above example, SYSREC is coded and it
should be one of the DDNAME in JCL, which points to actual dataset.
Data are loaded in the order they appear in the dataset. Automatic data conversion between compatible
data types is done if needed.
COPY Utility
COPY TABLESPACE EDSDB.TRG007TS
FULL YES |NO YES FOR FULL IMAGE and NO FOR INCREMENTAL
SHRLEVEL CHANGE
Mainframe Refresher Part-1 Page:144
MERGECOPY Utility
MERGECOPY TABLESPACE EDSDB.TRG007TS
NEWCOPY (YES/ NO)
YES. Merging all the incremental copies with the available full image copy and creates a new image copy.
NO. Merging all the incremental copies and prepares a single incremental image copy.
REPAIR Utility
//DSNUPROC.SYSIN *
REPAIR OBJECT LOG YES SET TABLESPACE NPCBTC00.TASSEM01 NOCOPYPEND
/*
This card repairs the table space NPCBTC00.TASSEM01 and clears the copy pending status on the table
space.
RUNSTATS Utility
//SYSIN DD *
RUNSTATS TABLESPACE NPCBTC00.TASSEM01
TABLE (NPCBT9TS.TASTEM01)
COLUMN (NPA, TELNO, CLS_MO, TR_CRT_MO, TR_CRT_YY,
SVC1_TYP, RPT1_TYP, SRC1_TYP, CLR_MO, CLR_DY)
INDEX (ALL)
SHRLEVEL CHANGE
REPORT YES UPDATE ALL
/*
QUIESCE Card:
QUIESCE
TABLESPACE NPCBT900.NPCS1002
TABLESPACE NPCBT900.NPCS1004
Mainframe Refresher Part-1 Page:145
START Database:
DSN SYSTEM(DB2X)
START DATABASE(NPCBT900) SPACENAM(NPCS1001) ACCESS(RO)
START DATABASE(NPCBT900) SPACENAM(NPCS1002) ACCESS(RO)
END
Or
SELECT A.COLNAME,
A.COLSEQ,
A.ORDERING,
FROM SYSIBM.SYSKEYS A,
SYSIBM.SYSINDEXES B
WHERE A.IXNAME = B.NAME
AND A.IXCREATOR = B.CREATOR
AND A.IXCREATOR = B.TBCREATOR
AND B.TBNAME = <TAB NAME>
AND B.TBCREATOR = <TAB CREATOR>
AND B.UNIQUERULE = ‘P’
Mainframe Refresher Part-1 Page:147
SYSPLANDEP table records the dependencies of plans on tables, views, aliases, synonyms, table spaces, indexes,
functions, and stored procedures.
BNAME - The name of an object the plan depends on.
BTYPE - Type of object identified by BNAME:
A Alias, F User-defined function or cast function, I index, S Synonym
T table, P Partitioned table space, R-Table space, V- Views, O-Stored Procedure
DNAME - Name of the plan.
For package dependency, query SYIBM.SYSPACKDEP.
In the second part, you derive the additional time (hours, minutes, and seconds, list in hhmmss format)
between the timestamps and convert the time to the number of seconds. First you need to extract and
convert the hours to seconds:
SELECT (HOUR (TIME (TS2)) - HOURS (TIME TS1))) * 3600
Next you need to extract and convert the minutes to seconds:
SELECT (MINUTE (TIME (TS2)) - MINUTE (TIME (TS1))) * 60
Then you extract the remaining seconds:
SELECT SECOND (TIME (TS2)) - SECOND (TIME (TS1))
Lastly, you add all partial results to produce the difference between the two timestamps in total number of
seconds.
If AUTOCOMMIT is ‘Y’, then all the changes made to DB2 using SQL statements are committed on
successful execution of the query.
If you set the option CHANGE DEFAULTS to ‘Y’, then you will get the screen with SPUFI default values. The
SPUFI allows you to set the values for:
1. Isolation level and Maximum number of lines to be returned from a SELECT
2. Output dataset characteristics.
3. Output format characteristics. (Defining length of numeric and character column, defining
headers in your output file)
Mainframe Refresher Part-1 Page:150
//*
//STEP1 EXEC PGM=IKJEFT01,DYNAMNBR=20,COND=(4,LT)
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DSNP)
BIND PLAN(SOCBATCH) PKLIST(SOCCOLL.*) ACTION(REPLACE) +
RETAIN ACQUIRE(USE) RELEASE(COMMIT) +
ISOLATION(CS) VALIDATE(BIND) NODEFER(PREPARE) +
CACHESIZE(0)
END
//*
//JS01 EXEC PGM=IKJEFT01,DYNAMNBR=20,COND=(4,LT)
//STEPLIB DD DSN=D2TB.DSNLOAD,DISP=SHR
//SYSTSIN DD *
DSN SYSTEM(DSNP)
RUN PROGRAM(SOC02P01) PLAN(SOCBATCH) LIB('DP.GOLIB')
END
//
Mainframe Refresher Part-1 Page:153
CICS
Mainframe Refresher Part-1 Page:154
History
IBM launched the initial version of CICS in 1968.
It is a Database/Data Communication Control System where an application program can concentrate on
the application processing without worrying about OS, hardware and others. Initially CICS was on macro
level and later upgraded to command level.
In Pseudo conversation mode, whenever there is a need for conversation with user, the program
logically terminates there, releases the resources held by it and pass control information to next
transaction and the next transaction is automatically started once user entered the information in the
screen.
It is actually multi task operation but looks like conversation from user point of view.
For easy understanding we would say the communication in telephone line is conversational
mode (Telephone line is in usage through out the communication.) IRC as Pseudo conversation (Once the
message sent, the line is freed and it again gets the resources when the other side replied.)
Reentrant program is defined as a program that does not modify itself so that it can reenter to
itself and continue processing after an interruption by the SVC call of OS. Batch programs are non-
reentrant. Reentrancy under CICS environment is called quasi entrant as the interruption in CICS may
involve more than one SVC calls or no SVC at all.
COBOL programs should be compiled with RENT option for reentrancy in multithreading
environment.
Control Function
Mainframe Refresher Part-1 Page:155
Table
PCT The transactions and the main program associates with the transaction should be
registered in Program table. Task control Program (KCP) refers PCT.
PPT All the CICS programs and Maps have to be registered in Processing Program Table.
Program Control Program (PCP) refers PPT.
FCT All the VSAM files used in the CICS programs has to be registered in File Control Table.
File Control Program (FCP) refers FCT.
DCT Transient data queues should be predefined in Destination Control Table. Transient
Data Program refers DCT.
TST If you want to recover Temporary storage queues during system crash, then they should
be registered in Temporary Storage Table.
RCT If any DB2 commands are used in the program, then the PLAN should be registered
here.
SNT User ID and Password should be registered in Sign-On-Table.
TCT All the terminals should be registered in Terminal Control Table.
PLT All the programs that need to be automatically started during CICS start up and Shut
down should be listed in Program List Table.
JCT Control information of system logs and journal files is stored in Journal Control Table.
Journal Control Program refers to JCT.
If your Program has DB2 commands then the sequence of preparing load module would be DB2
Pre-compiler, CICS Translator, COBOL Compiler and Link editor. Logically speaking the order of DB2
precompiler and CICS translator can be reversed also. But as a convention we are first doing
precompilation.
If translation is done first, CICS translator tries to recognize to DB2 statements and would issue
diagnostic messages. The other reason is, most of the programs do lot of DB2 operations than CICS
operations. So if you do pre-compilation first, all the DB2 statements are converted into COBOL call
statements in first phase itself and the translation time would be less.
COBOL-CICS programs should be compiled with RENT RESIDENT NODYNAM and LIB options.
VS COBOL 2 allows STOP RUN and that returns control back to CICS.
Mainframe Refresher Part-1 Page:156
MAP DESIGN
Before get into program design, let us see how maps (screens) are designed in CICS. Most of the
installations use tools like SDF for screen designing. The tools generate BMS macros for the designed
screen. We brief the BMS macros involved in the map design. BMS is acronym for Basic Mapping Support.
Symbolic maps define the map fields used to store the VARIABLE data referenced in COBOL
program. They are also coded used BMS Macros. But after assembling, they are placed in a COPY library
and then copied into CICS programs using COPY statement. They ensure device and format independence
to the application programs.
Since BMS map definitions are purely assembler macros, the following coding convention must me
maintained.
1 10 16 72
(1-8) Label (10-15) Macro name (16-71) Operands 72-Continuation.
Label: Label is name of the operation. If the macro is DFHMSD, it specifies map-set name. If the
macro is DFHMDF then it specifies field name.
Operands: Define the parameters for the macro being invoked.
nd
Continuation: Continuation of macro is achieved by ‘X’ in 72 column of the current line and
th
continues from the 16 column of next line.
Comments: Comment lines are indicated by ‘*’ in column 1. A comment line cannot be placed
between continuation lines and comment lines cannot be continued.
Blank lines: You cannot have blank lines in the assembler program.
DFHMSD
It is used to define a mapset with its characteristic and to end a mapset. So you will find two
DFHMSD in any BMS coding. The important operands are below:
TYPE.
It should be DSECT for Symbolic map generation, MAP for physical map generation and FINAL to
indicate the end of mapset. Alternatively symbolic parameter &SYSPARM can be coded in the TYPE of
defining DFHMSD and the value can be overridden in the PARM parameter of assembly procedure. This
avoids the change in the BMS coding.
Mainframe Refresher Part-1 Page:157
MODE.
IN for input maps like order entry screens and OUT for output maps like display screens and
INOUT for input-output maps like update screens.
LANG.
It specifies the language in which the symbolic map is to be generated. It can be COBOL, PLI, ASM
or RPG.
STORAGE.
AUTO is used to acquire separate symbolic map area for each mapset.
BASE=MAP-IOAREA allows multiple maps from more than one mapset to share
same storage area. MAP-IOAREA will be redefined multiple times to achieve it.
TIOAPFX.
It should be ‘YES’ to reserve the prefix space of 12 bytes for BMS commands to access TIOA
properly. This is required for command level CICS.
CTRL.
Device control requests are placed here. Multiple parameters are separated by comma. FREEKB
is used to unlock the keyboard. FRSET is used to reset the MDT of all the fields in all the maps to zero.
ALARM is used to set an alarm at screen display time. PRINT is used to send the mapset to printer.
TERM.
If anything other than 3270 terminal is used for display of screens, then it should be coded here.
This ensures device independence by means of providing the suffix. SUFFIX is used to specify suffix for the
terminal and it should correspond to TCT entry of the terminal.
DFHMDI
It is used to define a map with its characteristic in a mapset. There can be any number of
DFHMDI. Some of the important operands of DFHMDI are below:
SIZE. It has two arguments namely length and breadth and as a whole the
size of the map is specified here.
LINE. The map starting line is mentioned here.
COLUMN. The map-starting column within the LINE is mentioned here.
JUST. RIGHT or LEFT is coded here to inform the justification of the map within mapset.
The above four parameters decides the size and location of map within map set. CTRL and
TIOAPFX can be also coded in DFHMDI. Value of DFHMDI overrides the value of DFHMSD.
DFHMDF
It is used to define a field with its characteristic in a map. There can be any number of DFHMDF
within DFHMDI. Some of the important operands of DFHMDF are below:
POS.
It has two arguments that decided the position of the field. The two arguments are line and
column. It is the position where the attribute byte of the field starts.
LENGTH.
The length of the field is coded here. It excludes the attribute character.
ATTRIB.
Mainframe Refresher Part-1 Page:158
All the input and output fields are prefixed by one byte attribute field that defines the attributes of
the field. Some of the attributes are:
1. ASKIP/PROT/UNPROT Mutually exclusive parameters that define the type of the field.
UNPROT is coded for input and input-output fields. PROT is coded for output and stopper fields.
ASKIP is coded for screen literals and skipper fields. The cursor automatically skipped to next field
and so you cannot enter data into skipper field.
2. NUM. 0-9,Period and – are the only allowed characters.
3. BRT/NORM/DRK Mutually exclusive parameters that define the intensity of the field.
4. IC Insert Cursor. Cursor will be positioned on display of map. If
IC is specified in more than one field of a map, the cursor will be placed in the last field.
5. FSET Independent of whether the field is modified or not, it will be
passed to the program. MDT is set for the field.
JUSTIFY.
RIGHT is the default value. Code LEFT for numeric fields.
INITIAL.
The default value of the field is coded here. When the MAP is sent, this value will appear in the
field. The constant information like TITLE is coded using INITIAL keyword of field definition. To avoid data
traffic, these constant information fields should not be coded without LABEL parameter. If there is no
LABEL parameter, then symbolic map will not generated for those fields as they are unnamed fields.
01 EMPDETI.
02 FILLER PIC X(12) TIOAPFX = YES creates this 12 byte filler.
02 EMPNAMEL PIC S9(04) COMP. Length Field
02 EMPNAMEF PIC X. Flag byte
02 FILLER REDEFINES EMPNAMEF.
03 EMPNAMEA PIC X. Attribute byte
02 EMPNAMEI PIC X(20). Actual field (Input)
Other fields….
01 EMPDETOO REDEFINES EMPDETI.
02 FILLER PIC X(12) TIOAPFX = YES creates this 12 byte filler.
02 FILLER PIC X(03)
02 EMPNAMEO PIC X(20). Actual field (Output)
Other fields…
Mainframe Refresher Part-1 Page:159
So four fields are generated for every named field in the BMS.
Fieldname+L
It has length of the field entered by the user during the input operation.
Fieldname+I
It is the actual input field that carries the entered information. The value of this field is X’00’ if no
data is entered. The space corresponds to X’40’.
Fieldname+A
It is attribute byte. It defines the attributes of the field.
Fieldname+F
It is a flag byte. It has X’00’ by default. It will be set to X’80’ if the user modifies the field but no
data is sent. That is when the user pressed clear key over the field.
Fieldname+O
This field should be populated in the program before sending the screen to display.
Please note that the words INPUT (RECEIVE) and OUTPUT (SEND) are with respect to program.
1. When the user modifies the field, the MDT of the field is automatically set to ON.
2. CTRL=FRSET of DFHMSD or DFHMDI will RESET the MDT to ‘OFF’ for all the fields in the
mapset or map. FSET keyword of the attribute operand definition of DFHMDF will set the
MDT to ‘ON ‘. It overrides the FRSET definition for the specific field.
3. Before sending the screen, by overriding the MDT bit of attribute byte of field the MDT can
be set to ‘ON’.
If you are specific on the values of some fields independent of whether the user has modified or
not, code them with FSET. One good example is default values for the input fields (like Order received
date). If the user finds default value (current date) in the screen and it is fine with his requirement, then
he won’t touch the field and MDT will not be set. The program cannot receive the field as MDT is OFF.
But actually the program needs this field. So this field should have been defined with FSET.
CURSOR Positioning
Mainframe Refresher Part-1 Page:160
Positioning of cursor is an important area in screen design. By default, the cursor will be placed in
the first unprotected field.
Static Positioning.
If IC is coded in the attribute operand of DFHMDF macro, then the cursor will be placed in that
field. If IC is coded in more than one field, then last field with IC will get the cursor.
Symbolic Positioning.
Move –1 to length of the field where you want place the cursor and send the map with CURSOR
option. This is device independent method and recommended to control the cursor position dynamically.
Relative Positioning.
Send the map with CURSOR(value) option. This will set the cursor at the position coded by
‘value’, relative to the first column of the screen. This is device dependant method of dynamic cursor
positioning and not recommended. When there is change in screen layout, the program needs to be
modified.
th
CURSOR(30) will place the cursor in the 30 column. (First line first column is ZERO).
Cursor Position.
EIBPOSN of DFHEIBLK contains the offset of cursor position in the screen when the data was
transferred to program from the terminal.(relative to zero). It is half word binary field.
RECEIVE MAP.
Mainframe Refresher Part-1 Page:161
It is used to receive the information entered by the user into program. If INTO is not coded, then
CICS automatically finds the symbolic map area (mapname+I) and places the mapped data. The values of
the field can be read in the program by referring to fieldname+I.
EXEC CICS RECEIVE MAP(map-name) MAPSET(mapset-name) END-EXEC.
The option TERMINAL ASIS overrides the upper-case translation specified in the TCT. As we
already discussed, if the user didn’t modify any of the fields then MDT will be ‘OFF’ for all the fields. Zero
bytes transmission results MAPFAIL exception error.
SEND MAP.
This is used to send a map to a terminal. Before issuing this command, the application program
should prepare the data in the symbolic map area. If FROM is not coded, then CICS automatically finds the
symbolic map area (mapname+O) and takes the data to the terminal.
EXEC CICS SEND MAP(map-name) MAPSET(mapset-name) END-EXEC.
Other Options in SEND MAP are:
ERASE. Erases the screen before displaying the MAP. When you first time throw the screen, it
should be specified with ERASE. It will not be coded when you just want to display the error messages
over the current screen. ERASEUP erases only the unprotected fields of the screen before displaying the
MAP.
DATAONLY. Only symbolic map data is sent to the terminal.
MAPONLY. Only physical map data is sent to the terminal. FROM cannot be coded.
FREEKB, ALRAM and FRSET can be also coded and the meaning is already discussed.
TEXT Building- SEND-TEXT, ACCUM and PAGING
Text streams can be sent to the terminal without any pre-defined BMS maps. This is called text
building. Text streams can optionally have header and trailer.
commands respectively. PURGE MESSAGE is used to purge the message that is accumulated but not yet
send.
01 TEXT-HEADER.
05 FILLER PIC S9(4) COMP VALUE 27. => Length of the text.
05 FILLER PIC X VALUE ‘&’. => Character identifying automatic
page number in the text.
TRAILER also can be coded in the same way. Automatic- page-number-identifying character will
be spaces for TRAILER working storage variable.
ACCUM and PAGING can be also used with SEND-MAP and the meaning is same.
SEND-CONTROL
When the MAP is sent, we can specify device control options like FREEKB ALARM ERASE, along
with SEND-MAP. If one wants to issue the device control options before sending the map, SEND CONTROL
will be useful. It is used to establish the device control options dynamically.
Syntax:
EXEC CICS SEND CONTROL
[CURSOR(data-value)] [ERASE | ERASEUP] [FREEKB] [ALARM] [FRSET]
END-EXEC
Message Routing
A message can be routed to one or more terminals other than the direct
terminal with which the program has been communicating. The message eligible for message routing is, a
message constructed by the SEND MAP command with the ACCUM option.
ROUTE command establishes the message routing environment and the SEND
PAGE command issued after ROUTE command sends the message to the destination.
Mainframe Refresher Part-1 Page:163
Syntax:
EXEC CICS ROUTE [LIST(data-area)], [OPCLASS(data-area)],
[INTERVAL(hhmmss)|TIME(hhmmss)],
[TITLE(data-area)], [ERRTERM(name)]
END-EXEC.
LIST and OPCLASS name the route list and operator class codes respectively. INTERVAL / TIME determines
the actual timing of message delivery in the time interval or the time respectively.
TITLE names the title field defined in the working storage section and
ERRTERM specify the terminal ID where the error message (if any) to be sent.
Route list is prepared in working storage using the following convention.
TTTTrrOOOsrrrrrr – 8 bytes named ‘r’ are declared as spaces. TTTT names the terminal identifier as in TCT
and OOO specify the operator id as in SNT. s is status flag. Code as many 16 bytes fields as the
destinations and indicate end of route list is with the declaration of half word binary field with –1 value.
The message can be routed to every terminal at which users of the specified operator class is
signed on. This is done using OPCLASS.
Program Design
2.Terminal Control Program along with Terminal Control Table recognizes the incoming data
from the terminal.
3.Storage Control Program acquires the storage for the terminal input output area (TIOA)
4.Terminal Control Program places the data from the terminal into TIOA and sets the pointer into
TCT entry of the terminal.
5.If there is no task is associated with the terminal, then TCP gives the control to task Control
Program, which realizes the transaction identifier in the data in TIOA. (KCP)
6.SCP acquires the storage area for task control area (TCA) in which KCP prepares the control
data for this task.
7.KCP refer PCT to identify the program associated with the transaction.
8.Program Control Program (PCP) loads the program into main memory from the load library and
gives the control back to KCP.
9.KCP gives the control to application program loaded into main memory.
10.Program started processing – Task is initiated.
Ways of Data Passing between transactions.
1. By COMMAREA.
In the example below, Working Storage item WS-ITEM of length WS-LENGTH is passed to the
transaction EMPC. The program for the transaction ‘EMPC’ should have DFHCOMMAREA of size WS-
LENGTH in the linkage section to receive the information passed by RETURN of this program.
EXEC CICS
RETURN TRANSID(‘EMPC’) COMMAREA(WS-ITEM) LENGTH(WS-LENGTH)
END-EXEC
WS-LENGTH is full word binary and the maximum length that can be specified is 64K. So we can
pass data of maximum size 64K. But it is recommended not to pass more than 24K.
LINK and XCTL can also have use COMMAREA to pass the information to the program being
called and the concept is same.
2. Queues.
There are two types of queues TSQ and TDQ. TSQ can be used as scratch pad in main memory.
You can write as much as you want in TSQ and they will be available to all the transactions that are aware
of the queue name. TSQ is primarily used to share huge amount of information across the transactions.
Refer Queues section for more details.
01 PARM-LIST.
05 FILLER PIC S9(08) COMP.
05 TCTUA-PTR PIC S9(08) COMP.
05 TWA-PTR PIC S9(08) COMP.
01 TCTUA-AREA.
05 TCTUA-INFORMATION PIC X(m).
01 TWA-AREA.
05 TWA-INFORMATION PIC X(n).
The mapping between the pointers and data area is done in linkage section as follows.
First filler is points the current 01 level, which is PARM-LIST itself.
TCTUA-PTR points to next 01 level, which is TCTCA-PTR
TWS-PTR points to next 01 level, which is TWA-PTR.
This will store the pointer of TWA in TWA-PTR and TCTUA in TCTUA-PTR.
As the mapping between BLL cells and areas is already done in linkage section,
TCTUA-AREA can access m bytes of TCTUA, which exist outside your working storage and similarly TWA-
AREA to access n bytes of TWA, which exist outside your working storage area.
To ensure the addressability, SERVICE RELOAD statement should follow whenever the content of
BLL cell is changed in anyway. So there should be a SERVICE RELOAD statement after the ADDRESS
statement as follows.
Enhancement by VS COBOL2
ADDRESS OF operator of VS COBOL2 easies the access of external items.
The above requirement can be met in VS COBOL2 as follows. There is no need for PARM-LIST or SERVICE
RELOAD.
LINKAGE SECTION.
01 TCTUA-AREA.
05 TCTUA-INFORMATION PIC X(m).
01 TWA-AREA.
05 TWA-INFORMATION PIC X(n).
PROCEDURE DIVISION.
EXEC CICS ADDRESS TCTUA (ADDRESS OF TCTUA-AREA)
TWA(ADDRESS OF TWA-AREA)
END-EXEC.
ADDRESS OF maps the TCTUA-AREA with TCTUA exists outside your working storage.
ASSIGN statement
It is used to access the system value outside of application program.
Some of them are length of common areas, user-id.
CWALENG, TCTUALENG, TWALENG – assign to full word binary working storage item.
USERID - assign to X(08) field.
Mainframe Refresher Part-1 Page:166
LK-ITEM is a linkage 01 item whose length is equal to length mentioned in the LENGTH parameter and
that much memory will be allocated for you in the main memory. The initial value of this field will be set
by INITIMG parameter.
These commands are highly useful in macro level coding where the quasi-reentrancy is the
responsibility of the application programmer. Quasi-reentrancy is guaranteed in the CICS command level
COBOL programs and so the need and usage of these commands are almost obsolete.
Mainframe Refresher Part-1 Page:167
CICS programs are usually run at various levels. The first program, which gets the control from
CICS, that is the program registered against the transaction in PCT, runs at first level. Linked and Called
programs are running one level lower than linking or calling program and so the RETURN or GO BACK in
these programs will give the control back to Linking or calling program. XCTL programs run at the same
level and so the RETURN gives control to next upper level.
Ws-length is length of ws-area and ws-area has the information that needs to be passed to
LINK/XCTL program. VS COBOL 2 allows reentrant program and so whatever is achieved using LINK or
XCTL can be also achieved by COBOL CALL statement. The called programs should be attached to the main
program during link edit and so the size of the load module will be large in this case.
Prefer XCTL whenever possible as it involves fewer overheads. If that is not possible then based
on sub-program size and possible modification, go for LINK or CALL. If the size of the program is less and
used by only very few programs go for CALL as it wont increase the size much at the same time
application will run fast.
If the program is expecting more changes, then calling program also need to be compiled for
every change in sub program. In case of LINK, the compilation of linked programs is enough. Called CICS
programs need not be registered in PPT whereas LINK and XCTL programs should be.
Program PGM1 is loaded and the address of the program or table is mapped to LK-ITEM and so
the table can be accessed using the linkage are LK-ITEM. The size of the linkage item is WS-LENGTH. If
‘HOLD’ keyword is coded in the LOAD command, then loaded program or table will be permanently
resident until explicitly released. If it is not mentioned, then termination of the task release the program
or table.
EXEC CICS RELEASE PROGRAM(PGM1) END-EXEC is used to release the program or table.
Mainframe Refresher Part-1 Page:168
IGNORE CONDITION.
The syntax is same as HANDLE CONDITION but it causes no action to be taken if the specified
condition occurs in the program. The control will be returned to the next instruction following the
command, which encountered the exceptional condition. It will be effective from the place where it
appears to the end of the program or until any HANDLE condition overrides it.
Mainframe Refresher Part-1 Page:169
RESP
Like the file status verification of batch COBOL program, SQLCODE verification of DB2 program,
the success or failure of CICS command can be done using COBOL statements and this give more
structured look for the program.
To achieve this, code RESP along with CICS command. CICS will place the result into the variable
coded in RESP. It can be checked against DFHRESP(NORMAL) or DFHRESP(condition) and appropriately
control the flow following the command.
HANDLE ABEND
HANDLE CONDITION command intercepts only abnormal conditions of the CICS command
execution whereas HANDLE ABEND takes care of any abnormal termination within the program.
USER-ABEND
In batch COBOL, the user ABENDS can be thrown by calling the assembler routine ILBOABN0
using AB-CODE whereas AB-CODE is working storage field of half word binary.
The following command is used to throw user ABENDS in CICS.
EXEC CICS ABEND ABCODE(‘9999’)
END-EXEC is used to throw user ABEND 9999.
FILE-HANDLING.
CICS supports only VSAM and BDAM files. All the files, that you want to use in your CICS
application, should be registered in FCT with their complete attributes.
CICS commands refer the FCT entry name for doing operation on the file.
As all the files are already declared and defined in tables, coding File-Control Paragraph of
ENVIRONMENT division or FILE SECTION of DATA DIVISION is meaningless and not required. Thus CICS
frees the application program from any data dependant coding.
Mainframe Refresher Part-1 Page:170
The unit of IO during READ is one control interval. So even you read one record into your
program, the complete control interval is read into main memory buffer. The size of control interval is
preferred to be large for sequential processing and small for random processing.
The file should be OPEN to issue an I-O command. The status of the file can be queried using the
master transaction CEMT. It can be OPENED, CLOSED, ENABLED or DISABLED. This explicit opening or
closing can be done using CEMT.
But this needs human intervention.
CICS Version 1.7 introduces automatic opening of the file if it is not in open status during the
access. It is always better to close it the when you no longer need it. DFOC (Dynamic File Open Close) can
be done in program using the SET command or linking to DFHEMTP.
The file open command is written into WS-COMMAREA and its length is populated in WS-
LENGTH.
File Open Command: SET DATASET(FCT-NAME) OPENED
S1. Reads the file and if update is intended then code UPDATE clause. This will get exclusive access
over the complete control interval where the specific record exists, during the READ. Thus CICS ensures
data integrity.
S2. Read the file into working storage variable WS-ITEM. Alternatively, the address of the record in
the input-output area can be mapped to linkage section variable by using SET command. Performance-
wise SET is better than READ INTO. VS COBOL2 supports ADDRESS of keyword and makes the code easier.
In the prior version COBOL, PARM list and SERVICE RELOAD should be used to achieve the same.
S3. After the READ, the LENGTH of the record READ is updated into WS-LENGTH. WS-LENGTH is the
working storage half word binary item.
S4. Key of the record to be read is moved into WS-KEY, a working storage item and a part of record
structure (WS-ITEM).
S5. If partial key is used, then the length of the partial key should be moved to
WS-KEY-LENGTH and the keyword GENERIC should be coded. This is optional for full-key read.
S6. Remote system name where the request to be directed, is coded here. (1-4 character name)
S7. EQUAL is default. GTEQ can be coded when you know the full key, but you are not sure the
record with that key exists in the file.
REWRITE
To release the exclusive access acquired during the READ with UPDATE, the record should be
REWRITTEN using the above syntax. The parameters are self-explanatory.
After you read record, if you feel that you don’t want to update it, then inform the same to CICS
by issuing UNLOCK command so that CICS release the lock acquired by you on the record.
EXEC CICS UNLOCK FILE(FCT-NAME) END-EXEC.
WRITE
The syntax of WRITE is same as REWRITE. There is a parameter RIDFLD with Key-value is coded in
the WRITE command. (Like S4 for READ command)
When you want to add a set of records whose keys are in ascending order, then qualify your first
WRITE with another parameter MASSINSERT. This will get exclusive control over the file and provide high
performance during the mass insert.
If you use MASSINSERT, then you should issue UNLOCK to inform the completion of your
additions. CICS releases the file on UNLOCK.
DELETE
1.The record read using READ with UPDATE can be deleted using
EXEC CICS DELETE DATASET(FCT-NAME) END-EXEC.
2.The record in the file can directly be deleted by providing complete key.
Mainframe Refresher Part-1 Page:172
SEQUENTIAL READ:
Sequential access of VSAM file under CICS is called Browsing. It has FIVE Commands associated
with it.
STARTBR.
It establishes a position to start browsing.
Meaning of the parameters is same as READ operation explanation. When you want to do
multiple browsing concurrently over the same file, then use REQID. The first STARTBR can be coded with
REQID(1) and the second STARTBR can be coded with REQID(2).
One browse operation occupies one string of VSAM. If all VSAM strings are exhausted for one
VSAM file, then the other transactions will have to wait for one of the strings to become free. So it is not
recommended to use multiple browsing. Instead, once the browsing is completed, using RESETBR set the
position to another place and start browsing. The syntax of RESETBR is same as STARTBR.
READNEXT is used to read the records in the forward direction from the position established by
STARTBR. READPREV is used to read the records in the reverse direction. READPREV followed by
READNEXT retrieves the same record once again.
During the browse, if you want to skip set of records, then move the key of the next record you
intended to read to RIDFLD and then issue READNEXT. This is called skip sequential read. Thus RIDFLD can
be used as both input as well as output field.
Mainframe Refresher Part-1 Page:173
As VSAM files are variable length in most of the cases, WS-LENGTH should be populated with
maximum record length before issuing READ command.
KEYLENGTH(0) will position the cursor at the beginning of the file.
If you specify READPREV immediately after STARTBR, then you should code key of a record that
exists on the dataset. Otherwise NOTFND condition occurs on READPREV.
ENDBR
It is used to terminate the current browse function.
EXEC CICS ENDBR FILE(FCT-NAME) REQID(INTEGER-VALUE) SYSID(SYSTEM-NAME)
END-EXEC.
ESDS-BROWSING
Define a full-word binary item in working storage for the RBA of ESDS file. Move LOW-VALUES or
HIGH-VALUES to the field for the forward or reverse read respectively. Issue STARTBR with RBA and
EQUAL option. RIDFLD should point to defined RBA field. Now issue READNEXT or READPREV for forward
or REVERSE read respectively.
GTEQ is invalid for ESDS.
ESDS-WRITE
The syntax is same as KSDS WRITE command. Qualify the WRITE with RBA option. The record will
be appended to the file and the RBA of the record is placed into RBA field mentioned in the WRITE
command. (ESDS-RBA)
ESDS-RANDOM ACCESS
If you know the RBA value of the record you want to access, then you can randomly access the
ESDS file. The syntax is same as READ of KSDS file but qualify it with RBA option. RIDFLD should point to
full-word binary item pre-filled with RBA of the record to be accessed.
RRDS ACCESS
RRDS file can be accessed using RRN in place of RBA and populating the RIDFLD with RRN
number. The field should be full word binary.
As the alternate key need not be unique, DUPKEY condition is very common during the alternate
index usage and so it has to be properly handled.
ASKTIME
EIBDATE and EIBTIME have the values at task initiation time. Upon the completion of ASKTIME,
these two fields are populated with current date and time.
EXEC CICS ASKTIME END-EXEC.
FORMATTIME
FORMATTIME is used to receive the information of date and time in various formats. EXEC CICS
FORMATTIME FORMAT-TYPE(data-area) END-EXEC
Format-type: YYDDD, YYMMDD, YYDDMM, MMDDYY, DDMMYY, DAYOFWEEK,
DAYOFMONTH, MONTHOFYEAR, YEAR, TIME, TIMESEP, and
DATESEP.
Example:
EXEC CICS
FORMATTIME MMDDYY(WS-DATE) DATESEP TIME(WS-TIME) TIMESEP
END-EXEC
It is used to delay the processing of a task for a specified time interval or until the specified time.
If your task is doing some heavy CPU bounded work, it is a good to place the DELAY command in order to
allow the other tasks to proceed.
EXEC CICS DELAY INTERVAL(HHMMSS) | TIME(HHMMSS) END-EXEC.
SUSPEND is used to suspend a task. During the execution of the command, the task will be
suspended and the control will be given to other tasks with higher priority. As soon as all higher priority
tasks have been executed, control will be returned to the suspended task.
EXEC CICS SUSPEND END-EXEC.
CANCEL
It is used to cancel the interval control commands such as DELAY, POST and START which have
been issued. The interval commands to be cancelled are identified using REQID.
The data passed by START command is received by the new transaction using RETRIEVE
command upon the expiry of START command.
TSQ No need to predefine anywhere. By default, TS queues are created in main memory. So the
content cannot be recovered after system crash. If you want to recover, then you should define
them in TST.
Records can be randomly accessed using ITEM option of READQ. READ is not destructive.
Deletion of queue deletes all the records in it. Deletion of recoverable TSQ should follow sync
point before next WRITEQ.
READ is destructive and only sequential. Once the record is READ, it will be logically deleted and
Mainframe Refresher Part-1 Page:177
Automatic Task Initiation: When number of records in the queue exceeds the TRIGLEV defined
in the DFHDCT entry of the queue, the transaction coded in the TRANSID of DFHDCT is
automatically triggered. This ATI is possible only in TDQ.
There are two types of TDQ – Intra and Extra partition. The DCT entry identifies the type of
queue from TYPE parameter.
Intra Partition Queues are used within a CICS region and DELETEQ deletes all the records
physically in the queue.
Extra partition Queues are used across the regions and systems. If you want to pass some data
from CICS to batch or receive data from Batch to CICS, you should go for extra partition queue.
In the same program TDQ cannot be opened in both input and output mode.
TSQ are preferred over TDQ for data passing. TDQ is used for batch interface or on ATI
requirement.
MASTER TRANSACTIONS
CEMT:
This is Master Terminal transaction. It is menu driven and easy-to-use transaction but due to its
nature of manipulating the CICS environment, most of the functions are restricted to application
programmer or end user.
CEMT INQUIRE|SET|PERFORM
CEMT INQ TRAN|PRO|FILE – Display information from PCT|PPT|FCT
CEMT INW TASK – Display the active running tasks in the region
CEMT SET command can be used to reset the values of PCT|PPT|FCT.
PERFORM has to be handled carefully. CEMT PERFORM SHUTDOWN will shut down the entire CICS region.
Frequently used commands:
CEMT SET PR(PGM-NAME) NEW - To create a new copy of an application program
Mainframe Refresher Part-1 Page:178
CECI:
This is Command Interpreter transaction. CICS commands can be pre-tested using this command
before placing them into the program.
CEBR:
This is browse transaction. TSQ can be browsed using this transaction.
CEDF:
This is Diagnostic Facility transaction. If you want to debug your program step by step, then
before typing transaction ID type CEDF so that debug mode will be set.
It intercepts a transaction at initiation and termination of a program, before and after execution of any
EXEC CICS or EXEC SQL commands.
CMAC:
This transaction is used to get ABEND codes and messages.
At the top of the ABEND dump, there is a dump header area, which provides ABEND code, TASK
(the transaction ID), Program Status Word (PSW) and the contents of registers at the time of ABEND.
PSW.
nd
It is a double word field containing the status information at the time of ABEND. 32 bit says the
addressing mode in use. If the addressing mode is 31 bits, then the bit will be ‘1’ and the bits 33 to 63
contains the next sequential instruction (NSI), which would have been executed if the ABEND had not
occurred.
First make sure that you have program compilation and link edited SYSPRINTS of the program
ABENDED and dump prints of the ABENDED transaction is with you. Program should be compiled with
LIST option.
2. From the program storage, identify the starting address of program storage.
3.Subtract the starting address of program storage from the NSI address identified in the first step, you
will get the displacement of the NSI from the beginning of program storage.
4.Find the displacement of application program from the beginning of the load module in the link edit list
and subtract this value from the calculated NSI displacement to get the real NSI displacement.
Mainframe Refresher Part-1 Page:179
5.Find the statement in the compilation listing that corresponds to the OFFSET calculated in the previous
step. The statement one above is the statement that caused the ABEND.
6.Analyse the statement for the cause of ABEND. This might have involved one or more fields. Most of the
times, you can easily come to conclusion the cause of the ABEND once you identified the statement. If you
could not, then you may check the value of the field at the time of ABEND as follows.
FCT
All the VSAM files, PATH between base cluster and alternate index and any BDAM datasets are to
be registered in FCT to access them in the application program.
SERVREQ lists the authorized input/output operations against the file. If other than the specified
services is requested in the file control command, then INVREQ condition will occur.
FILESTAT indicates the initial file status when CICS initially starts. BUFND and BUFNI indicate the
number of data buffers and index buffers respectively. Default value is one for BUFNI and two for BUFND.
STRNO is the number of VSAM strings by which concurrent access to the file is allowed.
If the file being registered is path, then BASE indicates the FCT name of the base cluster.
PPT
All the CICS application programs and BMS map sets must be registered in PPT. If the program is
not registered here, then the program is unrecognizable to CICS.
Mainframe Refresher Part-1 Page:180
DFHPPT TYPE=ENTRY,
PROGRAM=name| MAPSET= name
[PGMLANG=(ASSEMBLER | COBOL | PLI)],
options..
ASSEMBLER is the default program language. All the map-sets are considered as written in assembler.
PCT
The control information of all CICS transactions must be registered in program control table
(PCT).
DFHPCT TYPE=ENTRY,
TRANSID=name,
TASKREQ=xxxx, (PF1-PF24, PA1-PA3)
PROGRAM=name,
[DTIMOUT=mmss],
[RTIMOUT=mmss],
[RESTART= NO | YES],
[TRANSEC=1 | DECIMAL], (1-64)
[DUMP=YES|NO],
…Other options..
TCT
All the terminals, which are to be under CICS control, should be registered in TCT. Terminal
Control Program uses this table for identifying the terminals and performs all input/output operations
against these terminals.
DFHTCT TYPE=ENTRY,
ACCMETH=VTAM,
TRMIDNT=name,
TRMTYPE=type,
FEATURE=(UCTRAN,..)
Options..
Mainframe Refresher Part-1 Page:181
DCT
TDQ control information is registered here. Destination Control Program uses this table for
identifying all TDQs and performs input/output operations against them.
ATI:
TRANSID and TRIGLEV are used for automatic task initiation. If the number of records in TDQ exceeded
the number of records mentioned against TRIGLEV, then transaction ID mentioned against TRANSID will
be invoked automatically.
Once a record of intra partition TDQ is read by a transaction, the record is logically removed from, the
queue. If REUSE = YES is coded, then the space occupied by it can be used by other records in future but
the logically deleted records are not recoverable.
OPEN=INITIAL means the file will be open at the CICS start-up time and DEFERED means the file
will be closed until it is specifically opened by CEMT.
DSCNAME defines data control block and for one DSCNAME, a corresponding DFHDCT entry must
be made with TYPE=SDSCI and the same DSCNAME, which in effect indicates DDNAME of extra partition
dataset in JCL or CICS JOB itself.
TYPFILE indicates the file to be INPUT, OUTPUT or READ BACKWARD (RDBACK)
JCL can be submitted using the SPOOLOPEN, SPOOLWRITE and SPOOLCLOSE commands.
NODE('*') specifies a destination node to send the JCL to. USERID is set to the name of the
internal reader INTRDR. A unique token will be allocated by CICS when the SPOOLOPEN is executed and
placed in the field you specify using TOKEN(report_token). The token will be used as a sending field on
subsequent commands. The token will be 8 bytes long.
To write each line of the job to the spool use the SPOOLWRITE command.
EXEC CICS
SPOOLWRITE FROM(io_area) TOKEN(report_token)
RESP(resonse_field)
END-EXEC.
The "io_area" field should be the name of a data item containing the line of JCL. The
"report_token" field should be the same as the 8 byte token returned from SPOOLOPEN. An end of job
statement ('//' or '/*EOF') should be written as the last line.
Finally you must close the spool using SPOOLCLOSE. (Note if you do not explicitly close the spool
it will be closed when the transaction terminates, However it is good practice to close the spool
explicitly)
EXEC CICS
SPOOLCLOSE TOKEN(report_token) RESP(response_field)
END-EXEC.
Again the "report_token" field must be the same as the one allocated at SPOOLOPEN.
Notes:
The RESP option should be coded on all the Commands and it is recommended that you also
code RESP2, because additional information is returned for some exception conditions in this
field.
DCT entries and JCL DD statements are not needed when using this method.
Note that in order to use this method DFHSIT SPOOL=YES must be coded in the CICS System
Initialization Table. Check with your friendly local SysProg if you are unsure.
Under OS/VS COBOL the SPOOLWRITE command had to have FLENGTH specified. FLENGTH
specifies the length of the data being written in a fullword binary field. This field is optional in
newer versions, if it is omitted then the length is assumed to be the length of the data item (io-
area) specified in FROM.
Be aware of the performance considerations for writing to the spool, IBM says "Transactions that process
SYSOUT data sets larger than 1000 records, either for INPUT or for OUTPUT, are likely to have a
performance impact on the rest of CICS".
(Source: CICS/ESA V4R1 Application Programming Reference SC33-1170-00)
Mainframe Refresher Part-1 Page:183