In Easytrieve, a variable is any named field your program can read or change: GROSS on the payroll file, WS-COUNT in working storage, NET-PAY derived in a PROC, or LEVEL during report formatting. Easytrieve does not use COBOL level numbers. You define each field with FILE or DEFINE, then reference it in IF, assignment, PRINT, REPORT LINE, and SQL. Variables fall into families—FILE record fields, W working storage, S static storage, overlays, system fields, and SQL nullable fields with indicators. Beginners who treat every name as interchangeable storage get burned when W fields spool at PRINT time, when FILE fields need qualifiers, or when NULL indicators differ from blank bytes. This overview builds the mental model before scope, lifetime, initialization, and memory detail pages.
Nothing is a variable until DEFINE or FILE gives it a name, location, length, and type. FILE PAY-GROSS 94 4 P 2 declares a packed variable on the input buffer. DEFINE WS-FLAG W 1 A declares a one-byte working storage variable. Assignment NET-PAY = GROSS - TAX requires NET-PAY defined first. Easytrieve enforces declare-before-use more strictly in activities than in library sections where DEFINE may be omitted after FILE.
12345678910111213FILE PERSNL FB(150 1800) NAME 17 20 A GROSS 94 4 P 2 DEFINE WS-COUNT W 5 N RESET VALUE 0 DEFINE NET-PAY W 7 P 2 JOB INPUT PERSNL WS-COUNT = WS-COUNT + 1 NET-PAY = GROSS - DEDUCT IF NET-PAY LT 0 NET-PAY = 0 END-IF
| Family | Defined by | Typical value source |
|---|---|---|
| FILE field | FILE name position type | Dataset bytes on READ |
| W working storage | DEFINE W | Assignment, VALUE, RESET |
| S static storage | DEFINE S | Assignment; live at report format |
| Overlay subfield | Parent field + offset | Same bytes as parent |
| System field | Product-provided LEVEL TALLY | Report writer or runtime |
| SQL nullable | SQL INCLUDE NULLABLE | SELECT plus null indicator |
FILE variables mirror record layouts on disk or tape. Each READ or automatic JOB INPUT loads the buffer. You may define only the columns you need—not every byte in the physical record. Misaligned lengths shift every following variable. OUTPUT FILE variables change only when your logic assigns them before PUT or WRITE. VALUE does not preload FILE variables from compile-time literals.
W and S variables live outside the file buffer. Use them for counters, scratch math, flags, derived amounts, and report annotations. Broadcom recommends S unless you understand W spooling. W variables referenced in REPORT copy to work files at PRINT. S variables remain in static storage until the formatter reads them during printing.
Overlays are variables that share storage with a parent. DEFINE HIRE-MM DATE-OF-HIRE 2 N creates a variable view into the parent bytes. Changing HIRE-MM changes DATE-OF-HIRE. Overlays are variables structurally but not separate allocations.
Field names must be unique within each FILE and within working storage. The same name on FILE and working storage requires qualification: PERSNL:STATUS versus WORK:STATUS. Library section searches current FILE and WORK when unqualified references fail or collide. Explicit qualifiers make audits easier for beginners.
123IF WORK:ECHO-SW EQ 'Y' DISPLAY PERSNL:NAME END-IF
Assignment and MOVE change variable contents. NET-PAY = GROSS - DEDUCT updates NET-PAY. MOVE SPACES TO OUT-NAME clears a character variable. Figurative constants follow MOVE rules for nullable fields. Arithmetic with NULL operands errors per nullable assignment tables—guard SQL variables before math.
VALUE on DEFINE sets initial content for working storage variables at allocation. RESET on W variables reloads initial value at JOB, SCREEN, or SORT start. Without VALUE, numeric W and S default to zero; alphabetic default to blanks. FILE variables have no VALUE default from dataset—they reflect whatever was read.
Easytrieve provides system-defined fields for reports and runtime: LEVEL and BREAK-LEVEL during control reports, TALLY for control break counts, LINE-COUNT and PAGE-NUMBER, FILE-STATUS per file, SYSDATE and SYSTIME, RETURN-CODE, and others in Symbols documentation. You do not DEFINE these—they exist by product rules when referenced in supported contexts.
Variables appear in arithmetic expressions, relational IF tests, field-class conditions, DUPLICATE and EOF tests, and REPORT LINE lists. Type matters: quantitative variables need decimal positions for signed math and SUM. Comparing alphabetic variables to numeric literals triggers conversion rules that beginners should avoid by matching types.
User variables can change during the run. VALUE-initialized fields are variables by definition but constant by team convention. System constants ZERO SPACE EOF are not variables—you do not DEFINE them. See constants chapter pages for figurative and reserved value behavior.
Variables are labeled boxes. FILE boxes get filled when a new card arrives from the file pile. WORK boxes sit on your desk for counting and scratch notes. Some labels need a file name or WORK written before them so you open the right box. Some boxes are windows into a bigger box—that is an overlay. You must make the box before you put anything inside.
1. In Easytrieve, a variable is:
2. FILE fields receive values primarily from:
3. W working storage differs from S because:
4. When the same name exists on FILE and in working storage, qualify with:
5. Numeric W fields without VALUE default to: