Easytrieve Manual

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 44

Easytrieve Induction Manual

Narayana kandi

1
Easytrieve

Easytrieve is a programming languages used to generating reports.


Easytrieve is a product of CA, Inc. (Computer Associates). Easytrieve is an
information retrieval and data management system designed to simplify typical
programming tasks.

Easytrieve syntax is a combination of the COBOL and BASIC programming


languages and is meant to be easy to use by non-programmers. It is simple
enough for a beginner to use without additional training.

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.

The Activity Definition section is


where the programming logic is
defined. This section is where all
file processing, data
manipulation, sorting, and
reporting is programmed. Of
course, the Activity Definition
section is required in every
Easytrieve program. 

3
MODES OF OPERATION
 Easytrieve provides five modes of operation that
facilitate production as well as ad-hoc programming.

 Syntax check source statements


 Syntax check and compile source statements
 Syntax check, compile and execute source
statements (Default)
 Syntax check and compile source statements and
produce an object module
 Execute previously link edited programs

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

Variable block Files


FILE FILE1 VB(80 200)

VSAM files
FILE FILE1 VS

6
Easytrieve – File Handling and File Declaration

File record definition  


FILE FILE1 FB(80 200)
   IN-REC 1 80 A
    IN-FIELD1 IN-REC 40 A
    IN-FIELD2 IN-REC +40 20 A
    IN-FIELD3 IN-REC +60 20 A
(OR)
FILE FILE1 FB(80 200)
   IN-REC 1 80 A
   IN-FIELD1 1 40 A
   IN-FIELD2 41 20 A
   IN-FIELD3 61 20 A
If field1 and Field2 are not used, then just Field3 can be defined
FILE FILE1 FB(80 200)
   IN-REC 1 80 A
   IN-FIELD3 61 20 A
Simply use * as starting position, if you declare all the variables in contiguous locations, and you are not using any group variables.
FILE FILE1 FB(80 200)
   IN-FIELD1 * 40 A
   IN-FIELD2 * 20 A
   IN-FIELD3 * 20 A

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,)

 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 INFILE
    PUT OUTFILE FROM INFILE
 END-JOB 8
Writing to Variable block files

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)

 FILE INFILE VB(80 200)


   IN-REC 180 A
 FILE OUTFILE VB(80 200)
   OUT-REC 180 A
   JOB INPUT NULL
 GET INFILE
 DO WHILE NOT EOF INFILE
   MOVE IN-REC TO OUT-REC
   OUTFILE :RECORD-LENGTH = INFILE :RECORD-LENGTH
   PUT OUTFILE
   GET INFILE
 END-DO
 STOP  

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

JOB INPUT NULL

 DO WHILE IND1 LE 30


      IF FULL-NAME-ARRAY(IND1) NE ' '
         CASE FLAG
            WHEN 1
              MOVE FULL-NAME-ARRAY(IND1) TO FIRST-NAME-ARRAY(IND2)
            WHEN 2
              MOVE FULL-NAME-APRAY(IND1) TO MID-NAME-ARRAY(IND2)
            WHEN 3
              MOVE FULL-NAME-ARRAY(IND1) TO LAST-NAME-ARRAY(IND2)
         END-CASE
         IND2 = IND2 +1
      ELSE
         IND2 = 1
         FLAG = FLAG +1 Output will be
      END-IF
      IND1 = IND1 +1
   END-DO
    KARTHIK
DISPLAY FIRST-NAME
   DISPLAY MID-NAME KAR
   DISPLAY LAST-NAME
STOP THIK  
11
Easytrieve Error messages A0** and B0*

A001 File OPEN Error


A002 Invalid block Size
A003 Insufficient Core storage
A005 I/O error
A007 Table input not in sequence
A008 Too many table entries
A009 report processing terminated due to sort error
A012 Invalid Length of file name
A013 wrong record length for a file

B003 Expected continuation not received


B004 Report Exceeds page size
B010 Invalid Block size
B011 Table input not in sequence
B012 Duplicate name for a file, field or report
B027 Not a valid name file, field or report
B048 Field name not in file
B094 Invalid record format

12
SYSDATE and SYSTIME in Easytrieve

SYSDATE and SYSTIME are keywords in


  Easytrieve that will return Current
LIST ON System date and System time
 JOB INPUT NULL respectively.
   DISPLAY SYSDATE
   DISPLAY SYSTIME
 STOP
*

Output will be
07/02/12
04.40.47

13
JOB statement with START and FINISH procs in Easytrieve

JOB INPUT NULL START BEGIN-PROC


In this program,
FINISH FINAL-PROC
   PERFORM MID-PROC BEGIN-PROC will execute
   DISPLAY' IN THE JOB ' first
 STOP (Before starting the JOB block)
