Thursday, November 15, 2012

An introduction to Easytrieve

The below tutorial gives brief overview of Easytrieve.

Structure of an Easytrieve program

Contains 3 sections
~~~~~~~~~~~~~~~~~~~

ENVIRONMENT SECTION : Optional
LIBRARY SECTION     : Optional
ACTIVITY SECTION    : Mandatory

ENVIRONMENT SECTION (Equivalent to ID Division & Environment Division)

Establishes parameters for the program. These parameters override standard Easytrieve options.

LIBRARY SECTION (Equivalent to DATA DIVISION in cobol)

Describes datafiles and other fields(including working storage fields) to be used in the program.

ACTIVITY SECTION

There are 2 types of activities - JOB and SORT

JOB activities read from or write to files and manipulate data.

SORT activities create sequenced files.


ENVIRONMENT SECTION
~~~~~~~~~~~~~~~~~~~~

PARM STATEMENT

The parameters of the PARM statement provide a method for customizing the operating environment for the duration of one program's compilation and execution.

ABEXIT (SNAP/NOSNAP/NO)

ABEXIT indicates the level of control exercised over program interrupt
codes 1 through 11.

- SNAP prints a formatted dump of CA-Easytrieve Plus
storage areas along with an error analysis report.
  • NOSNAP prints only a error analysis report.
  • NO inhibits CA-Easytrieve Plus interception of program interrupts.

COMPILE
COMPILE terminates execution after the completion of the syntax check and
compile operations.

DEBUG
DEBUG and its subparameters control generation of certain system outputs.
These outputs are used to analyze programming errors that cause abnormal
execution termination.

Subparameters of DEBUG :
- CLIST
CLIST creates a condensed listing of the executable program produced
by the compiler.

- PMAP
PMAP creates a complete listing of the executable program produced by
the compiler.

- DMAP
DMAP creates a listing of the data map for each file and its
Associated fields.

- FLDCHK
FLDCHK validates all data references during program execution.

- FLOW
FLOW activates a trace of the statements being executed.

STATE
STATE saves the statement number of the statement currently being
executed. The statement number is then printed in the associated abnormal
termination messages.

XREF
XREF causes the creation of a cross reference listing of each field name,
file name, procedure name, segment name, report name, and statement label.

ENVIRONMENT (COBOL,NONE)
LINK (prgname-1 R)
LINK terminates execution after the completion of syntax check and compile
operations.
Prgname-1 is the name of the program.
Subparameter 'R' specifies that the new program replaces an existing program
with the same name.
For eg.,

1) Chgman pgm PARM stmt : PARM LINK (STCIB010 R)

2) PARM statement for EZT programs to be compiled outside chgman :

PARM DEBUG (NOCLIST NODMAP NOFLDCHK NOFLOW NOXREF) +
LIST (NOFILE NOPARM) ENVIRONMENT COBOL




LIBRARY SECTION
~~~~~~~~~~~~~~~~

FILE statement - This statement describes the files accessed by the program.


SYNTAX :-
FILE <filename> <filetype> <devicetype> <recordformat>

Filename: Can be a max of 8 characters (Same as DDName in JCL)

Filetype: Specifies file type. Default is sequential. If the file type is
something other than sequential, this parameter must be specified

FILE-TYPE DESCRIPTION

IS Indexed Sequential Access method
VS Virtual Storage Access method.
ES ESDS
UPDATE - code the UPDATE option to update this file with the PUT or WRITE
statements.

Devicetype: This could be CARD, PUNCH, PRINTER, DISK, TAPE.
For Reports this parameter MUST be specified as PRINTER.

Recordformat : This specifies the record format of the file. This parameter can take the following values :

F=fixed unblocked, FB=fixed blocked
V=variable unblocked, VB=variable blocked
U=undefined

For Eg.,
  1. For VSAM file -> FILE SMLML VS
  2. Sequential file -> FILE MBRFILE
  3. Reports -> FILE STML250R PRINTER

FIELD DECLARATIONS

Field names can be a max of 40 characters. It can contain
alphabets(A-Z and a-z), numbers(0-9) and all special characters except
delimiters. A field name should contain atleast one alphabet or special char.

Examples :

  1. Working Storage fields ->
a) NO-OF-DAYS W 7 N -> Field type – N for Numeric & A for Char.
| |_Length of the field
|
|__Indicates Working storage variable

   b) PRINT-FLAG W 1 A VALUE 'N'
|
|__VALUE clause is similar to COBOL
  1. Fields to be used within Report Section like page number etc., should be defined with type “S”

  1. MASK can be used for editing characters(to be displayed in rpt etc.,)
a) For Eg., PAGENO S 5 N VALUE 1 MASK('ZZZZZ')
| |__Usage is similar to COBOL
|
|__If a field is defined as type ‘S’ it can be modified in REPORT section.

b) MASK of 9 causes a digit to print.
c) MASK of Z causes a digit to print (except for leading zeros).
d) MASK of * causes an asterisk to replace leading zero digits.
e) MASK of - causes a minus sign to print prior to the first non-zero digit
of a negative number.
f) MASK of $ causes a currency symbol to print prior to the first non-zero
digit

  1. We can use DEFINE statement to declare fields in ACTIVITY section.
Eg., DEFINE CURRENT-MONTH W 10 A VALUE 'JANUARY'

  1. We can Redefine fields/records by specifying the offset.
