Keywords

Easytrieve
IF ELSE DO FILE REPORT OR AND EQ NE GT GE NE LT LE LIST ON JOB INPUT NULL EOF GET PUT FROM RECORD-LENGTH END-IF END-DO WHILE NOT STOP A N P B KEY STATUS NODATE NOPAGE NOADJUST NOSPREAD NOHEADING LINE TITLE COL W PAGESIZE LINESIZE PRINT VB FB VS VALUE MASK PRINTER MOVE ADD TO DISPLAY READ WRITE OCCURS INDEX

DB2

SELECT FROM CREATE DELETE UPDATE TABLE DECLARE DEFAULT WHERE AND OR IN NOT ORDER GROUP BY CURSOR CURRENT TIME TIMESTAMP CURRENT_TIME CURRENT_TIMESTAMP GLOBAL TEMPORARY INTO FETCH INTEGER CHAR VARCHAR SMALLINT DECIMAL NUMERIC DATE CURRENT_DATE INSERT COMMIT FETCH VALUES ALTER ROWS

JCL

JOB EXEC DD PGM STEPLIB JOBLIB JCLLIB DSN DISP SYSOUT PROGRAM PARM PLAN LIB SYSTEM SHR NEW CATLG DELETE OLD OMIT INCLUDE

Easytrieve File matching : Synchronized Files

File1

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
A1
B1
D1

File2

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
XXX A1 YYYY ZZZZ
CCC A1 DDDDDDDDD
DDD A2 UUUUUUUUU
RRR B1 TTTTTTTTT
XXX B1 YYYY ZZZZ
CCC C1 DDDDDDDDD
DDD C2 UUUUUUUUU
RRR D1 TTTTTTTTT

Output File Should have only the records from file2, with second column values which are present in File1.
File1 has unique records
File2 should be in sorted order (Second column)
Ie,
OUTFILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
XXX A1 YYYY ZZZZ
CCC A1 DDDDDDDDD
RRR B1 TTTTTTTTT
XXX B1 YYYY ZZZZ
RRR D1 TTTTTTTTT

This Can be achieved in two ways. The first way is,

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE FILE1
   F1-REC 1 50 A
   F1-KEY 1 2 A
 FILE FILE2
   F2-REC 1 50 A
   F2-KEY 5 2 A
 FILE OUTFILE
     OUT-REC 1 50 A
 JOB INPUT NULL
 GET FILE1
 GET FILE2
 DO WHILE NOT EOF FILE1 AND NOT EOF FILE2
   DO WHILE F2-KEY LE F1-KEY
      IF F1-KEY EQ F2-KEY
         PUT OUTFILE FROM FILE2
      END-IF
      GET FILE2
      IF EOF FILE2
         STOP
      END-IF
   END-DO
   GET FILE1
 END-DO
 STOP.

and the second way is,
Using JOB INPUT (FILENAME KEY(KEYNAME) FILENAME KEY(KEYNAME))

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE FILE1
          F1-REC           1    50   A
          F1-KEY           1     2   A
 FILE FILE2
          F2-REC           1    50   A
          F2-KEY           5     2   A
 FILE OUTFILE
 OUT-REC     1  50 A
 JOB INPUT (FILE1 KEY(F1-KEY)  FILE2 KEY(F2-KEY))
 IF MATCHED
     PUT OUTFILE FROM FILE2
 END-IF
 GO TO JOB

Matching the files in another way

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE FILE1
          F1-REC           1    50   A
          F1-KEY           1     2   A
 FILE FILE2
          F2-REC           1    50   A
          F2-KEY           5     2   A
 FILE OUTFILE
 OUT-REC     1  50 A
 JOB INPUT (FILE1 KEY(F1-KEY)  FILE2 KEY(F2-KEY))
 IF FILE1
   IF FILE2
     PUT OUTFILE FROM FILE2
  END-IF
 END-IF
 GO TO JOB

Matching Multiple keys
(FILENAME KEY(KEY1,KEY2) FILENAME KEY(KEY1,KEY2))

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE FILE1
          F1-REC           1    50   A
          F1-KEY1          1     2   A
          F1-KEY2          3     2   A
 FILE FILE2
          F2-REC           1    50   A
          F2-KEY1           5     2   A
          F2-KEY2           9     2   A
 FILE OUTFILE
 OUT-REC     1  50 A
 JOB INPUT (FILE1 KEY(F1-KEY1F1-KEY2)  +
 FILE2 KEY(F2-KEY1,F2-KEY2))
 IF FILE1
   IF FILE2
     PUT OUTFILE FROM FILE2
  END-IF
 END-IF
 GO TO JOB

