Easytrieve Derived Fields

A derived field is any field whose meaning comes from other data rather than a fixed byte position you read blindly from tape. NET-PAY derived from GROSS minus DEDUCTIONS is the classic payroll example. HIRE-MM derived as the first two bytes of DATE-OF-HIRE is a structural overlay. FULL-NAME derived by concatenating FIRST-NAME and LAST-NAME in a PROC is a string derivation. Easytrieve does not let you embed a formula inside DEFINE the way WebFOCUS virtual fields do. You declare the target field, then assign an expression in JOB logic, SORT, or a PROC. That two-step pattern—define storage, compute value—is the heart of derived field processing. This page walks beginners through arithmetic derivations, overlay derivations, date and string derivations, report implications with W versus S fields, and debugging when derived values look almost right.

Progress0 of 0 lessons

Define First, Derive Second

Broadcom requires the target field to exist before assignment. Define NET-PAY in working storage with length and type that can hold the result. Then in JOB INPUT compute it each record. Skipping DEFINE produces undeclared field errors at compile. Defining NET-PAY as type A when GROSS is packed produces conversion surprises—match quantitative types and decimal positions.

text
1
2
3
4
5
6
7
8
9
10
11
12
13
FILE PERSNL FB(150 1800) NAME 17 20 A GROSS 94 4 P 2 DEDUCT 98 4 P 2 DEFINE NET-PAY W 7 P 2 JOB INPUT PERSNL NET-PAY = GROSS - DEDUCT IF NET-PAY LT 0 NET-PAY = 0 END-IF PRINT NET-PAY

Arithmetic Derived Fields

Addition, subtraction, multiplication, division, and exponentiation in assignment statements produce derived numeric fields. Operands must be quantitative when signed math is required—decimal positions on DEFINE. Mixed types convert per product rules; beginners should keep operands same type and scale.

Arithmetic derivation patterns
Derived fieldTypical expressionNotes
NET-PAYGROSS - DEDUCTSubtraction; watch packed scale
TAX-AMTGROSS * TAX-RATERate constant field times amount
PCT-OF-TOTALLINE-AMT / GRAND-TOT * 100Division—define enough decimals
BONUSBASE * 1.05Literal factor in expression

Structural Derived Fields (Overlays)

Overlay syntax derives a subfield from a parent without a new absolute file position. DEFINE HIRE-MM DATE-OF-HIRE 2 N takes the first two bytes of parent DATE-OF-HIRE as month number. The derivation is structural—the bytes are the same memory as the parent. Changing HIRE-MM changes parent bytes and vice versa. Use overlays for year, month, day components, sign nybbles, or status codes embedded in a larger code field.

text
1
2
3
4
5
FILE PERSNL FB(150 1800) DATE-OF-HIRE 45 6 N HIRE-CC DATE-OF-HIRE 2 N HIRE-YY DATE-OF-HIRE +2 2 N HIRE-MM DATE-OF-HIRE +4 2 N

HIRE-CC, HIRE-YY, and HIRE-MM are derived views. IF HIRE-MM EQ 06 filters June hires without reading a separate column from the dataset layout document.

String and Character Derived Fields

Concatenation and substring operations derive alphabetic results. MOVE and assignment with quoted literals build display names. MASK on derived W fields controls report editing. VARYING fields support length-changing derivations for SQL VARCHAR targets. Padding and trimming rules apply—see string handling data type pages.

text
1
2
3
4
5
6
7
8
9
10
11
DEFINE FULL-NAME W 40 A PROC BUILD-NAME. FULL-NAME = FIRST-NAME FULL-NAME = FULL-NAME + ' ' FULL-NAME = FULL-NAME + LAST-NAME END-PROC JOB INPUT PERSNL PERFORM BUILD-NAME PRINT FULL-NAME

Date Derived Fields

Date fields stored as N or P can yield derived century, year, month, and day overlays or working storage fields computed with date routines where your shop macros provide them. Internal date representation matters—six-digit YYMMDD overlays differ from eight-digit CCYYMMDD. Misaligned overlay length produces wrong month digits and silent bad reports.