Example :

FILE MBRFILE
MEMBER-REC 1 248 A
ST-BASE-SSN-N MEMBER-REC + 02 09 N
ST-BASE-DEP-IND MEMBER-REC + 11 02 A
ST-PRI-NAME MEMBER-REC + 11 25 A
ST-PRI-SEX MEMBER-REC + 43 01 A
ST-PRI-DOB MEMBER-REC + 44 07 N
ST-DEP-NAME MEMBER-REC + 13 25 A
ST-DEP-SEQ-NBR MEMBER-REC + 38 02 A
ST-DEP-SEX MEMBER-REC + 47 01 A
ST-DEP-DOB MEMBER-REC + 40 07 N
ST-DEP-REL MEMBER-REC + 48 02 A

  1. OCCURS clause can be used to declare tables :

Examples :
a)
WS-TABLE W 26 A OCCURS 23
WS-DUE-OFF-DT WS-TABLE 8 A
WS-DUE-OFF-DT-MM WS-DUE-OFF-DT 2 N
WS-DUE-OFF-DT-DD WS-DUE-OFF-DT +2 2 N MASK('99')
WS-DUE-OFF-DT-DD-A WS-DUE-OFF-DT-DD 2 A
WS-DUE-OFF-DT-CC WS-DUE-OFF-DT +4 2 N
WS-DUE-OFF-DT-YY WS-DUE-OFF-DT +6 2 N
WS-NUM-MISSED WS-TABLE +8 3 N
WS-NUM-MISSED1 WS-TABLE +8 3 A
WS-JUL-INIT-DT-07 WS-TABLE +11 7 N
WS-INIT-DT WS-TABLE +18 8 N

NOTE :
Variables coded in BOLD are Primary variables of the Table (i.e., similar to
05 level).
Variables in ITALICS are Redefined variables

  1. REPORT HEADINGS : Default report heading for a field is the field name. Incase we need a different heading to be displayed in the report we can use HEADING option.
For Eg.,

a) WS-FNAME W 15 A HEADING ('FIRST NAME')
|
|__Heading displayed is FIRSTNAME

b)PAY-GROSS W 04 P 2 HEADING('GROSS' 'PAY')
|
|__Heading will be split into 2 lines & is
displayed as : GROSS PAY

c) CONTRACT W 11 N HEADING ('EMPLOYEE' 'ID') +
MASK '999-99-9999-99'


CONTINUATIONS : + OR -
The hyphen indicates that the statement continues with the first position
in the next statement area (which can be a blank).
The plus symbol indicates that the statement continues with the first
nonblank character in the next statement area (which could be in the first
position); leading blanks are ignored.
PROCESSING

  1. JOB – JOB statement performs the following activities
  • Retrieval of input files
  • Examination and manipulation of data
  • Initiation of printed reports
  • Production of output files.
  1. SORT statement

JOB:

SYNTAX – JOB INPUT <filename> START <procname> FINISH <procname>
| | |_This proc will be
| | performed at End of JOB
| |__The PROC mentioned here will be executed
| automatically when the JOB begins
|____Identifies that the Job has an Automatic input. The file
specified here will be read automatically and the
records will be processed sequentially until EOF.
  1. When INPUT is not specified, EZT automatically takes the first File defined
in the Library section as Input.

  1. To override the default input file NULL should be coded in place of filename
Eg., JOB INPUT NULL
PROC:
Procedures(or PROCs) can be coded to execute a set of statements. The PROCs can be called from the JOB statement by using PERFORM statement. PROCs must be coded immediately after the associated JOB, SORT or REPORT statement

Example :
JOB INPUT SMLML START START-PARA

IF MSR-7061-CURR-RREP-SOURCE EQ 'M' OR +
MSR-7061-CURR-RREP-SOURCE EQ 'P'
PERFORM LOC-31-PARA
END-IF
GOTO JOB

LOC-31-PARA. PROC

IF (WS-HOLD-MSR-JUL-DT GT WS-TEMP-INIT-DT-07)
PRINT STML240R
END-IF

END-PROC

ASSIGNMENTS & MOVES :

  1. Assignments(using EQ or =) assigns the value in right side to the variable in
the left side.
Example : MSR-7061-CURR-RREP-SOURCE EQ 'P'
  1. MOVE statement moves a string from one variable to another. MOVE statement does not transfer the value in Numeric form(ie., even if its used for numeric fields the value moved is in Character form). However, when we move ZEROES the value moved is Numeric

  1. The MOVE LIKE statement copies fields with identical field names from one
file to another.
SYNTAX : MOVE LIKE <file1/rec1> to <file2/rec2>

IF, DO & CASE statements :

  1. IF, ELSE-IF, ELSE & END-IF statements are available in Easytrieve. Relational operators are :
i) EQ or =
ii) NE or »= or NQ
iii) LT or < or LS
iv) LE or <= or LQ
v) GT or > or GR
vi) GE or >= or GQ
  1. To perform a set of statements n times, DO WHILE or DO UNTIL statement can be used.
Example :
I = 1
DO WHILE I < 10
I = I + 1
END-DO

  1. CASE stmt : CASE is similar to EVALUATE statement.