Easytrieve – Report creation sample

In most of the shops, Easytrieve is used for creating reports; and, Easytrieve has more customizable options for reporting.

Detailed reports:
Below is example 1. The output report file must be defined as FB 133 in the JCL.

In the below example, the input file INMAST contains below data

0001
0002
0003
0004
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE INMAST FB 4
   IN-NUM 1 4 N
 FILE OUTFILE PRINTER
 JOB INPUT INMAST
    PRINT TEMP-REPT
 END-JOB
*
 REPORT TEMP-REPT PRINTER OUTFILE
 TITLE 1 'ANNUAL REPORT'
 LINE  IN-NUM
*

Output will look like

106/02/12            ANNUAL REPORT         PAGE 1
-                       0001
0                       0002
                        0003
                        0004

Example 2:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE INMAST FB 4
   IN-NUM 1 4 N HEADING ('ACCOUNT' 'NUMBER')
 FILE OUTFILE PRINTER
 JOB INPUT INMAST
    PRINT TEMP-REPT
 END-JOB
*
 REPORT TEMP-REPT PRINTER OUTFILE PAGESIZE 50 +
 NOSPREAD NOADJUST NODATE NOPAGE
 TITLE 1 'ANNUAL REPORT'
 LINE  IN-NUM
*

Output will look like

1ANNUAL REPORT
-
 ACCOUNT
 NUMBER
0 0001
  0002
  0003
  0004

Summary reports:
Example 3:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE OUTFILE1 PRINTER
*
 WS-VAL1 W 2 A VALUE 'V1'
 WS-VAL2 W 2 A VALUE 'V2'
 WS-VAL3 W 2 A VALUE 'V3'
*
 JOB INPUT NULL
 PRINT SAMPLE1
 STOP
 REPORT SAMPLE1 PRINTER OUTFILE1 PAGESIZE 55 LINESIZE 80 -
 NODATE NOPAGE NOADJUST NOSPREAD NOHEADING
 TITLE 01 COL 01 'HEADING ' -
          COL 30 'VALUES '
 LINE 01 COL 10 'VAL 1 IS ' -
         COL 30 WS-VAL1
 LINE 02 COL 10 'VAL 2 IS ' -
         COL 30 WS-VAL2
 LINE 03 COL 10 'VAL 2 IS ' -
         COL 30 WS-VAL3

Easytrieve – File Handling and File Declaration

This post will help you in how to Declare a File, Read / Write.

File declaration examples

File declaration statement will have the keyword ‘FILE’ and then the DD Name of the file.

 FILE FILE1

In addition to the Keyword ‘FILE’ and the DD Name, mention the file type VB – variable block, FB – fixed block, VS for VSAM. Also, provide the Record length and blocksize in the format (<LRECL>, <Block Size>)

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

File record definition

The below example shows how to declare file variables. Also, you can read about Macros (Copybooks) in Easytrieve.

 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

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE INFILE
 FILE OUTFILE
 JOB INPUT NULL
 GET INFILE
 DO WHILE NOT EOF INFILE
   PUT OUTFILE FROM INFILE
   GET INFILE
 END-DO
 STOP 

(Or)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 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,)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 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

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)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON 
 FILE INFILE VB(80 200)
   IN-REC 1 80 A
 FILE OUTFILE VB(80 200)
   OUT-REC 1 80 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  

Reading VSAM file by Key

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE FILE1 FB(80 200)
   IN-REC 1 80 A
   IN-KEY 1 8 A  
 FILE FILE2 VS
   F2-REC 1 80 A
   F2-KEY 1 8 A
   F2-VALUE 15 30 A  
 FILE OUTFILE FB(80 200)
   OUT-REC 1 80 A
   OUT-KEY 1 8 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  

Also, you can read Writing / Updating VSAM records

Easytrieve – Variable declaration

This post will help you to understand the dataypes and how to declare a variable in Easytrieve (which is the first step in learning any new language. believe me, Easytrieve is the simplest language that you can learn in a day).

