EVALUATE
COBOL's multi-way decision statement, and a clearer alternative to a long chain of nested IFs.
Also written EVALUATE WHEN, case statement
EVALUATE tests a value against a series of possibilities and runs the branch that matches. It is COBOL's equivalent of a case or switch statement, and it is the readable way to express business rules with several outcomes.
The structure is straightforward: state what is being evaluated, then list WHEN clauses giving the values to match and what to do for each, with WHEN OTHER catching everything unmatched. Ranges and combinations of conditions are supported, so a rule such as one band of values behaving differently from another is expressed directly.
It also has a form that evaluates several values at once, which is how decision tables are written: a grid of conditions and the action for each combination. Business rules often arrive from the business in exactly that shape, and being able to write them that way keeps the code close to the specification.
Compared with deeply nested IF statements, which older code is full of, EVALUATE is far easier to read and much harder to get wrong when a new case is added later.
Related terms
- PROCEDURE DIVISIONThe part of a COBOL program that contains the actual logic, the statements that run.
- PERFORMThe COBOL statement that runs a paragraph and returns, and the way loops are written.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.