COBOL EVALUATE Statement: Syntax, Example, Limits and Best Practices
Learn how COBOL's EVALUATE statement replaces nested IFs with a clean multi‑way branch, see a salary‑grading example, and understand its limits and typical pitfalls.
27 May 2026, 22:53 UTC

When to use EVALUATE
If you need to choose one of several branches based on a value or a set of conditions, the COBOL EVALUATE statement gives a clear, readable alternative to nested IF sentences. It improves maintainability and makes the decision logic easy to follow.
Worked example: salary grading
Assume a data item WS-SALARY holds an employee’s annual salary. We want to assign a grade:
- salary > 10 000 → ‘H’ (high)
- salary > 5 000 → ‘M’ (medium)
- otherwise → ‘L’ (low)
IDENTIFICATION DIVISION.
PROGRAM-ID. SALGRADE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-SALARY PIC 9(5) VALUE ZERO.
01 WS-GRADE PIC X VALUE SPACE.
PROCEDURE DIVISION.
MOVE 12000 TO WS-SALARY *> try different values to test
EVALUATE TRUE
WHEN WS-SALARY > 10000
MOVE 'H' TO WS-GRADE
WHEN WS-SALARY > 5000
MOVE 'M' TO WS-GRADE
WHEN OTHER
MOVE 'L' TO WS-GRADE
END-EVALUATE
DISPLAY 'SALARY: ' WS-SALARY ' GRADE: ' WS-GRADE
GOBACK.
END PROGRAM SALGRADE.
The subject of the EVALUATE is the literal TRUE. Each WHEN clause contains a conditional expression; the first clause that evaluates to true is executed, and control passes to the statement after the matching END-EVALUATE. If none of the specific WHEN clauses match, the WHEN OTHER clause acts as a default.
How EVALUATE works
The statement evaluates the subject (either a data item or the literal TRUE) against each WHEN clause in order. When a clause’s condition is true, its associated imperative statements are run, and after the END-EVALUATE processing continues. If the subject is not TRUE, only simple relational expressions, literal values, figurative constants, or range tests with THROUGH are permitted in the WHEN clauses.
Limits
According to the ISO/IEC 1989:2014 COBOL standard:
- When the subject is a data item (not
TRUE),WHENclauses may contain only simple relational expressions (e.g.,WS-SALARY > 5000), literal values, figurative constants, or range tests usingTHROUGH(e.g.,WHEN 1 THROUGH 9). - When the subject is
TRUE, any valid conditional expression is allowed, including complex combinations ofAND,OR, arithmetic, or function calls. - An
EVALUATEblock can be nested inside anotherEVALUATEblock, provided each level has its own matchingEND-EVALUATE. The compiler treats each pair as a distinct construct.
Complex expressions that are not allowed with a non‑TRUE subject must first be moved to a temporary data item before they can be used in a WHEN clause.
Common mistakes and how to avoid them
- Missing
END-EVALUATEForgetting the terminator causes the compiler to treat the following procedural code as part of theEVALUATEblock, leading to unintended fall‑through. Always pair everyEVALUATEwith an explicitEND-EVALUATE. - Placing
WHEN OTHERbefore specific clauses Because evaluation stops at the first true condition, a prematureWHEN OTHERmakes all laterWHENclauses unreachable. KeepWHEN OTHERas the last clause unless you intentionally want a catch‑all early. - Overlapping conditions without
THROUGHUsing the same subject variable in multipleWHENclauses can create overlapping ranges (e.g.,WHEN WS-SALARY > 5000followed byWHEN WS-SALARY > 3000). The second clause will never be reached. UseTHROUGHto express non‑overlapping intervals or order clauses from most specific to most general. - Modifying the subject inside a
WHENclause Changing the value of the subject (or a variable used in the condition) while inside a clause can confuse the flow, especially if the change affects later clauses. Treat the subject as read‑only within theEVALUATEblock unless the modification is deliberate and documented.
Practical verification
- Save the program to a file named
salgrade.cob. - Compile with a COBOL compiler; for example, using GNUCobol 3.2:
- Run the produced executable and observe the output. Change the value assigned to
WS-SALARY(e.g., 4000, 7500, 12000) and re‑run to see the grade switch between ‘L’, ‘M’, and ‘H’. - If the output matches the expected grade for each salary, the
EVALUATEconstruct is working correctly.
cobc -x salgrade.cob
This command produces an executable named salgrade (or salgrade.exe on Windows). Ensure you have write permission in the current directory; the operation will overwrite any existing file with the same name.
These steps provide a quick, repeatable way to validate the branching logic without relying on untested claims.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.