First, we will see the different datatypes available.

Datatypes

Alphanumeric A
Numeric N Maximum length 18
Binary (Comp) B Maximum length 8. i e upto 18 digits
Packed (COMP-3) Define as P 0 Maximum length 9. i e upto 18 digits

A – Alphanumeric – can be used for variables containing Alphabets, numbers, special characters or any data. This is similar to PIC X(nn) in Cobol.

N – Numeric – can be used to have unpacked signed (or unsigned) numbers. This is similar to PIC S9(nn) in Cobol.

B- Binary – can be used to store signed (or unsigned) numbers in binary format. Length of this must be either 2 or 4 or 8 bytes. (similar to PIC S9(nn) COMP in Cobol)

P – Packed – for Packed numeric variables (similar to PIC S9(nn) COMP-3 in Cobol)

Declaring a working storage variable

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 WS-VAR1 W 8 A 
 WS-VAR2 W 8 A VALUE 'KARTHIK ' 
 WS-VAR2 W 9 N VALUE ZEROES 
 WS-VAR3 W 7 N 2 
 WS-VAR4 W 9 P 0 
 WS-VAR5 W 9 P 2

Variable declaration  statement has 4 mandatory parts

1. Variable name

2. Start position of the variable (should be given as W for Working storage variables; in File layouts, use the starting position – no need to add 4 for VB files, start with 1)

3. Number of bytes the variable occupies (note that this is not number of digits but number of bytes)

4. The datatype – A (Alpha), N (Numeric), B (Binary) or P (Packed)

For binary and packed variables if you want to have an implied decimal point (say for two digits), that number of digits should immediately follow the character P (packed), B for Binary.

For eg, the below variable WS-VAR4 is a binary, occupies 4 bytes (total) and has 3 digits (not bytes) after the implied decimal point. and the Packed variable WS-VAR5 occupies 9 bytes (total) and has 2 digits (not bytes) after the implied decimal point.

 WS-VAR4 W 4 B 3 
 WS-VAR5 W 9 P 2

Important note: For Packed variables, even if you don’t want to use any decimal, please declare as P 0 (meaning 0 digits after decimal). If you don’t do that, you may possibly get some error.

 WS-VAR6 W 9 P 0 

Declaring Group variables

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 WS-GROUP W 15 A 
 WS-GR1 WS-GROUP 5 A 
 WS-GR2 WS-GROUP +5 10 A 

Declaring a Group variable is easy – just use the High lever variable (+ offset) as the starting position for the variables that come under the group. Hope the above example helps you to understand.

Using indexed variables

In the below example, you can see an array WS-ALP-ARR with 26 items in it. In addition, it also redefines WS-ALPHA which is of 26 bytes length. We are also using an index ALPHA-NDX for the array WS-ALP-ARR. (We don’t have to declare the index variable)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON 
 FILE INFILE 
 WS-ALPHA W 26 A VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
 WS-ALP-ARR WS-ALPHA 1 A OCCURS 26 INDEX ALPHA-NDX 
* 
 JOB INPUT NULL 
* PRINT 16TH ALPHABET 
 ALPHA-NDX = 15 
 DISPLAY '16TH ALPHABET IS ' WS-ALP-ARR 
 STOP. 

Using arrays/tables

In the above example, we saw an array with Index. Below is a simple array with no index. Hope this example is self explanatory.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON 
 FILE INFILE 
 WS-DAYS-OF-WEEK W 10 A OCCURS 7 
* 
 JOB INPUT NULL 
 MOVE 'SUNDAY' TO WS-DAYS-OF-WEEK(1) 
 MOVE 'MONDAY' TO WS-DAYS-OF-WEEK(2) 
 MOVE 'TUESDAY' TO WS-DAYS-OF-WEEK(3) 
 MOVE 'WEDNESDAY' TO WS-DAYS-OF-WEEK(4) 
 MOVE 'THURSDAY' TO WS-DAYS-OF-WEEK(5) 
 MOVE 'FRIDAY' TO WS-DAYS-OF-WEEK(6) 
 MOVE 'SATURDAY' TO WS-DAYS-OF-WEEK(7) 
 DISPLAY '4 TH DAY IS ' WS-DAYS-OF-WEEK(4) 
 STOP 

Alos, read about REDEFINES in Easytrieve.