Easytrieve Addition Operator (+)

The plus sign is the addition operator in Easytrieve arithmetic. It sums two numeric values—gross pay plus bonus, year-to-date plus current amount, hours plus overtime hours— and produces a result you store in a working storage field, FILE output buffer, or nested inside a larger expression before multiply or compare. Addition looks simple but mainframe payroll depends on implied decimal alignment: adding two packed P 2 amounts keeps hundredths aligned internally; adding into a field too short overflows; adding FILE fields with corrupt packed signs abends the step. Beginners confuse + with string concatenation from other languages—Easytrieve uses + only for numeric sum in assignment expressions. This page teaches operand rules, packed and zoned behavior, accumulator patterns, chaining multiple adds, interaction with precedence, SUM report contrast, and defensive validation before adding untrusted extract amounts.

Progress0 of 0 lessons

Basic Syntax

Addition appears in assignment: TARGET = operand1 + operand2. Operands may be field names, numeric literals up to 18 digits, or parenthesized subexpressions. TOTAL = GROSS + BONUS adds two fields. WS-HOLD = GROSS + 100 adds literal hundred to gross—literal scale must match business intent for implied decimals. CHAIN = A + B + C adds left to right after any tighter operators inside operands: RESULT = A + B * C multiplies B * C first, then adds A.

text
1
2
3
TOTAL-PAY = GROSS + BONUS YTD-TAX = YTD-TAX + FED-TAX HOURS = REG-HRS + OT-HRS

Operands and Types

Addition operand types
Operand typeRole in additionBeginner notes
P packed decimalPrimary payroll currencyImplied decimals must align across operands and target
N zoned numericDisplay numeric sumsConverts with P per product rules
B binaryInteger-style sumsCounters and bit-related totals
Numeric literalFixed addend0.05 literal differs from 5—mind decimal intent
W or S fieldAccumulator targetSize target for maximum expected sum

Implied Decimal Alignment

DEFINE GROSS W 7 P 2 and BONUS W 7 P 2 both carry two decimal places. GROSS + BONUS computes sum at two implied decimals—1234.56 plus 10.00 yields 1244.56 when stored in W 7 P 2. Mixing P 2 with N 5 without decimals promotes per conversion rules—test with DISPLAY during development. Adding P 2 result into P 0 field truncates or rounds per assignment keywords—auditors notice penny drift. Standardize decimal positions across pay components before adding in production decks.

Accumulator Pattern

GRAND-TOT = GRAND-TOT + GROSS inside JOB INPUT loop accumulates program total. Library S field GRAND-TOT S 11 P 2 persists across records; W field without careful design may participate in report work file copy at PRINT—choose S for cross-record program totals referenced in reports. RESET on W accumulator restarts each JOB when coded. Addition assignment is O(1) per record—millions of adds run nightly in batch windows.

text
1
2
3
4
5
6
DEFINE GRAND-GROSS S 11 P 2 JOB INPUT PAYROLL GRAND-GROSS = GRAND-GROSS + GROSS PRINT PAY-RPT END-JOB

Addition vs SUM Statement

Plus in assignment executes during JOB procedural logic—you control when add happens. SUM on REPORT line accumulates field values during report formatting with control breaks— declarative totaling tied to PRINT. Use + for intermediate business calculations feeding PUT records. Use SUM when report writer should total GROSS by department on printed output. Both may appear in one program: NET = GROSS + BONUS in JOB; SUM GROSS on REPORT for department subtotals.

Chaining and Parentheses

NET = GROSS - FED - STATE - FICA chains subtraction which is addition of negated values internally in some implementations—subtraction page covers sign. Explicit add chain: TOTAL = A + B + C + D evaluates left to right: ((A + B) + C) + D. GROUP = (REG + OT) + (BONUS + ADJ) uses parentheses to document pay components. See order of evaluation when mixing + with * or / in same expression.

