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.

6 thoughts on “Easytrieve – Variable declaration”

  1. Nostalgia brought me here. I first started using Easytrieve at Citibank aka ‘CITIGROUP’
    fourty years ago. My last Easytrieve program was a work of art. Iy was for a small Company with 7 stores and no more than 8 employees in any store. They wanted 4 reports. They added 2 more later on. All reports were sorted by store-number, salesperson production, product code etc. It had one intrenal sort routine that was modified for each report .

  2. Hi Karthik,

    Need help to declare the below file variables in easytrieve in .
    I have them in cobol.

    3 INP-REPMT-MATRIX-X GROUP 40 86 465 380
    5 INP-REPMT-MATRIX(1) OCCURS 20 TIMES
    GROUP 41 86 104 19
    7 INP-RM-UPPER-LIMIT(1) S9(17) 42 86 94 9
    7 INP-RM-AMT(1) S9(17) 43 95 103 9
    7 INP-RM-PERCENT-R REDEFINES INP-RM-AMT
    7 INP-RM-PERCENT-R(1) GROUP 44 95 103 9
    9 FILLER(1) X(4) 45 95 98 4
    9 INP-RM-PERCENT(1) S9(9) 46 99 103 5
    7 INP-RM-FLAG(1) X 47 104 104 1

  3. Hi Lakshmi,

    Can you please use the tool at the top right corner of this site.

  4. Hi,
    I would like to pass JCL- variable to Easytrieve- variable via indata stream by means of SYMBOLS. But it does not work, I get error “B027 NOT A VALID NAME”. Maybe, have you any ideas ?
    Example:
    //SET2 SET AVSKTO=’12345678901′
    //SYSIN DD *,SYMBOLS=JCLONLY
    *easytrieve code
    W-KTO W 11 A
    JOB INPUT INFIL
    W-KTO = &AVSKTO.
    *******B027 NOT A VALID NAME – &AVSKTO

  5. I always thought the number zero after the comp-3 identifier ‘P’ meant that the variable is quantitative, which means it is signed, and if it’s in a report definition, it should be summarized. At least, that’s what’s in the manual. What error could I get for not declaring the decimal part?
    Marcello from Brazil

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.