Easytrieve Manual
Easytrieve Manual
Easytrieve Manual
Narayana kandi
1
Easytrieve
2
Easytrieve
Structure of an Easytrieve program The Environment Definition
section is used to specify
A typical Easytrieve program has three
operating parameters and modes
sections: Environment Definition, Library &
for the program and is optional.
Activity Definition.
The Library section is usually
required in every program, and it
is used to define data, such as
any input and output files and
working variables.
3
MODES OF OPERATION
Easytrieve provides five modes of operation that
facilitate production as well as ad-hoc programming.
4
Sample JCL to compile, Link edit and run the Easytrieve program
• //********************************************************************
//* Jcl to compile, Link edit and run the Easytrieve program *
//********************************************************************
//*
//********************************************************************
//* Compile the Easytrieve program *
//********************************************************************
//EZTCOMPL EXEC PGM=EZTPA00
//EZTVFM DD UNIT=SYSDA,SPACE=(CYL,(25,25))
//SYSPRINT DD SYSOUT=*
//SYSABEND DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSLIN DD DSN=&&SYSLIN,
// UNIT=SYSDA,SPACE=(CYL,(20,20),RLSE),DISP=(,PASS)
//SYSIN DD *
PARM LINK(UREZTPGM)
Your Easytrieve code goes here
/*
//*
//*********************************************************************
//* Link Edit the Easytrieve program *
//*********************************************************************
//EZTLINK EXEC PGM=IEWL
//SYSPRINT DD SYSOUT=*
//SYSLMOD DD DSN=YOUR.EZT.LOADLIB,DISP=SHR
//SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(1,5))
//SYSLIN DD DSN=&&SYSLIN,DISP=(OLD,DELETE,DELETE)
//*
//*********************************************************************
//* Run the Easytrieve program *
//*********************************************************************
//EZTRUN EXEC PGM=UREZTPGM
//STEPLIB DD DSN=YOUR.EZT.LOADLIB,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSABEND DD SYSOUT=*
//SYSOUT DD SYSOUT=* 5
Easytrieve – File Handling and File Declaration
File declaration
File declaration statement will have the keyword ‘FILE’ and then the DD Name of the file.
FILE FILE1
Fixed block files
FILE FILE1 FB(80 200)
*80 is LRECL and 200 is blocksize
VSAM files
FILE FILE1 VS
6
Easytrieve – File Handling and File Declaration
7
Reading File record by record and copy it to another file
EOF <DD NAME> checks the End of File, and returns true when there are no more records to fetch.
GET <DD NAME> statement is used to read one record from the file
PUT <DD NAME> statement is used to write one record to the file
=================================================================================
FILE INFILE FB(80 200)
IN-REC 1 80 A
FILE OUTFILE FB(80 200)
OUT-REC 1 80 A
*
WS-COUNT W 4 N VALUE 0
*
JOB INPUT NULL
GET INFILE
DO WHILE NOT EOF INFILE
MOVE IN-REC TO OUT-REC
PUT OUTFILE
WS-COUNT = WS-COUNT + 1
GET INFILE
END-DO
DISPLAY WS-COUNT ' RECORDS WRITTEN'
STOP
(Or Simply,)
For Variable block files, in addition to writing the record, we also need to specify the
Record length of the record. Below example will help you understand on how to do
that. (RECORD-LENGTH keyword is the one that you need to note)
9
Reading VSAM file by Key
FILE FILE1 FB(80 200)
IN-REC 1 80 A
IN-KEY 1 8 A
FILE FILE2 VS
F2-REC 180 A
F2-KEY 1 8 A
F2-VALUE 15 30 A
FILE OUTFILE FB(80 200)
OUT-REC 180 A
OUT-KEY 18 A
OUT-VALUE 10 30 A
JOB INPUT NULL
GET FILE1
DO WHILE NOT EOF INFILE
READ FILE2 KEY IN-KEY STATUS
IF FILE2 :STATUS EQ 0
MOVE IN-KEY TO OUT-KEY
MOVE F2-VALUE TO OUT-VALUE
PUT OUTFILE
ELSE
DISPLAY IN-KEY ' NOT PRESENT IN VSAM FILE'
END-IF
GET INFILE
END-DO
STOP
10
Easytrieve program to parse a string
FULL-NAME contains ‘KARTHIK KAR THIK’, which is split into First name, Middle name and Last name.
==============================================
DEFINE IND1 W 3 N VALUE 1
DEFINE IND2 W 3 N VALUE 1
DEFINE FLAG W 1 N VALUE 1
DEFINE FULL-NAME W 30 A VALUE 'KARTHIK KAR THIK‘
DEFINE FIRST-NAME W 1 5 A
DEFINE MID-NAME W 1 5 A
DEFINE LAST-NAME W 1 5 A
DEFINE FULL-NAME-ARRAY FULL-NAME 1 A OCCURS 30
DEFINE FIRST-NAME-ARRAY FIRST-NAME 1 A OCCURS 15
DEFINE MID-NAME-ARRAY MID-NAME 1 A OCCURS 15
DEFINE LAST-NAME-ARRAY LAST-NAME 1 A OCCURS 15
12
SYSDATE and SYSTIME in Easytrieve
Output will be
07/02/12
04.40.47
13
JOB statement with START and FINISH procs in Easytrieve
File INMAST:
FILE INMAST FB4 0001
IN-NUM 1 4 N 0002
JOB INPUT INMAST 0003
PERFORM DISP-LINE 0004
END-JOB
*
DISP-LINE. PROC Output of this program is
DISPLAY'IN-NUM IS: 'IN- IN-NUM IS: 0001
NUM IN-NUM IS: 0002
END-PROC IN-NUM IS: 0003
* IN-NUM IS: 0004
15
SORT in Easytrieve
The Syntax is
SORT file-name-1 +
• Simple Sort on a key
TO file-name-2+
USING (field-name [D]...) +
[BEFORE proc-name]
FILE INFILE FB(80
• file-name-1 is the input file DD 960)
Name
• file-name-2 is the Sorted output
ACCOUNT-NO 1 8 N
file *
• field-name is the field defined in
file-name-1, based on which the FILE OUTFILE
file has to be sorted
• If you want the sort to be on
*
Descending order, pass the SORT INFILE
parameter ‘D’ after the field name
• If you have any select criteria to TO OUTFILE
filter what records to be written
in the output file, have it in a USING
Proc and give the proc name with
BEFORE parameter (optional) ACCOUNT-NO
16
Easytrieve MACROs (Copybook)
Easytrieve MACROs are similar to COBOL Copybooks.
A Sample Macro: MYDATA.SET.MACROS(MYFILE)
MACRO
INFILE
IN-REC 1 80 A
IN-KEY 1 8 A
The statement %INFILE includes the Macro MYFILE, into the program.
The dataset containing the Macros should be mentioned in the JCL as
//PANDD DD DSN=MYDATA.SET.MACROS,DISP=SHR
17
Macros with Parameters:
MYDATA.SET.MACRO(MYFILE)
FNAME and PREFIX are the parameters. Use an &VARIABLE. to substitute a variable (An Ampersand in the beginning and a dot in the
end).
How to use this in an Easytrieve program?
18
SAMPLE PROGRAMS
19
Using Files as Lookup tables in Easytrieve
01 JANUARY This Can be achieved by the following program which uses the
02 FEBRUARY LOOKUP1 file as a table.
03 MARCH
04 APRIL
05 MAY FILE LOOKUP1 TABLE
06 JUNE ARG 1 2 A
07 JULY DESC 4 15 A
08 AUGUST FILE ACTUAL
ACTUAL-REC 1 80 A
09 SEPTEMBER
MONTH-LIST 1 2 A
10 OCTOBER FILE OUTFILE
11 NOVEMBER OUT-REC 1 80 A
12 DECEMBER OUT-MONTH-NUM 1 2 A
OUT-MONTH-NAME 4 15 A
JOB INPUT NULL
GET ACTUAL
DO WHILE NOT EOF ACTUAL
MOVE MONTH-LIST TO OUT-MONTH-NUM
05 SEARCH LOOKUP1 WITH MONTH-LIST, GIVING OUT-MONTH-
12 NAME
2nd
33 File: for which the month names IF NOT LOOKUP1
have
03 to be read from the above file. MOVE 'INVALID MON‘ TO
OUT-MONTH-NAME
END-IF
PUT OUTFILE
05 MAY GET ACTUAL
END-DO
12 DECEMBER STOP.
33 INVALID MON
03 MARCH
OUTFILE:
REPORT TYPES
Standard format - Default format consisting of Title area,
Heading area and Report Body.
TITLE AREA
HEADING AREA
PAGESIZE
REPORT BODY
special-purpose reports.
SIZE DOWN
LINESIZE
Syntax of the REPORT statement
REPORT report-name +
[SUMMARY] +
22
Sample Report Program 1
FILE PERSNL FB(150 1800) }
NAME 17 8 A }
EMP# 9 5 N } LIBRARY SECTION
DEPT 98 3 N }
GROSS 94 4 P 2 }
23
Program 1(some minor changes)
FILE PERSNL FB(150 1800)
NAME 17 8 A
EMP# 9 5 N (HEADING ('EMPLOYEE' 'NUMBER')
DEPT 98 3 N
GROSS 94 4 P 2 MASK (A '$$,$$9.99')
NET-PAY W 4 P 2 MASK A
DEDUCTIONS W 4 P 2 MASK (A BWZ)
IF GROSS GE 500
DEDUCTIONS = .28 * GROSS
NET-PAY = GROSS—DEDUCTIONS
ELSE
NET-PAY = GROSS
DEDUCTIONS = 0
END-IF
PRINT PAY-RPT
REPORT PAY-RPT LINESIZE 80
SEQUENCE DEPT
TITLE 01 'PERSONNEL REPORT EXAMPLE-1'
LINE 01 DEPT NAME EMP# GROSS NET-PAY DEDUCTIONS
24
When we run our program, here is what we get:
11/18/88 PERSONNEL REPORT EXAMPLE-1 PAGE 1
EMPLOYEE
DEPT NAME NUMBER GROSS NET-PAY DEDUCTIONS
25
The SUM statement specifies the quantitative fields you want totaled on a control break.
===============================================================================
REPORT PAY-RPT LINESIZE 80
SEQUENCE DEPT
CONTROL DEPT
SUM GROSS (Now, GROSS is the only field totaled)
TITLE 01 'PERSONNEL REPORT EXAMPLE-1‘
HEADING NAME ('EMPLOYEE' 'NAME')
LINE 01 DEPT NAME EMP# GROSS NET-PAY DEDUCTIONS
================================================================================
11/18/88 PERSONNEL REPORT EXAMPLE-1 PAGE 1
EMPLOYEE EMPLOYEE
DEPT NAME NUMBER GROSS NET-PAY DEDUCTIONS
26
CONTROL Reports
TALLY
Slide 27
CONTROL Reports
Example:
Slide 28
JOB activities
JOB Statement
The JOB statement defines and initiates processing activity.
Also, it identifies the name of the automatic input file.
29
Conditional Expressions
Comparing the value of a field to a series or range of values:
Matching Records:
File Existence
IF [NOT] file-name
IF [NOT] EOF file-name 30
STOP Statement
A STOP statement lets you terminate an activity.
STOP ends the current JOB or SORT activity, completes the report processing for
the activity if any, and then goes on to the next JOB or SORT activity if one
exists. A FINISH procedure (if one is present) is still executed before going
on to the next JOB or SORT activity.
STOP Example:
31
MOVE Statement: The MOVE statement has two formats.
MOVE Format 1:
MOVE NAME 20 TO HOLD-NAME
MOVE NAME CTR TO HOLD-NAME FILL '*’
MOVE Format 2:
{ SPACE }
{ SPACES }
MOVE { ZERO } TO field-name-1 field-name-n
{ ZEROS }
{ ZEROES }
MOVE LIKE: MOVE LIKE moves the contents of fields in one file to
identically named fields in another file.
Example:
FILE INFILE1
NAME 17 20 A
DEPT 98 3 N
AMT 90 4 P 2
FILE OUTFIL1
AMT 1 7 N 2
NAME 8 11 A
----> MOVE LIKE INFILE1 TO OUTFIL1
32
SORT Procedures
Syntax:
SORT file-name-1 TO file-name-2 +
USING (field-name [D] ... ) +
NAME sort-name +
[BEFORE proc-name]
33
SORT Procedure Example
FILE PERSNL FB(150 1800)
NAME 1 10 A
DEPT 11 5 N
GROSS-PAY 16 4 P 2
FILE PAYSORT F(19) VIRTUAL
SORT-NAME 1 10 A
SORT-DEPT 11 5 N
SORT-GROSS-PAY 16 4 P 2
In the above example, SELECT-REC is the name of the SORT procedure. The procedure
selects only those records with a gross pay of greater than or equal to 500 for
sorting
34
Use of the POINT statement
FILE PAYFILE VS ...
REC-KEY 1 3 N
*
JOB INPUT NULL
POINT PAYFILE GE 500
GET PAYFILE
DO WHILE (REC-KEY < 600 AND NOT EOF PAYFILE)
PRINT PAY-RPT
GET PAYFILE
END-DO
STOP
*
REPORT PAY-RPT ...
(The statements in the above exhibit retrieve those records with keys
between 500 and 599 inclusive from file PAYFILE and output them to report
PAY-RPT. )
35
READ Statement
The READ statement provides random access to keyed and relative-
record VSAM and ISAM files.
Syntax
READ file-name KEY field-name [STATUS]
36
WRITE Statement
Use the WRITE statement to maintain keyed and relative-
record VSAM files (ISAM files are read/only). WRITE
updates or deletes the current record of the named file,
or adds new records.
Syntax
[DELETE]
WRITE file-name-1 [UPDATE] [FROM file-name-2]
[ADD ]
37
ISAM Files: Indexed Sequential Access Method (ISAM)
files are processed as input only. You can perform sequential,
skip-sequential, or random processing on these files.
Skip-Sequential Processing Random Processing
FILE PAYFILE IS FILE PAYFILE IS
REC-KEY 1 3 N EMPL# W 4 N
SALARY 94 4 P 2 NAME 5 20 A
* *
JOB INPUT PAYFILE FILE NEWFILE VS CREATE
IF REC-KEY EQ 299 THRU 499 *
PERFORM POINTER JOB INPUT NULL
GO TO JOB EMPL# = 1126
END-IF READ PAYFILE, KEY EMPL#, STATUS
SALARY = SALARY * 1.1 IF PAYFILE:FILE-STATUS NOT ZERO
PRINT UPD-RPT DISPLAY 'RECORD NOT FOUND'
* STOP
POINTER. PROC END-IF
POINT PAYFILE GE 500 STATUS IF NAME EQ 'OLDNAME'
IF EOF PAYFILE, OR PAYFILE:FILE- NAME = 'NEWNAME'
STATUS NOT ZERO PUT NEWFILE
STOP ELSE
END-IF DISPLAY 'NAME DOES NOT MATCH'
END-PROC END-IF
STOP
*
38
VSAM Files
File Loading :
This routine updates the PAYMSTR records between 300 and 499 with a
10% salary increase and also loads the updated records into the newly
created file SALUPD.
39
Record Addition
40
Record Deletion
You can delete individual records from a VSAM file with the WRITE
statement using the DELETE parameter as illustrated below.
41
Record Update
You can modify and update the current record of a VSAM input file using the WRITE statement as illustrated below
42
Report procedures
• REPORT-INPUT
• BEFORE-LINE
• AFTER-LINE
• BEFORE-BREAK
• AFTER-BREAK
• ENDPAGE
• TERMINATION
43
Special-name Report Procedures:
REPORT-INPUT: Final screening of report input data.
Report data can be selected and/or modified.
BEFORE-LINE: Detail line has been created but not
yet printed. Typical use is to annotate the body of
the report before line printing. Detail line data
cannot be modified.
AFTER-LINE: Detail line has been printed. Typical
use is to annotate the body of the report after each
line is printed.
BEFORE-BREAK: Modification of totals before total
line printing. Typical use is to calculate averages
on control reports.
AFTER-BREAK: Total line has been printed. Typical
use is special annotation following total lines on
control reports.
ENDPAGE: At end-of-page. This procedure can be used
to produce footers on each page of the report.
TERMINATION: At end-of-report. Produce end-of-report
information, such as hash or other control totals. 44