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.
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.
12345REMAINDER = RECORD-NUM MOD 7 SLOT = SEQ-COUNT MOD 10 IF REC-NUM MOD 2 EQ 0 PERFORM EVEN-PROCESSING END-IF
| Expression | 17 and 5 example | Use |
|---|---|---|
| 17 / 5 | Quotient 3.4 on decimal fields | Averages rates |
| 17 MOD 5 | Remainder 2 | Even odd cycle bucket |
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.
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.
1234567SEQ = SEQ + 1 SLOT = SEQ MOD 10 IF SLOT EQ 0 PERFORM STREAM-TEN ELSE IF SLOT EQ 1 PERFORM STREAM-ONE * ... etc
IF DIVISOR GT 0 before REM = VALUE MOD DIVISOR. Same discipline as slash division. Literal divisor 2 or 10 safe; field divisor requires guard.
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.
Assign remainder to field for later compare or report. IF inline MOD for branch—both valid. Assign first when DISPLAY debugging remainder in test.
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.
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.
1. REMAINDER = 17 MOD 5 yields:
2. MOD differs from / because:
3. IF REC-NUM MOD 2 EQ 0 tests:
4. MOD with zero divisor:
5. Batch slot = SEQ MOD 10 might: