Easytrieve Division Operator (/)

The slash divides one numeric value by another, producing a quotient. Average pay is TOTAL divided by COUNT. Unit price is extended amount divided by quantity. Rate recovery divides tax by gross when rate field missing—guard divisor non-zero. Division shares precedence with multiplication and binds tighter than addition. Chained division evaluates left to right: 100 / 10 / 2 yields 5 then 2.5 depending on associativity—parenthesize when business formula demands explicit grouping. Division by zero is the primary runtime hazard—IF divisor GT 0 before every divide on variable count fields. Packed decimal quotients need target width and implied decimals for fractional averages—ROUNDED on assignment matches currency policy. This page teaches quotient patterns, zero guards, precision loss, divide in IF conditions, relation to MOD remainder, and contrast with multiply for inverse operations.

Progress0 of 0 lessons

Basic Syntax

TARGET = dividend / divisor. AVG-GROSS = GRAND-TOTAL / REC-COUNT. UNIT-PRICE = EXT-AMT / QTY. Divisor must be non-zero at runtime. Literal divisor 100 converts percent display in some utility patterns—AMT / 100 when input stored as basis points—document convention.

text
1
2
3
4
5
IF REC-COUNT GT 0 AVG-GROSS = GRAND-TOTAL / REC-COUNT ROUNDED ELSE AVG-GROSS = 0 END-IF

Zero Divisor Guards

Mandatory pattern for variable divisors: test before divide. COUNT from accumulation may be zero on empty file. QTY on order line may be zero on bad extract. IF COUNT GT 0 protects AVG assignment. ELSE branch sets default zero, skips record, or DISPLAY exception. Never divide by COUNT without guard in production—nightly empty file should not abend entire payroll step.

Zero guard strategies
StrategyPatternWhen
IF GT 0IF COUNT GT 0 AVG = TOT / COUNTStandard average
ELSE defaultELSE AVG = 0Empty set acceptable
Skip recordELSE DISPLAY skipBad input row

Average and Mean Calculations

Financial average: sum divided by count with ROUNDED into P 2. GRAND-TOTAL accumulated in S field across records; REC-COUNT incremented each iteration; after loop or in trailer logic AVG = GRAND-TOTAL / REC-COUNT ROUNDED. Weighted average needs sum of products divided by sum of weights—multiply page for numerator accumulation.

Precision and ROUNDED

Division expands fractional part—TOTAL 100 / COUNT 3 yields 33.333... ROUNDED into P 2 stores 33.33 per policy. TRUNCATED stores 33.33 without round up on third decimal—regulatory choice. Intermediate quotient in wider W field before final ROUNDED into report field prevents double-round errors.

Precedence with Multiply

A / B * C left to right: divide A by B, multiply result by C. A * B / C multiply first when * and / left associate. AMOUNT * RATE / 100 converts stored rate percent—parentheses if policy differs: (AMOUNT * RATE) / 100. Expression TOTAL / COUNT + ADJ adds ADJ after divide—divide before add unless parens.

Division in IF Conditions

Less common than assignment—IF TOTAL / COUNT GT LIMIT compares average to threshold when COUNT known non-zero from prior guard. Prefer assign AVG first then IF AVG GT LIMIT for clarity and single divide. IF QTY GT 0 AND EXT / QTY GT MAX-UNIT detects unit price exception—validate QTY before divide in same AND chain does not short-circuit—still test QTY GT 0 explicitly first line or use nested IF.

Inverse of Multiplication

If TAX = GROSS * RATE then GROSS = TAX / RATE when RATE non-zero recovers gross from tax line—algebraic check in audit scripts. RATE = TAX / GROSS when GROSS GT 0 derives effective rate for exception report.

Division vs MOD

Slash yields quotient whole and fractional part in one number. MOD yields remainder—use for even-odd, batch slot, cycle detection. 10 / 3 quotient 3.333; 10 MOD 3 remainder 1 per MOD semantics on your release.

Invalid Packed Divisor

Divisor COUNT with corrupt packed sign causes abend like dividend issues—validate NUMERIC on both operands for FILE-sourced fields. FLDCHK during test.

Common Division Mistakes

  • Divide by zero on empty COUNT.
  • Missing ROUNDED on currency average.
  • Target P 0 field for fractional average.
  • Wrong left-to-right chain without parens.
  • Divide in IF without divisor guard.
  • Confusing / with slash in comments or paths—only in expressions.

Explain It Like I'm Five

Divide shares marbles into equal groups. Ten marbles divided by two groups gives five each. You cannot divide by zero groups—the computer gets upset. Averages are total marbles divided by how many friends shared. Sometimes you round the answer to two decimal places for pennies.

Exercises

  1. Write average with zero-safe COUNT guard and ROUNDED.
  2. Compute unit price EXT / QTY with QTY GT 0 IF.
  3. Evaluate 100 / 10 / 2 left-to-right by hand.
  4. Derive effective rate TAX / GROSS when gross positive.
  5. Contrast quotient / with remainder MOD for 17 / 5.

Quiz

Test Your Knowledge

1. AVG = TOTAL / COUNT divides:

  • TOTAL by COUNT to form quotient
  • COUNT by TOTAL
  • Strings
  • Files

2. Division by zero in Easytrieve:

  • Causes runtime data exception or abend
  • Yields zero always
  • Ignored
  • Compile error always

3. AVG = TOTAL / COUNT ROUNDED:

  • Rounds quotient into target field
  • Rounds TOTAL only
  • Skips divide
  • Truncates file

4. / and * at same precedence evaluate:

  • Typically left to right
  • Always multiply first globally
  • Never together
  • JCL order

5. Integer versus fractional quotient on P fields:

  • Implied decimals on P affect fractional quotient storage
  • Always integer
  • Always alphabetic
  • No decimals ever
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 division operator and zero divisor behaviorSources: Broadcom Easytrieve 11.6 Language Reference arithmetic operatorsApplies to: Easytrieve division operator