Easytrieve Subtraction Operator (-)

The minus sign subtracts one numeric value from another—gross minus tax, balance minus payment, count minus one—or negates a single value when used as unary minus. Net pay is the archetypal subtraction chain: start with gross, subtract federal tax, state tax, FICA, other deductions until net remains. Easytrieve evaluates chained subtraction left to right at the same precedence level as addition unless parentheses group terms. Negative results require field definitions that support signed packed or zoned storage; unsigned fields may produce invalid sign nibbles when subtraction would go below zero. Beginners use subtraction inside IF to detect negative net before PUT—IF (GROSS - DEDUCT) LT 0— without assigning NET first. This page covers binary minus syntax, chained deductions, unary negation, signed versus unsigned targets, interaction with multiply precedence, and validation patterns for payroll exception reporting.

Progress0 of 0 lessons

Binary Subtraction Syntax

TARGET = left - right subtracts right from left. NET = GROSS - DEDUCT stores difference. Operands follow same numeric type rules as addition—packed P, zoned N, binary B, literals. Implied decimals align on P fields—subtracting P 2 from P 2 preserves scale in result when target sized correctly.

text
1
2
3
NET-PAY = GROSS - FED-TAX - STATE-TAX - FICA VARIANCE = BUDGET - ACTUAL REMAIN = LIMIT - COUNT

Chained Subtraction

NET = GROSS - A - B - C parses as ((GROSS - A) - B) - C with left-to-right associativity at same precedence as addition. Equivalent to subtracting sum when deductions grouped: TOTAL-DED = A + B + C; NET = GROSS - TOTAL-DED. Grouping deductions into TOTAL-DED clarifies audit trail and allows DISPLAY of total deductions before net. Parentheses override: NET = GROSS - (A + B + C) subtracts combined deductions in one step after add inside parens.

Chained vs grouped deductions
FormEvaluationWhen to use
GROSS - A - B - CLeft-to-right subtractSimple legacy style
GROSS - (A + B + C)Sum deductions then subtractClear single deduction total
TOTAL-DED = A+B+C; NET = GROSS - TOTAL-DEDTwo statementsAudit DISPLAY of TOTAL-DED

Unary Minus (Negation)

Unary minus negates one operand: ADJ = -CORRECTION stores negative correction amount. BALANCE = -OLD-BAL when reversing entry sign. Unary minus binds tightly—evaluate before add subtract at same expression level per precedence rules. Invalid packed on negated field still abends—validate source.

text
1
2
ADJ-AMT = -CORRECTION NET = GROSS + ADJ-AMT

Signed Results and Field Definitions

Quantitative packed fields with decimal positions support signed arithmetic in standard payroll definitions. Subtracting deductions from gross into NET P 2 allows negative net if deductions exceed gross—business may flag as error. Unsigned N fields without sign representation may corrupt on negative mathematical result. Define NET with sign capacity when over-deduction is possible during test. IF (GROSS - DEDUCT) LT 0 branches to exception without storing invalid NET.

Subtraction vs Addition Precedence

Plus and minus share precedence level—evaluate left to right among them. RESULT = 100 - 50 + 25 yields 75: subtract 50 from 100, add 25. RESULT = 100 - (50 + 25) yields 25 when parens group add first. Multiply and divide bind tighter: NET = GROSS - DEDUCT * RATE may multiply DEDUCT * RATE before subtract from GROSS—likely wrong for tax; use NET = GROSS - (DEDUCT * RATE) or separate assignments.

Subtraction in IF Conditions

IF GROSS - TOTAL-DEDUCT LT 0 detects negative net in one condition—subtraction before relational LT. IF (BUDGET - ACTUAL) GT TOLERANCE finds variance over threshold. Parentheses recommended for readability even when precedence suffices. Combine with NUMERIC guards on FILE operands before subtraction in condition.

text
1
2
3
IF (GROSS - TOTAL-DEDUCT) LT 0 DISPLAY 'NEGATIVE NET' EMPL-NUM GROSS TOTAL-DEDUCT END-IF

Variance and Comparison Use Cases

Budget minus actual yields variance for management reports. Limit minus count shows remaining capacity. Date arithmetic may use specialized routines—display date subtraction as raw minus on alphabetic date fields is unreliable; use DATECALC or internal date representation pages for calendar math. Subtraction on day-offset internal dates is numeric subtract on P fields after conversion.

ROUNDED and TRUNCATED with Subtraction

When subtracting rounded product from gross, round product first: TAX = GROSS * RATE ROUNDED; NET = GROSS - TAX. TRUNCATED on final NET assignment drops excess precision when regulations require truncation not round on net pay line.

Common Subtraction Mistakes

  • GROSS - DEDUCT * RATE without parens—multiply steals precedence.
  • Unsigned target for net that can go negative.
  • Subtracting unvalidated FILE packed fields.
  • Assuming right-to-left chain for A - B - C.
  • Confusing unary minus with binary minus syntax error.
  • Date overlay subtract without internal date conversion.

Explain It Like I'm Five

Minus takes marbles away. Ten marbles minus three leaves seven. Chained minus goes left to right: ten minus three minus two means seven then five. Parentheses say add what you subtract first—ten minus (three plus two) leaves five. A minus sign in front of one number flips it to opposite direction—like owing marbles instead of having them.

Exercises

  1. Write NET = GROSS - three deduction fields chained.
  2. Rewrite as GROSS - (sum of deductions) with parens.
  3. IF negative net detection without assigning NET.
  4. Explain 100 - 50 + 25 left-to-right result.
  5. Size signed NET field for over-deduction test case.

Quiz

Test Your Knowledge

1. NET = GROSS - DEDUCT uses - to:

  • Subtract right operand from left
  • Multiply operands
  • Compare fields
  • Negate JCL

2. NET = GROSS - TAX - FICA evaluates:

  • Left to right after any tighter operators
  • Right to left only
  • Compile error
  • JCL order

3. IF (GROSS - DEDUCT) LT 0 detects:

  • Negative net before assignment
  • EOF
  • Compile warning
  • Alphabetic field

4. Unary minus on numeric field:

  • Negates value
  • Subtracts from JCL
  • Deletes field
  • Opens file

5. Subtracting larger from smaller on unsigned field may:

  • Produce unexpected sign or invalid packed
  • Always yield zero
  • Concatenate
  • Skip JOB
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 subtraction operator in assignment and conditionsSources: Broadcom Easytrieve 11.6 Language Reference arithmetic operatorsApplies to: Easytrieve subtraction operator