Easytrieve Constants (Field)

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.

Progress0 of 0 lessons

Why Named Constant Fields Matter

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.

Declaring Constant Fields with VALUE

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.

text
1
2
3
4
5
6
DEFINE 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.

Constant Fields vs Inline Literals

When to use a constant field instead of a literal
SituationLiteral approachConstant field approach
Tax rate used in five calculationsRepeat 0.0825 in each expressionDEFINE TAX-RATE ... VALUE 0.0825 once
Status code compared in many IF branchesIF STAT EQ 'OK' scattered everywhereIF STAT EQ DFLT-STAT
One-time message text in DISPLAYQuote string inline—acceptableOptional HEADING field for reuse
Loop bound known at coding timeDO WHILE IDX LE 12 for monthsDEFINE MONTH-CNT W 2 N VALUE 12

W vs S for Constant Fields

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.

text
1
2
3
4
5
6
7
8
DEFINE 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

Constant Fields vs System Constants

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.

  • Constant field: DEFINE MAX-RECS W 5 N VALUE 50000 — your named value.
  • System constant: IF MAX-RECS ZERO — tests whether MAX-RECS currently holds zero.
  • System constant: MOVE SPACES TO NAME — fills NAME with blank characters.

Numeric Constant Field Types

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.

Common constant field type choices
Business constantTypeExample DEFINE
Record limitN or IDEFINE MAX-RECS W 5 N VALUE 50000
Tax or percentage rateP with decimalsDEFINE TAX-RATE W 3 P 4 VALUE 0.0825
Status or codeADEFINE OK-CODE W 2 A VALUE 'OK'
Binary flag patternBDEFINE MASK-INIT W 2 B VALUE X'0000'

Alphabetic and Hex Constant Fields

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 and Constant Fields

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.

text
1
2
3
4
5
6
7
8
DEFINE 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

Constants on FILE Fields

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.

Maintenance and Naming Conventions

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.

Common Mistakes

  1. Using reserved words ZERO or SPACE as constant field names.
  2. VALUE on FILE field expecting preload before READ.
  3. Wrong decimal count on P constant—rate scales incorrectly.
  4. W constant referenced in REPORT totals that should be S.
  5. Changing constant fields in PROC without team agreement.
  6. Duplicating the same literal instead of one VALUE field.

Explain It Like I'm Five

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.

Exercises

  1. Define TAX-RATE P 4 with VALUE 0.075 and use it in a NET calculation.
  2. Define OK-CODE and ERROR-CODE alphabetic constants; use in IF STATUS EQ OK-CODE.
  3. Explain why MAX-RECS should not be a FILE field with VALUE.
  4. Convert three inline literals in sample JOB to named constant fields.
  5. Choose W or S for a company name printed on every report page header.

Quiz

Test Your Knowledge

1. The primary way to define a named constant field in Easytrieve is:

  • DEFINE with VALUE on working storage
  • CONST keyword on FILE
  • HIGH-VALUES on DEFINE
  • JCL PARM only

2. Constant fields are usually defined as:

  • W or S working storage
  • FILE record positions only
  • REPORT TITLE lines
  • MACRO parameters

3. VALUE 0.0825 on TAX-RATE P 4 means:

  • Packed field starts with rate 0.0825 at allocation
  • File field reads 0.0825 from disk
  • JCL sets tax rate
  • MASK prints 0.0825 always

4. System constant ZERO in IF GROSS ZERO tests:

  • Whether field contains zero in its defined format
  • Whether field name is ZERO
  • JCL return code
  • Compile option

5. For report grand totals that must not spool per record, constant accumulators should use:

  • S static working storage
  • FILE overlay
  • TITLE statement
  • VIRTUAL file
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 DEFINE VALUE working storage constant patternsSources: Broadcom Easytrieve 11.6 DEFINE Statement, Define Files and Fields, Getting StartedApplies to: Easytrieve named constant fields with VALUE