* FINAL-PROC will be
 BEGIN-PROC. PROC executed after the JOB
   DISPLAY' STARTING ..'
statements are complete.
 END-PROC
*
 FINAL-PROC. PROC Hence, output will look
   DISPLAY' ENDING ..' like,
 END-PROC
*
 MID-PROC. PROC STARTING ..
   DISPLAY' MIDDLE ..' MIDDLE ..
 END-PROC IN THE JOB
*
ENDING ..
14
PROC (perform paragraph) 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

How to use this in an Easytrieve program?

FILE INFILE FB(80 200)


  %MYFILE
*
 JOB INPUT NULL
 GET INFILE
...
 STOP.

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)

MACRO FNAME PREFIX


&FNAME.
&PREFIX.-REC  1 80 A
&PREFIX.-KEY  1 8 A

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?

 FILE INFILE FB(80200)


 %MYFILE IN IN
*
 JOB INPUT NULL
 GET INFILE
...
 STOP.

%MYFILE IN IN substitutes as FNAME=IN, PREFIX=IN


If you miss the PANDD in the JCL, or MACRO statement in the MACRO member, you will see an error as
*******B006 MACRO SYSTEM - PDS , ERROR IN MACRO FILE  

18
SAMPLE PROGRAMS

19
Using Files as Lookup tables in Easytrieve

1st File: Lookup table file.

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

Label Format - Includes mailing


LINESIZE labels, form-letters and other

special-purpose reports.
SIZE DOWN

LINESIZE
Syntax of the REPORT statement

REPORT report-name +

[SUMMARY] +

LABELS ([ACROSS literal-1] + Format


[DOWN literal-2] + Determination
[SIZE literal-3] +
[NEWPAGE]) +

[PRINTER file-name] + File Directing

[PAGESIZE ({literal-6a} [literal-6b])] +


[LINESIZE literal-5] +
[SPREAD] + Spacing
[NOSPREAD] + Control
[NOADJUST] +
[NODATE] +
[NOPAGE] +
[LIMIT literal-6] + Testing
[EVERY literal-7] Aids

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 }

JOB INPUT PERSNL NAME FIRST-PROGRAM }


PRINT PAY-RPT }
REPORT PAY-RPT LINESIZE 80 } ACTIVITY SECTION
TITLE 01 'PERSONNEL REPORT EXAMPLE-1' }
LINE 01 DEPT NAME EMP# GROSS }

The above program produces the following output

11/02/88 PERSONNEL REPORT EXAMPLE-1 PAGE 1


DEPT NAME EMP# GROSS
903 WIMN 12267 373.60
943 BERG 11473 759.20
915 CORNING 02688 146.16
935 NAGLE 00370 554.40
911 ARNOLD 01963 445.50

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)

JOB INPUT PERSNL NAME FIRST-PROGRAM

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

901 WALTERS 11211 $424.00 $424.00


903 WIMN 12267 $373.60 $373.60
912 LOYAL 04225 $295.20 $295.20
914 MANHART 11602 $344.80 $344.80
914 VETTER 01895 $279.36 $279.36
914 GRECO 07231 $1,004.00 $722.88 $281.12
914 CROCI 08262 $376.00 $376.00
914 RYAN 10961 $399.20 $399.20
915 CORNING 02688 $146.16 $146.16
917 TALL 11931 $492.26 $492.26
918 BRANDOW 02200 $804.64 $579.35 $225.29
918 EPERT 07781 $310.40 $310.40
919 DENNING 02765 $135.85 $135.85
920 MILLER 05914 $313.60 $313.60

Note: The records are now in order by department number.

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

901 WALTERS 11211 $424.00 $424.00


901 $424.00
903 WIMN 12267 $373.60 $373.60
903 $373.60
912 LOYAL 04225 $295.20 $295.20
912 $295.20
914 MANHART 11602 $344.80 $344.80
VETTER 01895 $279.36 $279.36
GRECO 07231 $1,004.00 $722.88 $281.12
CROCI 08262 $376.00 $376.00
RYAN 10961 $399.20 $399.20
914 $2,403.36

26
CONTROL Reports
 TALLY

A control report system-defined field which contains the number of


detail records that comprise a control break.

Can be coded in a LINE statement or used in calculations within report


procedures

A ten-byte packed-decimal field with zero decimal places

Commonly used when computing for averages for a control level

Slide 27
CONTROL Reports
Example:

FILE EMPFILE FB(150 2100)


DEPT TALLY
EMPNAME 14 10 A
EMPNO 9 5 N
101 5
DEPT 120 3 N
111 3
* produces 126 8
JOB INPUT EMPFILE NAME SAMPLE-TALLY
151 6
PRINT EMPL-REPT
161 4
REPORT EMPL-REPT LINESIZE 80 SUMMARY
201 4
SEQUENCE DEPT EMPNAME
225 6
CONTROL DEPT
301 6
LINE 01 DEPT TALLY
401 6
48

