Tuesday, October 9, 2007

Dinosaurs - Let's Learn EasyTrieve


Hi All
Thought of sharing my knowledge on Easytrieve this time...I just have beginner's knowledge in it. So if anybody finds any mistakes in my mail please feel free to correct me. As usual this article is published in https:\\ctsdinos.blogspot.com

Easytrieve is a powerful and easy to learn programming language. With few lines of code you could create powerful reports. This is very helpful for any adhoc work or any application development .It also adds value to your Resume :))

I am not going put everything in one mail.. I will just start with a very simple example like a "Hello World" program and then over the subsequent weeks , we will go through in detail.
Requirement .

I have an Input file with the following data

NAME WS-TEST-RECORDWS-EMP-IDWS-NAME WS-DEPT-IDWS-SALARY
TYPE LV1 80 CHR 4 CHR 20 CHR 8 PAC 7
COLUMN(1:80) (1:4) (5:24) (25:32) (33:36)
NUMBER1 2 3 4 5
000001 1123 SUNDAR PANCH ACCTNG 10000.00
000002 2012 PRABHA SUNDAR IT 13000.00
000003 0234 PRASUNYA SUNDAR ADMIN 7000.00
000004 8647 BALAJI SUNDARAM IT 25000.00
000005 9213 MR X TRAVEL 20000.00
000006 5643 JAMES DAVID TRAVEL 5000.00
000007 2212 ROBERT STEVE HR 1000.00
000008 3241 JACKIE JOHN IT 7800.00
000009 4412 ARNOLD S ADMIN 12000.00
and I Need a beautiful report like this sorted on Employee id


Just think of writing a small Cobol program for the above requirement . I bet you would end up with at least 100 lines of code and up to 3 hours. You also need a sort step to sort the input on Employee ID
With Easytrieve all you need is a few lines of code and no extra sort step is required. The code given below is all it takes for the above requirement

FILE PERSNL
EMPNUM 1 4 A HEADING ('EMPLOYEE' 'NUMBER')
EMPNAME 5 20 A HEADING ('EMPLOYEE' 'NAME')
SALARY 33 4 P 2 MASK ('$$$$9.99') HEADING ('BASE SALARY')
FILE REPTOUT PRINTER
JOB INPUT PERSNL NAME MYFIRST
PRINT REPT
REPORT REPT LINESIZE 80 PRINTER REPTOUT
SEQUENCE EMPNUM
TITLE 01 'REPORT OF EMPLOYEES'
LINE 01 EMPNUM EMPNAME SALARY

The jcl to execute the above program is given below
//STEP030 EXEC PGM=EZTPA00,COND=(0,NE)
//*
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//PERSNL DD DSN=ADCF74C.SUN.SORTTEST,DISP=SHR
//REPTOUT DD DSN=ADCF74C.SUN.SORTTEST.OUT,DISP=(,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(1,1),RLSE),
// DCB=(RECFM=FB,LRECL=100,BLKSIZE=0)
//SYSIN DD DSN=ADCF74C.SUN.SOURCE(EZTR1),DISP=SHR <== Your program comes here
//*


Lets go over the above program in detail

The structure of Easytrieve program is simple .
First is the Library Section - where you define the Files and Variables
Second is where all the processing takes place. This section starts with Job statement

Library Section
FILE PERSNL
FILE REPTOUT PRINTER

Our program has two files. DDNAME PERSNL is our input file and REPTOUT is our Output file .

FILE PERSNL
EMPNUM 1 4 A HEADING ('EMPLOYEE' 'NUMBER')
EMPNAME 5 20 A HEADING ('EMPLOYEE' 'NAME')
SALARY 33 4 P 2 MASK ('$$$$9.99') HEADING ('BASE SALARY')


From the input file we need Employee number , Name and salary. The above lines contains the definition of the field. First column is the Field-name , Starting position, Length , type (Alphanumeric or Packed). For the packed field salary you can see additional parameters. "2" indicates decimal position, " MASK ('$$$$9.99')" indicates how the field should be formatted in the report.
You dont need to define all the fields in the file like you do for a Cobol program . For example we don't need department id from the input file and hence they can be ignored
The HEADING parameter indicates the heading name for the fields defined in the report

Processing section


JOB INPUT PERSNL NAME MYFIRST
Job statement marks the begging of the processing section . The above statement indicates use PERSNL as input and the name of this program is MYFIRST

PRINT REPT
The above statement says Print the report as defined by the "REPT"

REPORT REPT LINESIZE 80 PRINTER REPTOUT
SEQUENCE EMPNUM
TITLE 01 'REPORT OF EMPLOYEES'
LINE 01 EMPNUM EMPNAME SALARY

The above Report statement defines how the report "REPT" needs to be formatted

REPORT REPT LINESIZE 80 PRINTER REPTOUT
This line indicates Define report "REPT", and length of the report is 80 bytes . The file name where the report needs to be printed is the REPTOUT. The words "REPORT" "LINESIZE" "PRINTER" are all EasyTrieve words


SEQUENCE EMPNUM
The above line says the report should be printed in the order of EMPNUM

TITLE 01 'REPORT OF EMPLOYEES'
As you guess this defines the title of the report

LINE 01 EMPNUM EMPNAME SALARY
This actually tells the content of the report. Print the fields EMPNUM EMPNAME SALARY

Hope my explanation was clear. The above is a very simple example to explain EasyTrieve.
Lets discuss more about file handling (using multiple files), using IF THEN and some more report options in the next mail
Questions/ Suggestion/Comments are welcome


Comments:
Interesting to know.
 
Thank you for posting this page. It helped me prepare for a technical interview
 
Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]

Web Counters
HTML Counter