Nearly every production Easytrieve program reads files, writes files, or both. Payroll extracts arrive as sequential QSAM datasets; employee masters live in VSAM KSDS; audit trails append to GDG bases; printers receive formatted report lines. File processing in Easytrieve is the bridge between JCL DD allocation on the mainframe and the FIELD definitions your JOB logic uses. You declare files once in the Library with FILE, map record layouts with DEFINE, then drive I/O in JOB, PROGRAM, SORT, or SCREEN activities. Beginners who learned COBOL first often hunt for OPEN before every READ; Easytrieve opens files implicitly when automatic input starts or when the first GET, READ, PUT, or WRITE runs. This overview teaches the file lifecycle from declaration through read and write patterns, compares sequential versus keyed access, explains UPDATE and CREATE authority, and points you to focused pages on sequential files, VSAM, indexed KSDS, relative RRDS, and record maintenance. Master this chapter before writing complex multi-file jobs or keyed lookups.
Broadcom divides Easytrieve source into Environment, Library, and Activity sections. File processing starts in the Library immediately after optional PARM. Each FILE statement gives a unique file-name your program uses in I/O verbs. That name is not necessarily the DD name in JCL—SYSNAME and site conventions map logical names to operating-system identifiers. DEFINE statements under each FILE describe bytes inside the record: employee number, name, salary, dates. Activity sections consume those fields. A typical batch report declares FILE INPUT sequential, FILE OUTPUT sequential or printer, JOB INPUT INPUT to auto-read, and PRINT or PUT to emit results. Misplacing FILE in a REPORT block or Activity before Library causes compile errors that disappear once you respect section order from the program structure chapter.
12345678910111213* Library — declare files and fields FILE PAYROLL FB(200 2000) FILE REPORT PRINTER DEFINE PAYROLL EMP-NO 9 1 EMP-NAME A 20 GROSS P 9.2 JOB INPUT PAYROLL IF GROSS GT 50000 PRINT 'HIGH EARNER' EMP-NO EMP-NAME GROSS END-IF
| FILE type | Access style | Typical dataset |
|---|---|---|
| SEQUENTIAL (default) | Forward sequential read; append on output | QSAM disk/tape, VSAM ESDS browse |
| INDEXED | Key-based READ, random and sequential by key | VSAM KSDS employee master |
| RELATIVE | Record number (RRN) addressing | VSAM RRDS slot table |
| SQL | Cursor-managed table rows | DB2 payroll table |
| PRINTER device | Formatted report lines to SYSOUT | Detail and summary listings |
Omitting type defaults to sequential. Explicit SEQUENTIAL also enables FILE-STATUS for that file. INDEXED maps to VSAM KSDS on z/OS; RELATIVE maps to RRDS. Choosing the wrong type produces runtime ABENDs or silent wrong-record reads when JCL allocates a different organization than FILE declares. Match FILE type to DD DISP and AMP parameters your operations team documents.
JOB INPUT file-name is the workhorse of batch Easytrieve. It tells the runtime to read the next record automatically at the start of each JOB iteration—equivalent to a hidden GET. Your IF, MOVE, PRINT, and PERFORM logic runs with a fresh input buffer each time. You cannot also GET the same file while it is automatic input; use JOB INPUT NULL on that file and explicit GET in a loop when you need custom control, or GET a secondary lookup file while the primary remains automatic. PROGRAM activities without JOB INPUT use GET or READ explicitly. SORT activities read and write work files the product manages. Understanding which pattern you use prevents the common error of testing EOF on a file that never received a manual GET.
| Pattern | How records arrive | EOF handling |
|---|---|---|
| JOB INPUT MASTER | Auto-read each iteration | Activity ends when input exhausted |
| JOB INPUT NULL + GET MASTER | You issue GET inside logic | You test IF EOF MASTER |
| READ key on INDEXED | Keyed retrieval into buffer | Test file presence / status |
Sequential QSAM files usually specify FB (fixed blocked), F (fixed unblocked), VB (variable blocked), or V (variable). FB(150 1800) means record length 150 and block size 1800—or FULLTRK on some releases for track-sized blocks. Variable formats need correct RDW handling; Easytrieve abstracts much of this when DEFINE lengths match the dataset. Wrong LRECL in FILE causes field misalignment: salary digits appear in name columns, totals go negative, and debugging takes hours. Always confirm BLKSIZE and LRECL with IDCAMS LISTCAT or IEBCOPY on the real dataset before coding DEFINE positions.
CREATE on FILE allows building a new dataset when the JCL disposition permits. UPDATE authorizes changing existing records—mandatory for VSAM in-place maintenance and for SQL DELETE/INSERT paths. Output sequential files often use FILE OUTFILE FB(...) without UPDATE; the program PUT or WRITE appends new records. Printer files use the PRINTER device type so REPORT activities format headings and lines. VIRTUAL files hold intermediate data in memory or temp storage for multi-step jobs without permanent catalog entries. TABLE marks files used with SEARCH/LOOKUP for in-memory or external reference tables.
Automatic JOB INPUT ends the activity when the input file exhausts—your FINISH procedure runs on normal termination. Manual GET loops must test IF EOF file-name or IF NOT file-name before processing buffer fields. STATUS on GET or READ sets FILE-STATUS with the operating-system return code so you can branch on error without aborting the step. Constants like EOF in condition expressions are file-specific. Never assume the buffer is valid after a failed read; Broadcom documents that using fields after EOF without a guard produces unpredictable results.
Easytrieve file-name is logical; JCL //DDNAME DD DSN=... allocates physical storage. Site standards often require file-name to match DD name for clarity, but SYSNAME can diverge when one program template serves multiple datasets. STEPLIB and SYSPRINT are product datasets, not business files. Confirm DISP=SHR for shared reads, DISP=OLD or NEW for updates, and AMP parameters for VSAM (AMP='AMORG=VSAM'). A mismatch between FILE INDEXED and a QSAM DD is a frequent beginner mistake caught only at execution.
Production jobs combine input extract, master lookup, and error output. Pattern: JOB INPUT TRANSACTION as automatic input; FILE MASTER INDEXED for keyed READ inside BEFORE-LINE or job PROC; FILE ERRFILE SEQUENTIAL for rejected records via PUT. Secondary GET files must not be the automatic input file. Release documentation limits how many files stay open simultaneously; CLOSE files you finish early in long PROGRAM paths to free VSAM share locks. The multiple-files page in this chapter expands fan-in and fan-out designs.
File processing is like labeled boxes of cards your program can read and write. First you put stickers on each box saying what is inside—that is FILE and DEFINE. Then you decide whether the computer hands you one card automatically each turn (JOB INPUT) or you ask for a card when you are ready (GET). Some boxes are numbered in order; some have names on tabs to find one card fast; some use slot numbers. You must say please stop when the box is empty (EOF), and you need permission to change cards already in the box (UPDATE). JCL is the warehouse map telling the computer which real box each sticker points to.
1. Where do you declare files in Easytrieve?
2. Default FILE type when you omit the type keyword is:
3. Automatic JOB INPUT means:
4. UPDATE on FILE is required when you want to:
5. After manual GET you should test: