JOB statement with START and FINISH procs in Easytrieve

Consider reading about JOB INPUT statements and PROCs in Easytrieve to know about JOB and PROC in easytrieve (not the usual JOB and PROC in JCL !).

 LIST ON
 JOB INPUT NULL START BEGIN-PROC FINISH FINAL-PROC
   PERFORM MID-PROC
   DISPLAY ' IN THE JOB '
 STOP
*
 BEGIN-PROC. PROC
   DISPLAY ' STARTING ..'
 END-PROC
*
 FINAL-PROC. PROC
   DISPLAY ' ENDING ..'
 END-PROC
*
 MID-PROC. PROC
   DISPLAY ' MIDDLE ..'
 END-PROC
*

In the above program, BEGIN-PROC will execute first (before starting the JOB block) and FINAL-PROC will be executed after the JOB statements are complete. hence, output of this program will look like,

 STARTING ..
 MIDDLE ..
 IN THE JOB
 ENDING ..

REXX – Reading a sequential file into a STEM (array)

The below REXX program gets a PS file my.seq.dsn into a STEM (array).
We can immediately FREE the file, since the file data has now copied to an internal variable.

/******REXX******/
ADDRESS TSO                                     
"ALLOC F(INFILE) DSN('my.seq.dsn') SHR REU"    
/* INFILE is a logical name for the file */
"EXECIO * DISKR INFILE ( FINIS STEM MYFILE." 
/* MYFILE is the stem (array) that holds the data */
"FREE F(INFILE)"
I = 1
/* MYFILE.0 will have the number of */
/* elements in the stem             */
DO WHILE I <= MYFILE.0
   SAY ' LINE ' I ' : ' MYFILE.I
   I = I + 1
END
EXIT

INFILE – my.seq.dsn

MY
DATA
SET
IS THIS

Result of the above Rexx program is:

 LINE 1 : MY
 LINE 2 : DATA
 LINE 3 : SET
 LINE 4 : IS THIS

PROC (perform paragraph) in Easytrieve

As we use paragraph / section in COBOL, that can be executed multiple times using perform statement, we can use PROC in Easytrieve that can be called using PERFORM statement.

Below example will help you understand the syntax of PROC and PERFORM.

 LIST ON
 FILE INMAST FB 4
    IN-NUM 1 4 N
 JOB INPUT INMAST
  PERFORM DISP-LINE
 END-JOB
*
 DISP-LINE. PROC
   DISPLAY 'IN-NUM IS: ' IN-NUM
 END-PROC
*

File INMAST:

0001
0002
0003
0004

the output of this program is

IN-NUM IS: 0001
IN-NUM IS: 0002
IN-NUM IS: 0003
IN-NUM IS: 0004

SORT in Easytrieve

You can Sort a file into another file in Easytrieve. The Syntax is

 SORT file-name-1 +
 TO file-name-2 +
 USING (field-name [D]...) +
 [BEFORE proc-name]
  • file-name-1 is the input file DD Name
  • file-name-2 is the Sorted output file
  • field-name is the field defined in file-name-1, based on which the file has to be sorted
  • If you want the sort to be on Descending order, pass the parameter ‘D’ after the field name (by Default, it will be Ascending)
  • If you have any select criteria to filter what records to be written in the output file, have it in a Proc and give the proc name with BEFORE parameter (optional)

Let us see a couple of sample programs to explain.

Simple Sort on a key

The below program will simply

 FILE INFILE FB(80 960)
   ACCOUNT-NO  1 8 N
*
 FILE OUTFILE
*
 SORT INFILE TO OUTFILE USING ACCOUNT-NO

being updated..

EDIT MASKS – Masking variables in Easytrieve

have you already read Easytrieve Variable declaration?

For creating reports, or printing (displaying) numeric variables, we will always need masking. It can be used to print the decimal character for the variables that have implied decimal

 WS-SSN W 9 N MASK '999-99-9999'
 ...
 MOVE 123456789 TO WS-SSN
 DISPLAY ' WS-SSN : ' WS-SSN

This will be printed as

 WS-SSN : 123-45-6789

Edit mask pattern is created by using combinations of the following characters:

9 — causes a digit to print. (including leading zeros)

Z — causes a digit to print (except for leading zeros)

$ — causes a currency symbol to print prior to the first non-zero digit

more examples to come..

DISPLAY statement in Easytrieve

DISPLAY statement in Easytrieve is exactly the same as in COBOL.

 WS-VAR1 W 20 A VALUE 'I AM INITIALIZED HERE'
 ...
 DISPLAY 'value of WS-VAR1 is: ' WS-VAR1

This will be printed as

 value of WS-VAR1 is: I AM INITIALIZED HERE

If you want to continue the DISPLAY statement in multiple lines, use ‘+’ symbol as continuation character

 WS-VAR1 W 20 A VALUE 'I AM INITIALIZED HERE'
 ...
 DISPLAY 'value of WS-VAR1 is: ' +
         WS-VAR1

CA11-U11RMS Restart utility parameters

CA11 is a utility from Computer Associates that helps to re-run a job multiple times and also to restart from abended steps, taking care of what files to be used when we rerun.

We need to specify a restart parameter that tells CA11 – how we want the job to be run. Valid parameters are nP, nR, nN and more (n = 0,1,2,3,..)

P for Production run (0P, 1P, 2P, .. nP)

  • The job will execute from the first step.
  • if any file with DISP=(NEW,*,*) already exist in catalogue, it will be deleted and re-created as defined in the current JCL job.

When we submit a job for first time, a parameter of ‘0P’ will be passed.
Due to any failure, if we need to run the job for a second time, and start from first step, pass a parameter ‘1P’.
If that fails again, and you need to run again from the beginning, use ‘2P’. (and so on…)
R for Restart/Rerun (1R, 2R, .. nR)

  •  the job will start from last abended step
  •  all the files, GDG file versions used in the last run of the job will be used
  •  After the failure of first ‘0P’ run, if we want to restart from the failed step, pass ‘1R’ as the parameter. Consecutive restart runs should have ‘2R’ ,’3R’, and so on..

N for Null (1N, 2N,.. nN)

  •  CA11 utility will not perform anything, and just allow your job to run.
  • but for every consecutive run, you need to change the number like 0N, 1N, 2N,.. etc

Note: if you do not change the number n in the parameter you will be getting a user abend U0060 saying that the parameter was not changes since the last run. However if your job has been completed successfully and you are rerunning the job, you do not need to change the number n.