Derived Fields in PROCs

Centralize repeated derivations in PROCs. CALC-NET in one PROC avoids duplicating NET-PAY = GROSS - DEDUCT - TAX in three JOB activities. PROCs accept no parameters in classic Easytrieve—use working storage for inputs and outputs. Call PERFORM CALC-NET before PRINT so derived W fields hold final values.

Derived Fields and Reporting

When PRINT selects a record for a REPORT, W derived fields copy to the report work file at that moment. If you derive NET-PAY after PRINT, the report shows stale or zero values. Order matters: compute, then PRINT. S derived fields used in control breaks evaluate at format time—see working storage page for W versus S spooling rules.

  1. READ or automatic JOB INPUT brings file fields.
  2. Assignment derives W or S target fields.
  3. IF filters on derived values.
  4. PRINT passes derived fields to REPORT layout.

Derived Fields vs FILE Columns

FILE columns exist on the physical record. Derived W fields exist only in memory for the run. Output files receive derived values only when you MOVE or assign into FILE output fields before PUT. Do not add NET-PAY to input FILE unless the source dataset actually contains those bytes.

Type and Decimal Rules

  • Match decimal positions on monetary derivations—P 2 plus P 2 yields P 2 target.
  • Unsigned fields cannot hold negative NET-PAY—define signed quantitative fields.
  • Binary derived fields need aligned lengths—4-byte fullword for some counters.
  • Alphabetic derivation truncates silently when target too short—size FULL-NAME generously.

Debugging Derived Values

When derived numbers look wrong, verify operand field positions first—wrong GROSS length shifts every following derivation. DISPLAY operands and result before PRINT in test runs. Compare packed hex in SYSPRINT debug if S0C7 abends appear. Check whether W field was reset by RESET option between JOB activities.

Common Mistakes

  1. Assignment before DEFINE of target field.
  2. PRINT before computing derived W field.
  3. Overlay offset wrong—month reads year digits.
  4. Mixing unsigned types for values that go negative.
  5. Defining derived FILE column not on input tape.
  6. Expecting DEFINE to include formula like DEFINE NET = GROSS - DEDUCT.

Explain It Like I'm Five

A derived field is the answer you write after doing math with numbers from two other papers. You need an empty line labeled NET-PAY first—that is DEFINE. Then you subtract on that line—that is assignment. An overlay is looking at just the month part of a birthday written as one long number—you did not get a new birthday, you are just looking at piece of the same number.

Exercises

  1. Define NET-PAY and derive from GROSS and two deduction fields.
  2. Create HIRE-MM overlay on a six-digit date field; filter June records.
  3. Write PROC that derives TAX-AMT from GROSS and TAX-RATE constant field.
  4. Explain why PRINT must follow derivation for W fields.
  5. DISPLAY derived field and operands when result is off by factor of 100.

Quiz

Test Your Knowledge

1. Easytrieve derives field values primarily through:

  • Assignment and expressions in JOB logic or PROCs
  • DEFINE expression= on the same line as field name
  • JCL DD DCB
  • REPORT TITLE only

2. NET-PAY = GROSS - DEDUCTIONS requires:

  • NET-PAY defined in working storage with matching numeric type
  • NET-PAY on FILE only
  • No DEFINE if GROSS exists
  • MACRO expansion

3. Overlay field HIRE-MM on DATE-OF-HIRE derives:

  • Subfield view of parent bytes without separate file position
  • New file column on disk
  • JCL sort key
  • Screen map row

4. Derived packed field arithmetic needs:

  • Quantitative types with correct decimal positions
  • Type A only
  • No decimal specification
  • VIRTUAL file

5. A derived field on a report LINE:

  • Must be calculated before PRINT if it uses W fields in spooled reports
  • Calculates automatically at print without JOB logic
  • Requires SQL
  • Cannot use MASK
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 assignment overlay derived field patternsSources: Broadcom Easytrieve 11.6 Define Files and Fields, DEFINE Statement, Getting StartedApplies to: Easytrieve derived and calculated fields