The equals sign in assignment context stores a value into a field. GROSS = BASE + BONUS calculates pay components and writes the result to GROSS. STATUS = ACTIVE sets a code literal. COUNT = COUNT + 1 increments a counter. The same symbol in IF STATUS = ACTIVE compares for equality—context tells assignment from comparison. Assignment accepts arithmetic expressions with + - * / ** and nested parentheses. ROUNDED and TRUNCATED follow the expression to control decimal behavior on numeric targets. Type conversion applies when source and target differ—packed to zoned, numeric to alphabetic via edit patterns. SPACE HIGH-VALUES LOW-VALUES and ZERO act as source constants. Beginners use = in IF thinking it assigns, or omit ROUNDED on currency fields and audit finds penny drift. This page teaches assignment syntax, contrast with EQ keyword in IF, expression evaluation order, modifiers, constant sources, field-to-field copy via assignment, increment patterns, and testing assignments in Easytrieve batch jobs.
Assignment appears in JOB activities and PROC bodies as a standalone statement: target = expression. Target must be a writable field—W working storage, file output buffer, or report work field defined in Library. Expression may be literal, field reference, or full arithmetic. Multiple assignments execute in source order unless control flow redirects.
12345678JOB INPUT PAYROLL GROSS = BASE + BONUS + OT-PAY TAX = GROSS * TAX-RATE ROUNDED NET = GROSS - TAX IF NET LT 0 NET = 0 END-IF
| Context | Example | Meaning |
|---|---|---|
| Assignment statement | AMT = 100 | Store 100 into AMT |
| IF condition | IF AMT = 100 | Test whether AMT equals 100 |
| IF with EQ keyword | IF AMT EQ 100 | Same comparison—keyword form |
| Assignment from field | AMT = LIMIT | Copy LIMIT value into AMT |
Expressions evaluate with standard precedence: ** before * and / before + and -. Use parentheses to override: DISCOUNT = (AMT * RATE) + FEE. Mixed-type arithmetic promotes per compiler rules—verify packed decimal scale on currency jobs. Division by zero causes runtime errors—guard with IF before assign when divisor can be zero.
Append ROUNDED or TRUNCATED after the expression on numeric targets. TAX = GROSS * RATE ROUNDED for penny-aligned tax. AVG = TOTAL / COUNT TRUNCATED when policy drops fractional units. Omitting modifiers uses default truncation behavior for field type—document shop standard for financial fields. Inconsistent ROUNDED usage across related programs causes reconciliation gaps between subsystems.
123COMM-PCT = SALES / QUOTA COMM-AMT = SALES * COMM-PCT ROUNDED ADJ-AMT = RAW-AMT TRUNCATED
ZERO assigns numeric zero. SPACE assigns blank fill to alphabetic targets. HIGH-VALUES and LOW-VALUES set all bits high or low for sentinel patterns—common in COBOL-aligned interfaces. Literal strings and numbers assign directly: CODE = 01 or REGION = EAST with appropriate quoting for alphabetic fields.
Assigning numeric result to alphabetic may require edit-compatible intermediate or use documented conversion functions elsewhere in program. Assigning alphabetic to numeric parses digits per rules—invalid data causes runtime issues. Short field to long field pads; long to short truncates with possible data loss—match Library lengths to file layouts.
COUNT = COUNT + 1 increments per processed record. TOTAL = TOTAL + AMT accumulates running sums—often paired with SUM in reports for verification. WS-IDX = WS-IDX + 1 drives manual loop counters. Functional update style reads current value, computes new, stores back in one statement.
IF AMT GT LIMIT then AMT = LIMIT caps values. ELSE branches assign alternatives. Some shops use nested IF; others use single-line assign only when condition passes. No ternary operator—explicit IF blocks assign conditionally.
Simple field copy: DEST = SOURCE equals MOVE SOURCE TO DEST in many cases. Assignment shines when expression arithmetic is required. MOVE handles some group moves and bulk patterns documented separately. Choose assignment for calculations; consider MOVE for structured copy idioms your site standardizes.
Assignment equals put this answer in the box. If the box is labeled GROSS and you write GROSS = 500, the box now holds 500. If you write GROSS = BASE + BONUS, the computer adds two other boxes and puts the sum in GROSS. In an IF line, equals asks a question—is this box exactly this value?—instead of changing the box. Same sign, different job depending on whether you are storing or asking.
1. GROSS = BASE + BONUS in JOB logic:
2. IF STATUS = ACTIVE uses = as:
3. COUNT = COUNT + 1:
4. ROUNDED after assignment expression:
5. NAME = SPACE clears alphabetic field by: