Easytrieve does not offer a COBOL-style 78 level or a CONST keyword on DEFINE. Instead, programmers create constant fields—named working storage locations preloaded with fixed values that the rest of the program references by name. A tax rate of 8.25 percent becomes DEFINE TAX-RATE W 3 P 4 VALUE 0.0825. A default echo switch becomes DEFINE ECHO-SW W 1 A VALUE Y. A maximum batch size becomes DEFINE MAX-RECS W 5 N VALUE 50000. These are not bytes on your input file. They are program-owned values established at allocation and treated as read-only by convention. This page teaches how to declare constant fields, when to choose W versus S storage, how VALUE and RESET interact, and how constant fields differ from inline literals and from system reserved words like ZERO and SPACE used in IF conditions.
Beginners sprinkle literals through IF and assignment: IF WS-COUNT GT 50000, NET = GROSS * 0.0825. That works until the business changes the limit to 75000 or the rate to 7.5 percent. You search every statement. A constant field centralizes the value: IF WS-COUNT GT MAX-RECS, TAX-AMT = GROSS * TAX-RATE. Auditors and maintainers see intent in the Library section. Compile-time VALUE catches type mismatches early. Report MASK and HEADING still apply when you PRINT constant fields for documentation runs.
Append VALUE initial-value after type and optional decimal positions on DEFINE. The literal must match field type—quoted string for A, numeric for N P B U I, hex X for byte patterns. Maximum initial-value length is 254 bytes per Broadcom DEFINE rules.
123456DEFINE TAX-RATE W 3 P 4 VALUE 0.0825 DEFINE MAX-RECS W 5 N VALUE 50000 DEFINE DFLT-STAT W 2 A VALUE 'OK' DEFINE COMPANY-CD W 4 A VALUE 'ACME' DEFINE FLAG-ON W 1 A VALUE 'Y' DEFINE FLAG-OFF W 1 A VALUE 'N'
Each name becomes a symbolic constant for the run. JOB logic references TAX-RATE instead of 0.0825. Online screens can DISPLAY DFLT-STAT when validation passes. Numeric constants without VALUE still default to zero—VALUE documents non-zero defaults explicitly.
| Situation | Literal approach | Constant field approach |
|---|---|---|
| Tax rate used in five calculations | Repeat 0.0825 in each expression | DEFINE TAX-RATE ... VALUE 0.0825 once |
| Status code compared in many IF branches | IF STAT EQ 'OK' scattered everywhere | IF STAT EQ DFLT-STAT |
| One-time message text in DISPLAY | Quote string inline—acceptable | Optional HEADING field for reuse |
| Loop bound known at coding time | DO WHILE IDX LE 12 for months | DEFINE MONTH-CNT W 2 N VALUE 12 |
Broadcom distinguishes non-static W fields from static S fields. W fields copy to report work files when referenced in REPORT processing at PRINT time. S fields remain in static working storage and are evaluated when the report formats—not when data is selected. Constant fields used only in JOB arithmetic and IF logic fit W. Constants that hold report-wide limits, company codes printed on every page header via S-field references, or grand-total divisors should use S so spooling does not snapshot stale per-record values.
12345678DEFINE CO-NAME S 20 A VALUE 'ACME CORPORATION' DEFINE RPT-LIMIT S 5 N VALUE 99999 DEFINE WS-SCRATCH W 7 P 2 JOB INPUT PERSNL IF WS-COUNT GT RPT-LIMIT DISPLAY 'LIMIT EXCEEDED' END-IF
Easytrieve reserves words ZERO, ZEROS, ZEROES, SPACE, SPACES, HIGH-VALUES, and LOW-VALUES for field class conditions and MOVE targets—not as DEFINE field names you create. IF GROSS ZERO tests whether GROSS contains a zero value in packed format. MOVE ZERO TO WS-COUNT clears a counter. These are system constants applied to existing fields. Constant fields are the opposite: you invent TAX-RATE and preload it with VALUE. Confusing the two leads beginners to code DEFINE ZERO—which is invalid as a user constant name because ZERO is reserved.
Choose type to match how the constant participates in arithmetic. Integer counts use N or I. Money rates and amounts use P with correct decimal positions. Bit masks use B with VALUE X hex. A rate stored as P 4 needs four decimal places in VALUE 0.0825 or the internal scaled value will be wrong.
| Business constant | Type | Example DEFINE |
|---|---|---|
| Record limit | N or I | DEFINE MAX-RECS W 5 N VALUE 50000 |
| Tax or percentage rate | P with decimals | DEFINE TAX-RATE W 3 P 4 VALUE 0.0825 |
| Status or code | A | DEFINE OK-CODE W 2 A VALUE 'OK' |
| Binary flag pattern | B | DEFINE MASK-INIT W 2 B VALUE X'0000' |
Non-numeric VALUE must be enclosed in single quotes. VALUE ABC without quotes is a syntax error. Hex constants use X prefix: VALUE X 123F for packed seed values in test harnesses. Length shorter than field pads; longer truncates per assignment rules—test DISPLAY when borderline.
RESET on W fields returns the field to its initial value—including VALUE—when JOB, SCREEN, or SORT activity starts. Constant fields that must reload each job iteration should code RESET with VALUE. Constants that should persist across multiple JOB activities in one run omit RESET. S fields do not use RESET the same way—consult your release notes for S initialization semantics.
12345678DEFINE RUN-LIMIT W 5 N VALUE 1000 RESET DEFINE WS-COUNT W 5 N VALUE 0 RESET JOB INPUT FILE1 WS-COUNT = WS-COUNT + 1 IF WS-COUNT GT RUN-LIMIT STOP END-IF
FILE record fields read bytes from the dataset on each READ. VALUE does not turn a FILE column into a compile-time constant. If you need a constant on output, define a W field and MOVE it to the FILE field before PUT or WRITE. Initialization jobs that seed master files assign CUST-ID = 0 in JOB logic rather than VALUE on the FILE definition.
Shops often prefix constant fields with CO-, DFLT-, MAX-, MIN-, or LIT- to signal immutability. Document in comments when a VALUE field is intentionally overridden in rare PROC paths. Group constants at the top of the Library section after FILE definitions for quick audits. Avoid reusing a constant field name as a loop counter.
A constant field is a labeled jar of marbles you fill once before the game starts. The jar says TAX-RATE and always starts with the same number of marbles you chose at home. During the game you look at the jar instead of counting marbles from scratch each time. ZERO and SPACE are special words the game already knows—they describe empty jars or blank jars, not jars you name yourself.
1. The primary way to define a named constant field in Easytrieve is:
2. Constant fields are usually defined as:
3. VALUE 0.0825 on TAX-RATE P 4 means:
4. System constant ZERO in IF GROSS ZERO tests:
5. For report grand totals that must not spool per record, constant accumulators should use: