Easytrieve MOD Operator

MOD returns the remainder after division—the piece left over when one integer divides another evenly as far as possible. Seventeen MOD five yields two because seventeen divided by five is three remainder two. Slash gives the quotient three point something; MOD gives the leftover two. Batch utilities use MOD for even-odd routing—IF REC-NUM MOD 2 EQ 0 processes even records on alternate path—for cyclic batch slot assignment—SLOT = SEQ MOD 10 distributes work across ten parallel job streams—and for leap-year or calendar cycle checks in date utilities. MOD shares division hazards: zero divisor abends. Operand types follow numeric rules like slash. This page teaches MOD syntax, contrast with quotient, even-odd patterns, cyclic indexing, combination with IF, alternative remainder formula using divide and multiply when documenting legacy, and validation before MOD on FILE fields.

Progress0 of 0 lessons

Basic Syntax

TARGET = dividend MOD divisor. REM = 17 MOD 5. SLOT = SEQ-NUM MOD 10. MOD keyword separates operands—distinct from COBOL FUNCTION MOD in other languages but conceptually same remainder. Verify exact keyword spelling MOD on your release language reference.

text
1
2
3
4
5
REMAINDER = RECORD-NUM MOD 7 SLOT = SEQ-COUNT MOD 10 IF REC-NUM MOD 2 EQ 0 PERFORM EVEN-PROCESSING END-IF

MOD vs Division

Quotient versus remainder
Expression17 and 5 exampleUse
17 / 5Quotient 3.4 on decimal fieldsAverages rates
17 MOD 5Remainder 2Even odd cycle bucket

Even and Odd Tests

IF EMP-NUM MOD 2 EQ 0 routes even employee numbers—alternate file stripe pattern. IF EMP-NUM MOD 2 EQ 1 odd path. Validate EMP-NUM NUMERIC before MOD on FILE extract. Some shops use bit test on binary field instead—bit fields page for mask alternative.

Cyclic Bucket Assignment

SEQ increments each record; SLOT = SEQ MOD 10 yields 0 through 9 repeating—partition records across ten output datasets or ten PROC variants in utility programs. BATCH-ID = JOB-NUM MOD 4 load balances four batch streams. Document whether slot zero is valid business bucket.

text
1
2
3
4
5
6
7
SEQ = SEQ + 1 SLOT = SEQ MOD 10 IF SLOT EQ 0 PERFORM STREAM-TEN ELSE IF SLOT EQ 1 PERFORM STREAM-ONE * ... etc

Zero Divisor Guard

IF DIVISOR GT 0 before REM = VALUE MOD DIVISOR. Same discipline as slash division. Literal divisor 2 or 10 safe; field divisor requires guard.

Alternative Remainder Formula

Legacy or teaching equivalence: REM = VALUE - (VALUE / DIV) * DIV with integer division semantics—MOD clearer and one operation. Rounding in divide step corrupts remainder if fractional quotient—use MOD operator not manual formula on packed currency fields.

MOD in Assignment vs IF

Assign remainder to field for later compare or report. IF inline MOD for branch—both valid. Assign first when DISPLAY debugging remainder in test.

Numeric Types

Integer remainder concept on whole values—packed P 0 or N fields common. Remainder on fractional packed may follow product integer truncation rules—test 17.5 MOD 5 on your installation if fractional MOD appears in spec; payroll MOD usually on integer counters.

Common MOD Mistakes

  • MOD when / quotient needed—wrong operator.
  • Zero divisor on field MOD.
  • MOD on non-numeric FILE field.
  • Assuming slot range without testing SEQ start value.
  • Confusing MOD with MASK display formatting.
  • Manual remainder formula with rounded divide.

Explain It Like I'm Five

MOD is what is left in your hand after sharing marbles equally. Seventeen marbles shared among five friends—each gets three and you have two left. Those two left are the MOD. Divide tells how many each friend gets; MOD tells the leftover. You cannot share among zero friends.

Exercises

  1. Compute 23 MOD 4 and 23 / 4—state quotient and remainder.
  2. Write IF even test on COUNTER MOD 2.
  3. Assign SLOT = SEQ MOD 8; list slot values SEQ 1 through 10.
  4. Add divisor GT 0 guard before MOD assignment.
  5. Explain when MOD beats / for batch routing.

Quiz

Test Your Knowledge

1. REMAINDER = 17 MOD 5 yields:

  • 2
  • 3
  • 3.4
  • 17

2. MOD differs from / because:

  • MOD returns remainder not quotient
  • MOD concatenates
  • MOD is logical
  • MOD is FILE

3. IF REC-NUM MOD 2 EQ 0 tests:

  • Even record number
  • EOF
  • Negative
  • Alphabetic

4. MOD with zero divisor:

  • Unsafe like division by zero—guard divisor
  • Returns zero always
  • Returns one
  • Compile only

5. Batch slot = SEQ MOD 10 might:

  • Map sequence to slot 0-9 cycle
  • Open file
  • Sort records
  • Compile MACRO
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 MOD remainder operatorSources: Broadcom Easytrieve 11.6 Language Reference arithmetic operatorsApplies to: Easytrieve MOD operator