Addition Inside IF Conditions

IF REG-HRS + OT-HRS GT STD-HRS compares sum before relational test—addition binds before GT. IF A + B GT LIMIT + BUFFER mixes adds on both sides—each side evaluates before compare. Parentheses clarify: IF (A + B) GT (C + D). Numeric validation before add on FILE fields prevents abend: IF GROSS NUMERIC AND BONUS NUMERIC before TOTAL = GROSS + BONUS.

Overflow and Field Sizing

Target field must accommodate maximum sum range. Adding two W 7 P 2 fields may need W 8 P 2 target when carry exceeds seven digits. Cumulative GRAND-TOT S 11 P 2 sized for fiscal year program total. Overflow corrupts packed sign or truncates high digits—test with extreme production-like values. Intermediate WS-HOLD wider than final target captures sum before ROUNDED into display field.

ROUNDED and Addition

Pure addition of same-scale currency often needs no ROUNDED on assignment. When add follows multiply in same expression RESULT = GROSS + BONUS * PCT, product may need rounding before add—split: HOLD = BONUS * PCT ROUNDED; TOTAL = GROSS + HOLD. ROUNDED on final TOTAL = A + B ROUNDED applies rounding to stored sum when target has fewer decimals than intermediate computation.

Validation Before Adding FILE Fields

FILE GROSS from upstream extract may contain invalid packed data. IF GROSS NUMERIC before add to accumulator. FLDCHK in PARM DEBUG surfaces bad bytes during test. LOW-VALUES in numeric FILE field may pass some tests but fail addition—combine NUMERIC with reasonable range check IF GROSS GE 0 AND GROSS LT 9999999.99 when business rules allow.

Addition vs Concatenation Misconception

COBOL and Easytrieve beginners from JavaScript sometimes try NAME = FIRST + LAST for names—invalid for alphabetic join with +. Use MOVE, overlay, or documented string operations for text. Plus is numeric only in arithmetic expression grammar.

Common Addition Mistakes

  • Target field too narrow for running total.
  • Mixing decimal scales without conversion test.
  • Adding FILE fields before NUMERIC validation.
  • Assuming + concatenates text fields.
  • Forgetting multiply binds before add without parens.
  • Using W accumulator in report without understanding PRINT copy timing.

Explain It Like I'm Five

The plus sign puts numbers together. Three marbles plus two marbles makes five marbles. Pennies matter when the piggy bank counts dollars and cents—both piles must count the same way. The plus sign does not glue words together; it only adds numbers. When many numbers join in one line, times and divide may go first unless parentheses say add this group first.

Exercises

  1. Write accumulator GRAND = GRAND + AMOUNT in JOB loop.
  2. Compute total hours REG + OT into W field.
  3. Explain evaluation of A + B * C without parentheses.
  4. Add IF NUMERIC guards before adding two FILE amounts.
  5. Contrast + accumulator with REPORT SUM statement purpose.

Quiz

Test Your Knowledge

1. TOTAL = GROSS + BONUS uses + to:

  • Sum two numeric operands
  • Concatenate strings
  • Compare equality
  • Open a file

2. Adding two P 2 packed fields aligns:

  • Implied decimal positions in the sum
  • Only whole integers
  • Alphabetic bytes
  • JCL symbols

3. GRAND-TOT = GRAND-TOT + GROSS in a loop:

  • Accumulates running total
  • Resets GRAND-TOT each time
  • Compiles only
  • Concatenates names

4. Plus binds compared to multiply in A + B * C:

  • Looser—multiply runs first
  • Tighter—add first
  • Same level left only
  • Compile error

5. Adding invalid packed FILE data may:

  • Cause data exception at runtime
  • Always yield zero
  • Convert to alphabetic
  • Skip record
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 addition operator in assignment expressionsSources: Broadcom Easytrieve 11.6 Language Reference arithmetic operatorsApplies to: Easytrieve addition operator