Example :
i)
CASE ST-DEP-DOB-C
WHEN 1
WS-DOB-CC EQ '18'
WHEN 0 2 -> OR need not be coded explicitly
WS-DOB-CC EQ '19'
WHEN 3
WS-DOB-CC EQ '20'
END-CASE

ii)
CASE WORK-GROSS
WHEN 0 THRU 1000
XMAS-BONUS = PAY-GROSS * 1.03
WHEN 1001 THRU 5000
XMAS-BONUS = PAY-GROSS * 1.05
OTHERWISE
XMAS-BONUS = PAY-GROSS * 1.10
END-CASE

FILE OPERATIONS :

  1. GET statement : Used to READ a file sequentially.

SYNTAX - GET <filename> STATUS
|___If STATUS is specified FILE STATUS is returned
after the GET operation

Eg.,

GET PERSNL STATUS

IF PERSNL:FILE-STATUS NE 0
DISPLAY PERSNL:FILE-STATUS
END-IF

  1. POINT statement : Equivalent to START in COBOL.
SYNTAX - POINT <filename> <relational operator> <field name> STATUS
Eg.,
POINT DUPIN GE HD-IN-KEY STATUS

  1. PRINT : PRINT statement requests report output
SYNTAX - PRINT <rptname>
|
|__ If report name is not specified default will be assumed

  1. PUT : performs sequential file output

SYNTAX – PUT <filename> FROM <recname> STATUS
|
|__ this clause is optional
  1. READ : Read statement is used for Random Access to VSAM datasets.
SYNTAX - READ <file-name> KEY <field-name>  STATUSâ

  1. WRITE : Write statement is used for writing recs into VSAM files. Its used to Update, Add or Delete recs from VSAM files. To update a record, UPDATE subparameter must have been coded in the FILE definition.

SYNTAX – WRITE <filename> <activity> FROM <recname> STATUS
|
|
|__can have “UPDATE” or “ADD” or “DELETE”.

UPDATE is the default operation.

Eg.,
a)
FILE INTFILE VS (UPDATE) -> File definition
WRITE INTFILE UPDATE STATUS -> Write stmt in JOB

REPORT Definition

SYNTAX of REPORT stmt :
REPORT <rptname> <options>

Report Definition Statements

Following statements define the content of the report and must be coded in the same order as shown below.

SEQUENCE
CONTROL
SUM
TITLE
HEADING
LINE
special procedures

  1. SEQUENCE :
The SEQUENCE statement optionally specifies the order of the report. We
can order a report based on the content of one or more fields. The
fields do not have to be part of the printed report.

SYNTAX - SEQUENCE field-name-1 field-name2 D
|__indicates Descending order
Default is Ascending order.

  1. CONTROL :
The CONTROL statement identifies control fields used for a control
report. A control break occurs whenever the value of any control field
changes.

SYNTAX – CONTROL field-name1 <NEWPAGE/RENUM> <NOPRINT>
|__Optional

NEWPAGE causes a skip to top-of-page after control break processing is
complete for the specified field.

RENUM performs the same function as NEWPAGE, and also resets the page
number to 1 on the page following the control break.
NOPRINT suppresses printing the summary line group for the specified
control break

  1. SUM :
SUM statement prints the Totals of the specified fields at the end of
report or whenever control break occurs
Normally, Easytrieve automatically totals all quantitative fields
specified on LINE statements. The SUM statement overrides this process;
only the fields specified on the SUM statement are totaled. The fields
The SUM statement is only valid within a Control Report.

SYNTAX – SUM fieldname

  1. TITLE :

The TITLE statement defines the title items and their position on the
title line.

Easytrieve automatically positions the system date and current
page count on title line one. This can be overridden by the options on
the REPORT statement (NODATE/NOKDATE/LONGDATE/SHORTDATE and
NOPAGE/NOKPAGE).

Each title line is centered within the title area of the report unless we
specify NOADJUST in REPORT stmt.

Example :

TITLE 1 COL 15 'PGM: STCIB085 ' +
COL 45 'BLUE CROSS AND BLUE SHIELD OF GEORGIA, INC.' +
COL 97 'RPT: STC085R1'
TITLE 2 COL 50 'REPORT OF INVENTORIED STATE CLAIMS'
TITLE 3 COL 40 ' '
TITLE 4 COL 15 'CATEGORY:' +
COL 25 WT-CATEGORY-NAME(CAT-SS) +
COL 87 'REPORT PERIOD: ' RPT-DATE

  1. HEADING :
The HEADING statement optionally defines an alternate heading for a field.
When defining the field, you can specify the default heading.

HEADING WS-INIT-PRT-GREG-DT-06 ('DATE' 'RECEIVED')
HEADING WS-NUM-ACTIVATED ('NUMBER' 'ACTIVATED')

  1. LINE :

Line Stmt defines the detail lines for the report
Syntax : LINE <COL XX1>or <POS> field name1 +
<COL XX2>or <POS> field name2

COL specifies the column number where the next line item is placed. We
must specify the NOADJUST option of the REPORT statement to use the COL
option.



The POS parameter enables you to position line items on lines 2 through 99
so that they line up under particular line items on the first line.

REPORT PROCEDURES

REPORT-INPUT. PROC

It permits final screening and modification of report input data. It is
performed for each record selected for the report that contains the PROC.

We must execute a SELECT statement in the PROC to cause data to continue to
the report.

BEFORE-LINE. PROC

The proc is executed before each line is printed

AFTER-LINE. PROC

