Mainframe Refresher
Mainframe Refresher
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 // .
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.
Mainframe Refresher Part-1 Page:2
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.
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 Centralized Environment. There is a
processor processes the incoming jobs global processor that controls all the
individually. other processors and assigns the jobs to
them.
Datasets are allocated before the step Datasets are allocated before the job
execution. 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 are 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.
Mainframe Refresher Part-1 Page:3
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,
// 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).
Mainframe Refresher Part-1 Page:4
3. The second parameter controls the messages. (0- Only Step execution messages,
1-All JCL, JES, operator and allocation messages).
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 se 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.
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.
Mainframe Refresher Part-1 Page:5
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.
Mainframe Refresher Part-1 Page:6
PGM or PROC
Code the Program name or PROC name to be executed. (1-8 characters)
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)
5. To continue the PARM in the second line, start the second line from 16th 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.
Dont 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.
//EMPFILE DD DSN=SMSXL86.EMPLOYEE.DETAILS,DISP=SHR
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 dont 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)
Abnormal-termination-status:
PASS is not allowed. Meanings of CATLG, UNCATLG, KEEP, and 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.
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 dont 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.
Mainframe Refresher Part-1 Page:9
2. Usually for an existing dataset, we dont 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))
RETPD / EXPDT - indicates the retention period and the expiration date for a
dataset.
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
Mainframe Refresher Part-1 Page:10
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 any 100 tracks for the 16th 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.
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.
Mainframe Refresher Part-1 Page:11
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)
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.
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.
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.
Mainframe Refresher Part-1 Page:12
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.
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
//STEP1 EXEC PGM=INV1040
//INVLSTA DD SYSOUT=A
//INVLSTB DD SYSOUT=A
/*
DATA, The data follows from the next line and ends when the characters coded
Mainframe Refresher Part-1 Page:13
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
If the program tries to write 3001st 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
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
Mainframe Refresher Part-1 Page:14
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)),
// DCB=(DSORG=PS,RECFM=FB,LRECL=80)
//TRANERR DD DSNAME=AR.TRANS.ERR,DISP=(NEW,KEEP),
Mainframe Refresher Part-1 Page:15
// 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 dont
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).
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.
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
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.
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
//EMPOUT DD DSN=&&INVSEL,DISP=(NEW,PASS), INVSEL is temporary
// UNIT=SYSDA,SPACE=(CYL,(&SPACE)) dataset
//EMPCNTL DD DUMMY
//* EMPCNTL is a control card and any in-stream data can be coded during the
//* invoke.
//*
//INV3020 EXEC PGM=EMPRPT
//SYSOUT DD SYSOUT=&CLASS
//INVMAST DD DSNAME=&&INVSEL,DISP=(OLD,DELETE)
//INVSLST DD SYSOUT=&CLASS
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
Mainframe Refresher Part-1 Page:19
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.
Mainframe Refresher Part-1 Page:20
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
IDENT copied from the input dataset.
RECORD IDENT= (Length,Literal,Start-Column)
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.
RECORD FIELD=(5,1,,1),FIELD=(20,21,,6),FIELD=(9,61,ZP,26), X
FIELD=(9,70,ZP,31),FIELD=(4,'TEST',,36)
/*
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.
If TYPE is exclude, then the mentioned steps will not be copied/submitted.
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).
Mainframe Refresher Part-1 Page:23
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,CMUMBAI)
OUTFIL FILES=2 INCLUDE=(1,6,CH,EQ,CTRICHY)
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.
HIGHER(n) COPY those duplicates that occurs more than n times (n => 1-99)
LOWER(n) COPY those duplicates that occurs less than n times (n => 1-99)
EQUAL(n) COPY those duplicates that occurs exactly n times (n => 1-99)
FIRST - Retains the first copy in case of duplicates
LAST - Retains the first copy in case of duplicates
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
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:
CTL1 Add 1 to all the records of the first file at 80th column
CTL2 Add 2 to all the records of the second file at 80th column
CTL3 Concatenate both files and sort the file on key if duplicates found, sum on
81st column. So if any record exists in both the file, it will have 3 after summing.
So now extract records with 1 , 2 and 3 into three files. While writing the records,
remove the 81st 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 messages. Continuation of control card needs to be indicated by X
in 72nd column.
If your shop installed SMS, then uncatalog wont work it out because SMS
handles the catalog.
Mainframe Refresher Part-1 Page:27
IEHINITT
It is used to initialize a tape. It will write the volume serial number to the tape.
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,
Mainframe Refresher Part-1 Page:28
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.
Solution: Look for the abend code in the Solution: Refer IBM Manuals for system
program and study the application logic abend and take appropriate action. You
behind this abend. Then appropriately fix may need to analyse program/data to fix
the data/rerun. based on type of abend.
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.
5.Identify the source of the non-numeric data and correct it.
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).
Mainframe Refresher Part-1 Page:30
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
Mainframe Refresher Part-1 Page:31
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, 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
Mainframe Refresher Part-1 Page:32
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)
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
//SYSTSIN DD *
OUTPUT CENNAEFD(JOB08079) PRINT('T.ISP.MUTHU(TEST1)')
/*
//*
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.
Mainframe Refresher Part-1 Page:35
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.
Mainframe Refresher Part-1 Page:36
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.
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.
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.
Mainframe Refresher Part-1 Page:37
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.
PICTURE Clause
Describes the attributes of variable.
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 doesnt 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.
POINTER 4 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 full word cannot start at 6. So by SYNC rule, it
starts at 8th position. 6th & 7th 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:41
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.
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.
If the receiving field width is smaller than sending field then excess digits, to
the left and/or to the right of the decimal point are truncated.
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 A B C-(A+B)
C
SUBTRACT A B FROM A B C C-(A+B)
C GIVING D
Mainframe Refresher Part-1 Page:43
MULTIPLY A BY B A A*B
MULTIPLY A BY B A B A*B
GIVING C
DIVIDE A INTO B A B/A
DIVIDE A INTO B A B B/A
GIVING C
DIVIDE A BY B A B A/B
GIVING C
DIVIDE A INTO B A B Integer (B/A) Integer
GIVING C 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: Dont 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.
ADD A TO B ON SIZE ERROR DISPLAY ERROR!.
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.
Mainframe Refresher Part-1 Page:44
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)
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.
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.
Statement-Block-2
ELSE
NEXT SENTENCE
END-IF
END-IF
END-IF
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.
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
Mainframe Refresher Part-1 Page:47
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
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!
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).
Mainframe Refresher Part-1 Page:49
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.
4 It can be used in any arithmetic It cannot be used for arithmetic
operations or for display. operation or for display purpose.
5 Subscripts can be modified by any INDEX can only be modified with SET,
arithmetic statement. SEARCH and PERFORM statements.
SEARCH
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.
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 its program id is qualified with keyword COMMON.
Syntax:
SORT SORTFILE ON ASCENDING /DESCENDING KEY sd-key-1 sd-key2
Mainframe Refresher Part-1 Page:52
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.
Example:
WS-NAME MUTHU SARAVANA SURYA CHANDRA DEVI
STRING
STRING command is used to concatenate one or more strings.
Syntax:
STRING identifier-1 / literal-1, identifier-2/ literal-2
DELIMITED BY (identifier-3/literal-3/SIZE)
INTO identifier-4
END-STRING.
VAR2 DELIMITED BY
INTO VAR3
END-STRING.
The receiving field must be an elementary data item with no editing symbols
and JUST RIGHT clause.
With STRING statement, specific characters of a string can be replaced
whereas MOVE replaces the full string.
01 AGE-OUT PIC X(12) VALUE 12 YEARS OLD.
STRING 18 DELIMITED BY SIZE INTO AGE-OUT. => 18 YEARS OLD.
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]
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.
Mainframe Refresher Part-1 Page:55
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.
Sub-Program Changes:
WS-VAR1 and WS-VAR2 are working storage items of main program.
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.
Mainframe Refresher Part-1 Page:56
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).
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.
CALL WS-PGM
2 Default Compiler option is If you want convert the literal calls into
NODYNAM and so all the literal DYNAMIC, the program should be
calls are considered as static calls. compiled with DYNAM option.
By default, call variables and any un-
resolved calls are considered as dynamic.
3. If the subprogram undergoes If the subprogram undergoes change,
change, sub program and main recompilation of subprogram is enough.
program need to be recompiled.
4 Sub modules are link edited with Sub modules are picked up during run
main module. time from the load library.
5 Size of load module will be large Size of load module will be less.
6 Fast Slow compared to Static call.
7 Less flexible. More flexible.
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.
Steps in file-handing
2.Definition. The layout of the file and its attributes are defined in the FILE
SECTION of DATA DIVISION.
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
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 organization or relative record number of
relative organization.100th record can directly be read after getting the address of the
record from the INDEX part for INDEXED files.100th record can directly be read for
RELATIVE files even without any index.
Mainframe Refresher Part-1 Page:59
DYNAMIC.
It is mixed access mode where the file can be accessed in random as well as
sequential mode in the program.
Example: Reading the details of all the employees between 1000-2000. First
randomly access 1000th employee record, then read sequentially till 2000th 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
Mainframe Refresher Part-1 Page:60
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 dont close the files,
the completion of the program closes all the files used in the program.
Syntax: CLOSE FILENAME
multi-volume label. One reel is known as one volume. When the end of one volume
is reached, automatically the next volume opens. So there is no special control is
needed for multi volume files.
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]
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.
Mainframe Refresher Part-1 Page:62
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 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.
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
SYSPRINT
PARM (Compiler listing)
(Compiler
Mainframe Refresher Part-1 Page:66
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
Mainframe Refresher Part-1 Page:67
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.
With OFFSET, the procedure portion of the listing will contain line numbers,
statement references, and the location of the first instruction generated for each
Mainframe Refresher Part-1 Page:68
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.
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.
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
Mainframe Refresher Part-1 Page:69
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)
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).
2 The index component (contains the actual index).
All types of VSAM datasets are called clusters even though KSDS is the only
type that fulfills the cluster concept. ESDS and RRDS dont have Index component.
Data Component.
Mainframe Refresher Part-1 Page:70
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.
Later, when you add a record to the VSAM file, according to the key sequence, it is
placed in a specific control interval.
But if the specific control interval is already full, then this cannot be placed in
the sequence. The result is Control Interval split. It moves half of the records in the
filled control interval to any other free control interval available in the control area
and makes room for the new record in the right place.
If there is no free control interval exist in the control area, then half the
control intervals are moved to new control area and this is called control area split.
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 seen how they are organized. In the example below, to read
the 50th 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.
* 17 *50
Mainframe Refresher Part-1 Page:72
Root Index
First Level
*8 *17 * 23 *50
Index
1 2 4 12 14 20 21 23 33 35
Data Component
5 7 8 17 50
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.
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.
Mainframe Refresher Part-1 Page:75
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.
beginning of the record. This parameter is defined for a KSDS only. Default is
KEYS(64 0).
Syntax: KEYS(length offset)
For an ESDS (since it is processed sequentially) the CISZ should be relatively large
depending on the size of the record.
FREESPACE(ci% ca%)
Mainframe Refresher Part-1 Page:77
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.
2. The expected number of records to be deleted.
3. How often the dataset will be reorganized with REPRO.
4. The performance requirements.
control areas. The resulting free space in the spanned CI is unusable by other
records even if they fit logically in the unused bytes. NONSPANNED is the default.
It can be specified for ESDS and KSDS only.
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.
The IMBED option reduces the seek time it takes for the read-write head to
move from the index to the data component and the replication factor reduces the
rotational delay of the revolving disk.
NOIMBED(NIMBD) and NOREPLICATE(NREPL) are the defaults.
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 clusters name as dataset name. Therefore it is advisable to protect the data and
index components using passwords because someone could otherwise access them
Mainframe Refresher Part-1 Page:80
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.
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.
The records to be printed can be selected in the same way records are
selected in REPRO to COPY.
PRINT INDATASET(MM01.CUSTOMER.MASTER) -
CHARACTER -
SKIP(28) -
COUNT(3)
NOPURGE specifies that the entry not to be deleted if the retention period has
not expired. (Default). So DELETE command dont delete the dataset before expiry
date. PURGE parameter must be coded to delete the dataset before retention period.
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.
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, GDGs, 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
Mainframe Refresher Part-1 Page:85
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
/*
optional parameters
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.
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 -
Mainframe Refresher Part-1 Page:87
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.
Example
JCL for an AMS job with comments that runs an ALTER command
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 *
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
Mainframe Refresher Part-1 Page:89
/*
ALTERNATE INDEX
Steps Involved
Parameter Meaning
RELATE Relates AIX with base cluster
NONUNIQUE/ Duplicates are allowed / not allowed in alternate key.
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 didnt 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; X00 indicates ESDS and X01 indicates KSDS.
Byte-2 Length of base cluster pointers in alternate index; Primary key
length for KSDS and X04 for ESDS.
Byte-3 Half word binary indicates number of occurrences of primary key pointers
Byte-4 in alternate index record. X0001 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.
Example:
The order of build index and definition of PATH does not matter.
AMP Parameter in JCL
The Access Method Parameter (AMP) completes information in an Access
method Control Block (ACB) for a VSAM data set.
The ACB can be coded for a key-sequenced (KSDS), entry-sequenced (ESDS),
or relative record (RRDS) VSAM data set. AMP is only supported for VSAM data sets.
AMP is most often used to allocate I/O buffers for the index and data components for
optimizing performance.
AMORG
This parameter, which stands for Access Method ORGanization, indicates that
the particular DD statement refers to a VSAM dataset.
BUFND
Mainframe Refresher Part-1 Page:92
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
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
DB2 (Database 2)
History
Mainframe Refresher Part-1 Page:93
IBMs 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
DB2 Objects
There are two types of elements or objects in DB2.
Example: DB2 Directory, DB2 catalog, Active & Archive logs, Boot Strap Dataset
(BSDS), Buffer Pools, Catalog visibility Database and Locks.
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
value ranges for single or combination 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.
View of Non-clustered index Diagram (non-leaf pages and data pages are shown)
SYNONYM ALIAS
Private object. Only the user who Global object. Accessible by anyone.
created it, can access it.
Used in local environment to hide Used in distributed environment to hide the
the high level qualifier. location qualifier.
When the base table is dropped, When base table is dropped, aliases are not
associated synonyms are dropped.
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.
Mainframe Refresher Part-1 Page:97
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.
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)*
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 dont 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.
Mainframe Refresher Part-1 Page:100
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.
VERSION. With packages, the pre-compiler option VERSION can be used to bind
multiple versions of the programs into package.
With VERSION(TEST)
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.
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.
REBINDING
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.
is a pre-compiler statement and so it should be coded within the scope of EXEC SQL
and END-EXEC.
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.
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.
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.
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
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.
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.
Mainframe Refresher Part-1 Page:106
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.
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.
Thats 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)
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.
Mainframe Refresher Part-1 Page:108
SET NULL: SET the foreign key value as NULL when the respective primary row is
deleted.
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.
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 dont 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
Mainframe Refresher Part-1 Page:111
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).
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.
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
interim result table of each statement. If you use UNION to combine two columns
with the same name, the result table inherits that name.
You can use UNION to eliminate duplicates when merging lists of values
obtained from several tables whereas UNION ALL retains duplicates.
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,
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.
Mainframe Refresher Part-1 Page:115
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 dont 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 dont 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.
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.
the foreign key is null, the entire foreign key is considered null. If you drop the index
enforcing the primary key of the parent table, an INSERT into either the parent table
or dependent table fails.
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.
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.
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.
MOVE B.E TO WS-QUALIFICATION.
EXEC SQL
UPDATE EMPTABLE
SET QUALIFICATION = :WS-QUALIFICATION :WS-QUALIFICATION-NULL
WHERE EMPID=2052
END-EXEC.
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
while processing 1500th record, then the restart should not start from first record but
from 1001st 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
100 MUTHU TL
101 DEVI SSE
DESIG SALARY
SSE 400000
SE 300000
Result
DEVI 400000
Since there is no TL designation in the SALTABLE, MUTHU will not appear in the
output.
EMPTABLE.DESIGNATION = SALTABLE.DESIGNATION
Result:
MUTHU --
DEVI 400000
--- 300000
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.
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:
Mainframe Refresher Part-1 Page:121
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.
The query use matching index scan and returns all the module id and module
status for the given client and project.
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
Mainframe Refresher Part-1 Page:123
Filter factor
Filter factor is a ratio that estimates I/O costs. The optimizer calculates the
filter factor for a querys 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:
Mainframe Refresher Part-1 Page:124
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
programs 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.
Mainframe Refresher Part-1 Page:126
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:
Select statement is not supported.
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 columns 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.
Mainframe Refresher Part-1 Page:127
It ensures the data integrity between the tables related by Primary (Parent)
and Foreign (Child) keys.
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.
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.
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.
It specifies what access to the locked object is permitted to the lock owner
and to any concurrent application process.
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.
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.
This type of lock is known as LATCH. Latches are internally set by DB2 without going
to IRLM.
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.
Normalization
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.
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
dont 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)
Trigger is a piece of code that is executed in response to a data modification
statement. (insert/update/delete). To be a bit more precise: triggers are event-
driven specialized procedures that are stored in, and managed by the RDBMS. Each
trigger is attached to a single, specified table. Triggers can be thought of as an
advanced form of "rule" or "constraint" written using an extended form of SQL.
Therefore triggers are automatic, implicit, and non-bypass able.
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
Mainframe Refresher Part-1 Page:132
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 doesnt 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.
Mainframe Refresher Part-1 Page:133
Utility Purpose
COPY It is used to create image copy backup dataset for a complete
(Backup and table space or a single partition of a table space. It can be of
Recovery) 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
(Backup and copies.
Recovery)
QUIESCE It is used to record a point of consistency for related
(Backup and application or system tables. Usually done before image copy.
Recovery)
RECOVER It is used to restore DB2 table space and indexes to a specific
(Backup and point in time. It uses image copy and DB2 logs information to
Recovery) 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
(Data rows to a table retaining the current data or it can replace the
Organization) existing data with new data.
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:134
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
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)
Mainframe Refresher Part-1 Page:135
SHRLEVEL CHANGE
REPORT YES UPDATE ALL
/*
QUIESCE Card:
QUIESCE
TABLESPACE NPCBT900.NPCS1002
TABLESPACE NPCBT900.NPCS1004
START Database:
DSN SYSTEM(DB2X)
START DATABASE(NPCBT900) SPACENAM(NPCS1001) ACCESS(RO)
START DATABASE(NPCBT900) SPACENAM(NPCS1002) ACCESS(RO)
END
14. If the cursor is used for update, use FOR UPDATE OF clause in DECLARE
statement itself.
15. Though DECLARE CURSOR can be given in procedure division, code it in
working storage section as a good practice. DECLARE cursor is not an
executable statement and procedure division is for executable statements.
16. For existence checking, use constant. (..WHERE EXISTS (SELECT 1 FROM
TAB1)
17. Give a thought on dropping indexes before large insertions. It avoids
unorganized indexes and poor performance.
18. Dont USE Select * - If there is any change in DB2 table structure, then the
program needs to be modified though it doesnt need the field.
There is unnecessary I-O overhead.
19. Do the arithmetic operations while selecting the column(s) than doing in
programming language
Or
Mainframe Refresher Part-1 Page:137
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
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.
FROM SYSIBM.SYSTABLES
WHERE NAME = <TABLE or View or Alias Name>
AND CREATOR = < TABLE or View or Alias Creator>
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.
Mainframe Refresher Part-1 Page:139
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:140
//SYSLMOD DD DISP=OLD,DSN=&USER..TSTINDIA.LOADS(&MEM)
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSUT1 DD SPACE=(1024,(50,50)),UNIT=SYSDA
// PEND
//*
//*********************************************************************
CICS
Mainframe Refresher Part-1 Page:144
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.
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.
Mainframe Refresher Part-1 Page:145
Control Function
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.
VS COBOL 2 allows STOP RUN and that returns control back to CICS.
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.
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.
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.
Mainframe Refresher Part-1 Page:148
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.
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.
Mainframe Refresher Part-1 Page:149
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
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 X00 if no data is entered. The space corresponds to X40.
Fieldname+A
It is attribute byte. It defines the attributes of the field.
Fieldname+F
It is a flag byte. It has X00 by default. It will be set to X80 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.
Mainframe Refresher Part-1 Page:150
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 wont 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
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.
Mainframe Refresher Part-1 Page:151
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.
CURSOR(30) will place the cursor in the 30th 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.
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.
Mainframe Refresher Part-1 Page:152
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.
To use keys instead paging commands, the keys should be mapped with paging
commands in the System Initialization Table (SIT). Usually there will be a mapping
for PF7 and PF8 with page up and page down 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.
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.
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
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
Mainframe Refresher Part-1 Page:156
used to share huge amount of information across the transactions. Refer Queues
section for more details.
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.
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.
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.
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.
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.
The above checking is done in COBOL and this kind of check has to be done
after every RECEIVE command to properly route the flow. CICS provides its own
routing processing based on the key pressed by HANDLE AID command. This will be
effective through out the program and reduce the code redundancy. The routing will
be automatically invoked on every RECEIVE.
EXEC CICS HANDLE AID
DFHENTER(PARA-1)
DFHPF1(PARA-2)
ANYKEY(PARA-3)
END-EXEC.
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.
Maximum 12 conditions can be coded in one IGNORE CONDITION statement.
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.
Mainframe Refresher Part-1 Page:161
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:162
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
GTEQ | EQUAL S7
END-EXEC.
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 dont 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
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.
EXEC CICS DELETE DATASET(FCT-NAME) RIDFLD(WS-KEY) END-EXEC.
3.Group of records can be deleted using partial key. After the deletion, the number
of records deleted is updated in the variable coded in NUMREC parameter. (WS-DEL-
COUNT)
EXEC CICS DELETE DATASET(FCT-NAME)
RIDFLD(WS-KEY)
KEYLEGNTH(WS-KEY-LENGTH) GENERIC
NUMREC(WS-DEL-COUNT)
END-EXEC
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.
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.
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.
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
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.
During the program processing, if you want to roll back the changes made by
you, then you can code SYNPOINT with ROLLBACK. This will backed out all resource
modifications done since the last sync point.
EXEC CICS SYNCPOINT ROLLBACK END-EXEC.
SYNCPOINT in CICS-DB2 environment is called as two-phase commit.
The changes made in the resources that are directly under the control of CICS are
committed in the first phase and the changes made to DB2 environment are
committed in the second phase.
Queues
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 cannot be read again.
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.
Mainframe Refresher Part-1 Page:170
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
CEMT SET DA(file-name) CLO/OPEN - To close/open a file from CICS.
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:
Mainframe Refresher Part-1 Page:171
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.
It is a double word field containing the status information at the time of
ABEND. 32nd 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.
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
Mainframe Refresher Part-1 Page:172
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.
Mainframe Refresher Part-1 Page:173
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.
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:174
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)
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".
Mainframe Refresher Part-1 Page:176
They are:
1. Primary Commands that can be entered in the Command Line.
2. Line Commands that can be entered in the line(s).
F Musa WORD Look for Musa . Word is a string followed and prefixed by
space.
F Musa PREFIX/SUFFIX Look for Musa as a prefix or suffix with some other
strings.
Note: PREFIX/SUFFIX/WORD/CHARS are mutually
exclusive.
F Musa X Locates the string Musa in excluded lines.
NX searches the string only in non-excluded lines.
Note: X/NX are mutually exclusive with each other.
Locates the next occurrence of the string that was
F * NEXT searched in the last find command.
C ALL Musa Muthu Changes all Musa as Muthu.
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.
Mainframe Refresher Part-1 Page:179
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.
PF1 Help
PF2 SPLIT - Split the screen at the cursors 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:
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 ENTRIESSMSXL86.TEST.SOURCE ALL
LISTDS It is used get the information about one or more datasets.
LISTDS dataset-name MEMBERS|HISTORY|STATUS|LEVEL
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.