Free-format RPG supports compound assignment operators as shorthand for modifying a variable using its current value:
| Operator | Equivalent | Description |
|---|---|---|
x += expr; |
x = x + expr; |
Add and assign |
x -= expr; |
x = x - expr; |
Subtract and assign |
x *= expr; |
x = x * expr; |
Multiply and assign |
x /= expr; |
x = x / expr; |
Divide and assign |
These work with all numeric types (PACKED, ZONED, INT, UNS) and support complex expressions on the right-hand side:
wRRN += 1; // Increment RRN counter
total -= qty * price; // Subtract computed amount
amount *= 0.85; // Apply 15% discount