The proc is executed after each line is printed

BEFORE-BREAK. PROC

It permits modification of totals and special annotation before total line printing caused by the CONTROL statement. A system-defined field named LEVEL can be tested to determine which field has caused the break, when we have control breaks based on more than 1 field.

LEVEL = 1 for minor break(ie., the last field coded in control stmt)
= 2 for next break(last but one
= N + 1 for final totals.
(N is the number of control fields)
AFTER-BREAK. PROC
Same as BEFORE-BREAK proc except that the PROC will be executed after the Total lines for Control break has been executed.

ENDPAGE. PROC
Will be executed at the end of each page. Can be used to print Footnotes...

TERMINATION. PROC
Will be executed at the end of rpt.

REPORT PROCS – Eg.,

REPORT NEW-CIC-SUM PRINTER STC085R3
SEQUENCE CAT-SS
CONTROL FINAL NOPRINT CAT-SS NOPRINT
TITLE 1 'PGM: STCIB085 ' +
'BLUE CROSS AND BLUE SHIELD OF GEORGIA, INC.' +
'RPT: STC085R3'
TITLE 2 'REPORT OF INVENTORIED STATE CLAIMS'
TITLE 3 'CATEGORY SUMMARY - NUMBER RECEIVED IN REPORTING PERIOD'

LINE 1 WT-CATEGORY-NAME(CAT-SS) +
CLMS-PER-CAT

REPORT-INPUT. PROC
SELECT
END-PROC

AFTER-BREAK. PROC
IF LEVEL = 1
DISPLAY ' '
DISPLAY 'INVENTORY FILE STATISTICS'
DISPLAY ' '
DISPLAY ' RECORDS ON INVENTORY FILE : ' CIC-CNT
END-IF
END-PROC

SAMPLE EZT PGM :-

PARM DEBUG (NOCLIST NODMAP NOFLDCHK NOFLOW NOXREF) +
LIST (NOFILE NOPARM) ENVIRONMENT COBOL
**********************************************************************
* PROGRAM NAME : ADHOC *
* PROGRAMMER : SYNTEL *
* PURPOSE : *
* THIS PROGRAM WILL READ THE STATE MERIT FILE AND CREATE A REPORT *
* OF EMPLOYEES AND DEPENDENTS THAT HAVE EITHER SPECIAL CHARACTER *
* OR A BLANK SPACE IN THE FIRST POSITION OF FIRST NAME, *
* LAST NAME OR MIDDLE NAME. *
**********************************************************************
***************
* INPUT FILE *
***************
FILE MBRFILE
MEMBER-REC 1 248 A
ST-BASE-SSN-N MEMBER-REC +02 09 N
ST-BASE-DEP-IND MEMBER-REC +11 02 A
ST-PRI-NAME MEMBER-REC +11 25 A
ST-PRI-SEX MEMBER-REC +43 01 A
ST-PRI-DOB MEMBER-REC +44 07 N
ST-PRI-DOB-C ST-PRI-DOB 01 N
ST-PRI-DOB-YY ST-PRI-DOB +01 02 N
ST-PRI-DOB-MM ST-PRI-DOB +03 02 N
ST-PRI-DOB-DD ST-PRI-DOB +05 02 N
ST-DEP-NAME MEMBER-REC +13 25 A
ST-DEP-SEQ-NBR MEMBER-REC +38 02 A
ST-DEP-SEX MEMBER-REC +47 01 A
ST-DEP-DOB MEMBER-REC +40 07 N
ST-DEP-DOB-C ST-DEP-DOB 01 N
ST-DEP-DOB-YY ST-DEP-DOB +01 02 N
ST-DEP-DOB-MM ST-DEP-DOB +03 02 N
ST-DEP-DOB-DD ST-DEP-DOB +05 02 N
ST-DEP-REL MEMBER-REC +48 02 A

****************
* REPORT FILE *
****************
FILE REPORT1 PRINTER
******************
* WORKING STORAGE
******************
WS-LINK-REC W 61 A
WS-FULL-NAME WS-LINK-REC 25 A
WS-FNAME WS-LINK-REC +25 15 A HEADING ('FIRST NAME')
WS-F-FIRST WS-FNAME 01 A
WS-LNAME WS-LINK-REC +40 20 A HEADING ('LAST NAME')
WS-L-FIRST WS-LNAME 01 A
WS-L-15-20 WS-LNAME +15 05 A
WS-MNAME WS-LINK-REC +60 01 A HEADING ('MIDDLE' 'INITIAL')
WS-ERROR W 04 A HEADING ('ERROR' 'INDICATOR')
F-ERROR WS-ERROR 01 A
L-ERROR WS-ERROR +01 01 A
M-ERROR WS-ERROR +02 01 A
E-ERROR WS-ERROR +03 01 A
WS-SEX W 01 A HEADING ('SEX')
WS-REL W 02 A HEADING ('RELATION')
WS-MEMBER-ID W 09 A HEADING ('MEMBER ID')
WS-SEQ-NBR W 02 A HEADING ('SEQ' 'NBR')
WS-DOB W 10 A HEADING ('DOB')
WS-DOB-MM WS-DOB 02 A
WS-FIL1 WS-DOB +02 01 A VALUE '/'
WS-DOB-DD WS-DOB +03 02 A
WS-FIL2 WS-DOB +05 01 A VALUE '/'
WS-DOB-CC WS-DOB +06 02 A
WS-DOB-YY WS-DOB +08 02 A

*----------------------------------------------------------------------*
JOB INPUT MBRFILE
*----------------------------------------------------------------------*
MOVE SPACES TO WS-LINK-REC
CASE ST-BASE-DEP-IND
WHEN 'ZD'
WS-FULL-NAME EQ ST-DEP-NAME
OTHERWISE
WS-FULL-NAME EQ ST-PRI-NAME
END-CASE
CALL STRNAME USING (WS-LINK-REC)
IF ST-BASE-DEP-IND EQ 'ZD'
WS-SEQ-NBR EQ ST-DEP-SEQ-NBR
CASE ST-DEP-DOB-C
WHEN 1
WS-DOB-CC EQ '18'
WHEN 0 2
WS-DOB-CC EQ '19'
WHEN 3
WS-DOB-CC EQ '20'
END-CASE
WS-DOB-YY EQ ST-DEP-DOB-YY
WS-DOB-MM EQ ST-DEP-DOB-MM
WS-DOB-DD EQ ST-DEP-DOB-DD
WS-SEX EQ ST-DEP-SEX
WS-REL EQ ST-DEP-REL
ELSE
WS-SEQ-NBR EQ '00'
CASE ST-PRI-DOB-C
WHEN 1
WS-DOB-CC EQ '18'
WHEN 0 2
WS-DOB-CC EQ '19'
WHEN 3
WS-DOB-CC EQ '20'
END-CASE
WS-DOB-YY EQ ST-PRI-DOB-YY
WS-DOB-MM EQ ST-PRI-DOB-MM
WS-DOB-DD EQ ST-PRI-DOB-DD
WS-SEX EQ ST-PRI-SEX
MOVE SPACES TO WS-REL
END-IF
WS-MEMBER-ID EQ ST-BASE-SSN-N
MOVE SPACES TO WS-ERROR
IF (WS-F-FIRST NOT ALPHABETIC) OR +
(WS-F-FIRST SPACE)
F-ERROR EQ 'F'
END-IF
IF (WS-L-FIRST NOT ALPHABETIC) OR +
(WS-L-FIRST SPACE)
L-ERROR EQ 'L'
END-IF
IF WS-L-15-20 NOT SPACES
E-ERROR EQ 'E'
END-IF
IF (WS-MNAME NOT ALPHABETIC) OR +
(WS-MNAME SPACE)
M-ERROR EQ 'M'
END-IF
IF WS-ERROR NOT SPACES
PRINT REPORT1
END-IF

GOTO JOB
REPORT REPORT1 PRINTER REPORT1
TITLE 01 'MEMBERS IN STATE TAPE WITH NAME ISSUES'
LINE 01 WS-MEMBER-ID +
WS-SEQ-NBR +
WS-LNAME +
WS-FNAME +
WS-MNAME +
WS-DOB +
WS-SEX +
WS-REL +
WS-ERROR                                              

Friday, November 9, 2012

A quick guide for JCL



Job Control Language (JCL)

JCL controls how your programs are run on the mainframe. JCL is essentially an interface between your program and the operating system. It makes your programs more flexible, because you can specify options, such as dataset names, without the need to hardcode them in a program. You can easily change dataset names and specify parameters without needing to change and re-compile your program.
 The JCL tells the computer which program to run, where the program is located, which datasets to use and where to direct output.


General


Each line of JCL starts with two slashes ('//') in columns 1 to 2.
Columns 1 to 71 can be used to code JCL statements.
The JCL specifies a jobname and can contain one or more steps. Each step will execute a program.
Comments can be added to the JCL using //* in columns 1 to 3.
Every job will begin with a 'Job Card', which specifies the jobname, and other important information about how the job will execute.
The JCL is terminated using '//' in columns 1 and 2, or when there are no more statements to be read in.
 You can contuinue a statement parameters over several lines to make it more readable.
 

Some Terminology.
Dataset = Any type of file.
 Partitioned Dataset (PDS) = A special type of dataset which is split up into different members. Each 'member' of a PDS can contain, for example, a different program, or a piece of JCL. Also refered to as a library.
TSO = Time Share Option. An IBM interactive product. Provides facilities to edit datasets, submit JCL, and set up datasets amongst other things. Often the term is used to describe/include ISPF, which runs under TSO.
 ISPF = An interactive system that runs under TSO. Uses screens to navigate through options. Similar Products are CA's ROSCOE and Skybird Systems' RPF.
 DASD = Direct Access Storage Device, also known as a disk (or disc) although it can refer to any storage device which allows Direct Access to the data stored on it (ie you don't have to read sequentially through all the preceeding files to get to the one you want)
VSAM = A special type of file. There are a number of different types of VSAM files which can be accessed in a number of different ways, including sequentially or using an index.
 Initiator = A system routine which selects which job is to run next, and controls it's execution and termination. There may be a number of initiators in a system, each of which is set up to run different classes of job.
JES = Job Entry Subsystem. JES is a system that is designed to handle execution of all the jobs on the mainframe. It comes in two flavours - JES2 and JES3. JES2 is probably the most commonly used version of JES.


The Job Card


Every job you code will have a Job Card. This is the first thing you must code for every job.
 Each job card will have a jobname to identify the individual job. The jobname does not have to be unique, you can have several jobs with the same name. (The system will automatically allocate a job number when the JCL runs, this helps identify individual jobs when they have the same name).
 

Example:
//HERC04J1 JOB (PJ0001),CLASS=A,MSGCLASS=C,
//           MSGLEVEL=(1,1),NOTIFY=HERC04

The jobname is specified first, in this case HERC04J1. Then the word JOB is specified to indicate that this is a job. You MUST specify the word JOB on the first card.
The (PJ0001) is accounting information. This can indicate an 'accounting cost centre' where the job is to be charged to. The cost centre information varies from site to site.
 The cost centre can be used if your computer centre charges individual departments for usage of the system. Regardless of whether it is used to charge departments, you usually need to specify a cost centre (This may just be your userid eg (HERC04).
You can also specify additional accounting information, such as room number where output is to be sent to, but this is not often used. If you are only specifying a cost centre then the brackets are not required.
 The job class is specified using 'CLASS=' The job class is used to tell the system how the job is to be run. The job class in some cases can decide the priority of the job and how long it will be allowed to run. Jobs are started using OS initiators. Each initiator will be assigned one or more classes of jobs which it can run. So you might have an initiator that runs all Class A jobs and another initiator that runs class B and C jobs. If an initiator is already running a job, then your job may have to wait until the initiator is free.
You can specify where the job output will be directed by using MSGCLASS. The output class may determine what happens to the output. For example Class C may mean that the job is to be held on the system for 8 days before it is deleted, or it may mean that the output is sent immediately to a specific printer.
The system will issue messages when your job is running. You can use the MSGLEVEL parameter to tell the system the type of messages you want to be kept. MSGLEVEL=(1,1) means that all the messages are kept. MSGLEVEL=(0,0) or MSGLEVEL=0, means that the minimal set of messages are kept.
If you want to be told when the job has finished you can use the NOTIFY parameter. The NOTIFY parameter will specify a userid. If you are logged on to TSO then you will be notified when the job ends if you are logged in using that userid or when you log in with that userid.



Job Steps

After the Job Card has been coded you can begin to specify the steps for a job. There can be one or more steps, each of which specifies a program that is to be run. After you tell the system which program to run, you then specify the datasets to use for that program, and where to direct output from that program.
 Each step will have a step name coded in columns 3 onward. A stepname can be 1 to 8 characters long.

Example:


//STEP010 EXEC PGM=DATEST


STEP010 is the step name. The stepname can be anything you want.
EXEC PGM=DATEST tells the system that you want to EXECute a ProGraM called DATEST



Defining datasets to be used in a job step

You tell the system about the datasets you want to use, by specifying a 'DD statement'. DD means Data Definition.
The DD Statement has a DDNAME, this will correspond to the name defined in your program using the SELECT statement (in COBOL).

SELECT REPORT-FILE ASSIGN REPRT1.
 

REPORT-FILE refers to the FD description in your program, the REPRT1 corresponds to the DDName in the JCL.

//REPRT1 DD DSN=HERC04.REPORT.DS1,DISP=SHR 

DSN specifies the dataset name. This is followed by a DISPosition parameter. This tells the system how to access the dataset and whether the dataset already exists.
DISP=OLD, means that the dataset exists and this job should have exclusive use of the dataset.
DISP=SHR, means that the dataset exists and other users and jobs can access the dataset while this job is using it.
DISP=MOD means that the contents of the dataset should be kept and any new records will be appended at the end of the dataset. The dataset may or may not exist already. If it does not exist then one will be created.
DISP=NEW means that the dataset does not exist and will be created when the job is run.



Defining a new dataset.

If you want to create a new dataset during a job run, you use the DD statement. The DD statement will specify, amongst other things,the dataset attributes, where to store the dataset and how much space to be used for the dataset.

//NEWDS DD DSN=HERC04.OUTPUT.CLIENT,
//         DISP=(NEW,CATLG,DELETE),
//         UNIT=3390,SPACE=(TRK,(1,1)),
//         DCB=(RECFM=FB,LRECL=80,BLKSIZE=8000)
 

The DISP parameter specifies that this is a NEW dataset. The second subparameter, CATLG, specifies what will happen to the dataset when the job step ends normally, in this case CATLG means that the dataset is kept and cataloged. You can also specify DELETE or KEEP. DELETE means that the dataset will be deleted and uncatalogued. KEEP specifies that the dataset will be kept, but not catalogued. KEEP is generaly used more with tapes and cartridges than DASD datasets.
The last sub-parameter of the DISP statement, in this case DELETE, specifies what happens to the dataset when the job step terminates abnormally. Again you can specify CATLG, DELETE or KEEP.
 

The UNIT parameter specifies the type of media the dataset will be stored on. '3390' means that the dataset will be stored on a 3390 type disk pack. You can also specify a generic group name, which specifies a group of devices where the dataset can be stored. for example UNIT=SYSDA. This would store the dataset on one of the packs defined within the group SYSDA.
 

The SPACE parameter defines the amount of storage that will be allocated to a dataset. TRK specifies the units, it can be CYL for cylinders, BLK for blocks and TRK for tracks.
The (1,1) specifies the number of tracks/cylinders/blocks. The first number is the number of tracks initially allocated. The second number specifies the number of extents.
 

The DCB parameter tells the job the attributes of the dataset. RECFM defines the format of the dataset, FB means the dataset will have fixed length records and will be blocked, VB would mean the dataset is variable length and blocked.
 

The LRECL subparameter specifies the length of the records that will be in the dataset.
 

The BLKSIZE subparameter specifies the size of a block. It should be a multiple of the record length defined in LRECL. A blocksize of 8000 would hold 100 80 byte records.
For variable length records the blocksize should be a multiple of the record length plus four. The extra four is for the Record Descriptor Word (RDW), this will contain the length of the record. The RDW is not normally visible to your program, but is used by the system, so you must remember to allow for it in the JCL.


Note, you don't have to code the subparameters in any specific order, so your DCB= can come before the SPACE and/or UNIT sub parameters if you wish.



Dataset Concatenation

You can specify multiple datasets on a DD statement. The datasets will be read as if they were all one big dataset.

//DD01 DD DSN=PROD.CLIENTS.LIST1,DISP=SHR
//     DD DSN=PROD.CLIENTS.LIST2,DISP=SHR
//     DD DSN=PROD.CLIENTS.LIST3,DISP=SHR


In this example (assuming the program is reading sequentially through all records), the dataset PROD.CLIENTS.LIST1 will be read until there are no more records, then PROD.CLIENTS.LIST2 will be read until there are no more records then PROD.CLIENTS.LIST3 is read until there are no more records and an end-of-file condition will be returned to the program.



Directing Output

You can specify where your output will be sent using a SYSOUT statement on the DD statement. The statement will contain an output class. The output class determines what will happen to the output. For example, class A might send the output directly to a printer, class C might save the output on the system for seven days, before it is deleted. The output classes will be site specific, check the standards to find out what output classes you should use.

Examples:


//REPRT1 DD SYSOUT=A
//REPRT2 DD SYSOUT=*

If you specify SYSOUT=* then the job class will be the same as that specified in the MSGCLASS in the job card.
If you are using a DISPLAY in your program, then you can use the DDname SYSOUT to direct what happens to the information that is displayed.

 Example:

//SYSOUT DD SYSOUT=X



Passing Parameters to your Program

You can pass parameters to your program by using the SYSIN DDname
Example:
 

COBOL Program:


ACCEPT PARM-LIST FROM SYSIN 
JCL:


//SYSIN DD *
PGM1 20010201 20010301D
//*


The DD * tells the system that what follows is 'instream data'. It is included in the JCL rather than being read from a dataset. The instream data is terminated by either a '/*' (see below) or a new JCL statement being encountered.
In this example 'PGM1 20010201 20010301D' will be passed to the program and stored in the variable PARM-LIST.
Sometimes you will see a '/*' (slash followed by an asterisk) after the parameters (in columns 1 and 2), this tells the system that the instream data is at an end. In most cases you do not need to specify '/*', but it can sometimes be helpful to do so, for example if the SYSIN data is the last thing in the JCL. Eg.


//SYSIN DD *
PGM1 20010201 20010301D
/*


Alternatively you can pass the parameters using the PARM parameter on the EXEC PGM statement.
EG:


//STEP010 EXEC PGM=REPP01,PARM='PGM1 20010201 20010301D' 

This example will achieve exactly the same effect as the SYSIN statement in the previous example. Note that because there are spaces in the parameter you need to enclose the parameter in quotes. The quotes are not considered to be part of the parameter, so they are not passed to the program.
 


JCL PROCs
If you use a piece of JCL often, for example if it is used in several jobs or used in several job steps, then you can define a piece of JCL in a procedure (PROC).
The PROC can be stored in a separate library (PDS) or within the job (an 'In-stream Proc'). JCL in the proc will then be copied into the job and executed as if it was part of the original JCL.
If you store the proc in a library, then the library must be known to the system. Most systems will search a list of libraries to find a proc, if you put your proc into a dataset that is not in this list then the proc will not be found. (Note that you can specify the PROC libraries to be searched, using the JCLLIB statement, although this was not available in earlier versions of MVS).
A JCL Proc is identified by the 'PROC' statement as the first statement.
 Example:


//PH001A PROC 

The 'PH001A' is the name of the PROC, this should be the same as the partitioned dataset member name.
You execute the PROC using an EXEC statement:
 

//STEP050 EXEC PH001A 
If the proc is to be included in the JCL as an in stream proc the proc will be defined first in the JCL before the EXEC procname statement. Instream PROCs must be terminated with a PEND statement. The PEND is not required if the PROC is stored in a PDS.

Example:

//HERC04 JOB(IF0001),CLASS=A,MSGCLASS=X,
//         MSGLEVEL=(1,1)
//*
//PPH001  PROC
//STEPP01 EXEC PGM=IEFBR14
//DD01    DD DSN=HERC04.DATSET.DD01,DISP=SHR
//*
// PEND
//*
//STEP010 EXEC PPH001
//*


You can also specify substitution parameters to customise the JCL to a particular set of circumstances. Substitution parameters are variable names that take on a specified value when you execute the proc. For example if you want to run the same proc in different environments, you may have different dataset names, so instead of having a different proc for each environment you can use the same one but with different values for each environment.
If you are running the same proc for say production systems and development systems, but in production datasets begin with, say PROD, and development datasets begin with DEV, then substitution parameters are ideal. Alternatively you may want to specify a different output class each time you run a proc, again substitution parameters are useful.
You specify that you want to use a substituted value by prefixing the variable name with an '&' symbol.


//SYSOUT DD SYSOUT=&OCLASS 

When you submit the JCL to be run, the &OCLASS will be replaced by whatever value is assigned to it. You can assign a value in a couple of different ways.

1) You can specify the value on the PROC statement.
 

//PROC1 PROC OCLASS=A,JCLASS=B 
In this case each time the proc is run &OCLASS will be substituted by the letter A, and &JCLASS will be substituted by the letter B.

You can override these values on the EXEC procname statement.

 //HERC04 JOB XYX000,CLASS=A,MSGLEVEL=(1,1),
//         NOTIFY=HERC04,MSGCLASS=Q
//*
//STEP010 EXEC PROC1,OCLASS=X,JCLASS=Y
//*
//STEP020 EXEC PROC1,OCLASS=R,JCLASS=S
 

In this example PROC will be executed twice. The first time the proc is executed OCLASS will be substituted by X, JCLASS will be substituted by Y. On the second execution of the proc OCLASS will be substituted by R, and JCLASS will be substituted by S.
 

2) You can use the JCL SET statement.
 

//OCLASS SET OCLASS=X
//JCLASS SET JCLASS=Y
 

The SET statement can appear anywhere in the JCL (as long as it is after the job card), including inside the proc.

//HERC04 JOB XYX000,CLASS=A,MSGLEVEL=(1,1),
//   NOTIFY=HERC04,MSGCLASS=Q
//*
//OCLASS  SET OCLASS=X
//JCLASS  SET JCLASS=Y
//STEP010 EXEC PROC1
//*
//OCLASS  SET OCLASS=R
//JCLASS  SET JCLASS=S
//STEP020 EXEC PROC1


Note that the 'ddname' of the SET statement does not have to be the same as the variable name you are setting, it can be anything you want, but it is neater to have them the same.
If you use a variable name on a dataset name and the variable name is followed by a period (.) then you MUST include an extra period after the variable name. This is so that the system knows where the variable name ends.
For example if your dataset name is PROD.CLIENTS.LIST and you want to have a variable &ENV for the 'PROD' part of the name you would have to specify the name in the JCL as &ENV..CLIENTS.LIST


//HERC04J JOB XYX000,CLASS=A,MSGLEVEL=(1,1),
//    NOTIFY=HERC04,MSGCLASS=Q
//ENV     SET ENV=PROD
//*
//PROC1   PROC
//STEP010 EXEC PGM=REPRTPGM
//*
//DD01    DD DSN=&ENV..CLIENTS.LIST,DISP=SHR
//*
// PEND
//*
//STEP010 EXEC PROC1


When this jcl is executed the dataset name will be interpreted as PROD.CLIENTS.LIST. If you were to forget the extra period then the name would be interpreted as PRODCLIENTS.LIST and you would get a JCL error, because
 1) the dataset does not exist and
 2) the first part of the name is longer than 8 characters.



STEPLIBs and JOBLIBs

Sometimes you have to tell the computer where your program is located. (For example, if you have the program located in your own private library, or if you want to test a new version of your program without disturbing the existing program). You can use STEPLIB and JOBLIB to tell the computer where the program you want to run will be.
STEPLIB and JOBLIB will have a DD statement, containing the names of the Load Libraries that are to be looked at in order to find the program.
As their names imply, STEPLIB applies only to a particular Job Step, while JOBLIB applies to the whole job.
If you specify both, then the STEPLIB will override anything specified in the JOBLIB, but only for that particular step.
A JOBLIB statement will be specified after the Job Card, but before any Job steps. The STEPLIB will be specified after the EXEC PGM statement of the job step.


//HERC04J JOB (HERC04),'HERC04',CLASS=A,MSGCLASS=T
//JOBLIB DD DSN=GEN00.DEV.LOADLIB,DISP=SHR
//*
//STEP010 EXEC PGM=PROGR1
//*
//STEP020 EXEC PGM=PROGR2
//STEPLIB DD DSN=TRT01.DEV.LOADLIB,DISP=SHR
//*
//STEP030 EXEC PGM=PROGR3
//*
//STEP040 EXEC PGM=PROGR4


In this example the programs PROGR1 (in STEP010), PROGR3 (in STEP030) and PROGR4 (in STEP040) will all be run from the library GEN00.DEV.LOADLIB, because it is specified in JOBLIB. PROGR2 (in STEP020) will be run from TRT01.DEV.LOADLIB, because it is specified in the STEPLIB, and the STEPLIB overrides the JOBLIB.



Thursday, November 1, 2012

COBOL: How can I get the date a program was compiled?


If you want to get the date of compilation of a program (for example you may want to display it to ensure you are using the correct version of the program), then you can use the special register WHEN-COMPILED. This returns the date and time of compilation as a 16 character string formatted as MM/DD/YYhh.mm.ss . You cannot modify the WHEN-COMPILED register.
 

MOVE WHEN-COMPILED TO WS-COMP-DATE.


If you are using COBOL for OS/390 then you can also use the intrinsic function WHEN-COMPILED to get the compile date. This returns a 21 character string, but only the first 16 characters are used. The string is in the format YYYYMMDDhhmmsszz (where zz is hundredths of a second)


MOVE FUNCTION WHEN-COMPILED TO WS-COMP-DATE.