Slide 28
JOB activities
JOB Statement
The JOB statement defines and initiates processing activity.
Also, it identifies the name of the automatic input file.

Syntax : JOB [INPUT file-name] [NAME job-name] +


[START proc-name] [FINISH proc-name]

--You can code JOB statement parameters in any order.

29
Conditional Expressions
Comparing the value of a field to a series or range of values:

IF STATE = 'GA' 'SC' 'TN'


IF CLASS = 'A' THRU 'E'
IF AMT NE 100 THRU 500
IF DEPT = 900 940 THRU 950 960 +
970 THRU 980

Special IF statements to check the integrity of the data in files.


{ ALPHABETIC }
{ NUMERIC }
{ SPACE }
IF field-name [NOT] { SPACES }
{ ZERO }
{ ZEROS }
{ ZEROES }
{ HIGH-VALUES}
{ LOW-VALUES }

Matching Records:

IF [NOT] MATCHED [file-name-1 ... file-name-n]

File Existence

IF [NOT] file-name
IF [NOT] EOF file-name 30
STOP Statement
A STOP statement lets you terminate an activity.

Syntax : STOP [EXECUTE]

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 EXECUTE immediately terminates all CA-Easytrieve/Plus execution.

STOP Example:

IF AMT NOT NUMERIC


STOP
END-IF

---END of SECOND reading.

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]

• A SORT procedure must immediately follow the SORT


statement.
• You invoke a SORT procedure with the BEFORE
parameter.
• The SORT procedure executes for each record from
file-name-1 before passing the record to the sort.

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

JOB INPUT PERSNL NAME ACT-1


PRINT RPT1
REPORT RPT1
LINE 1 NAME DEPT GROSS-PAY

SORT PERSNL TO PAYSORT USING (DEPT GROSS-PAY D) +


BEFORE SELECT-REC NAME SORT-ACTIVITY
SELECT-REC. PROC
IF GROSS-PAY GE 500
SELECT
END-IF
END-PROC

 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 :

FILE PAYMSTR VS UPDATE


REC-KEY 1 3 N
SALARY 94 4 P 2

FILE SALUPD VS CREATE


*
JOB INPUT NULL
POINT PAYMSTR GE '300'
GET PAYMSTR
DO WHILE (REC-KEY < 500 AND NOT EOF PAYMSTR)
SALARY = SALARY * 1.1
WRITE PAYMSTR
PUT SALUPD FROM PAYMSTR
GET PAYMSTR
END-DO
STOP
*

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

VSAM Single Record Addition VSAM Mass-Sequential Record Addition

FILE PAYMSTR VS UPDATE FILE PAYMSTR VS UPDATE


* *
FILE NEWBODS VS FILE NEWBODS VS
EMPL# 1 4 N *
NAME 5 20 A
JOB INPUT NEWBODS
*
PUT PAYMSTR FROM NEWBODS STATUS
JOB INPUT NULL
IF PAYMSTR:FILE-STATUS NOT ZERO
GET NEWBODS
WRITE PAYMSTR ADD FROM NEWBODS STATUS
DISPLAY 'FILE ERROR - ' PAYMSTR:FILE-STATUS
IF PAYMSTR:FILE-STATUS EQ 8 STOP
DISPLAY EMPL# +3 NAME +3 'DUPLICATE RECORD' END-IF
END-IF *
STOP
*

40
Record Deletion
You can delete individual records from a VSAM file with the WRITE
statement using the DELETE parameter as illustrated below.

FILE PAYMSTR VS UPDATE


EMPL# 1 5 N
*
JOB INPUT PAYMSTR
IF EMPL# EQ 44152 THRU 44449
WRITE PAYMSTR DELETE
END-IF
IF EMPL# GE 44450
STOP
END-IF
*

41
Record Update
You can modify and update the current record of a VSAM input file using the WRITE statement as illustrated below

FILE PAYMSTR VS UPDATE


EMPL# W 5 N
NAME 6 20 A
*
JOB INPUT NULL
EMPL# = 41452
READ PAYMSTR, KEY EMPL#, STATUS
IF PAYMSTR:FILE-STATUS NOT ZERO
DISPLAY 'NO PAYMSTR RECORD EXISTS FOR ' EMPL#
STOP
END-IF
IF NAME EQ 'AMAN'
NAME EQ 'NICHOLSON'
WRITE PAYMSTR UPDATE
ELSE
DISPLAY 'EMPLOYEE NUMBER 41452 IS ' NAME
END-IF
STOP
*

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

You might also like