PERFORM
The COBOL statement that runs a paragraph and returns, and the way loops are written.
Also written PERFORM UNTIL, PERFORM VARYING
PERFORM is how COBOL structures execution. In its simplest form it runs a named paragraph and comes back to the statement after it, which is the language's equivalent of calling a routine.
It is also the loop construct. PERFORM UNTIL repeats a paragraph until a condition becomes true, which is how nearly every batch program processes a file: keep reading and handling records until the end is reached. PERFORM VARYING adds a counter that steps through values, used for working through tables. PERFORM a number of TIMES repeats a fixed count.
A related form, PERFORM THRU, runs a range of paragraphs in sequence. It appears often in older code and is a common source of confusion, because inserting a paragraph in the middle of a range silently changes what runs.
Inline PERFORM, where the statements sit directly inside the PERFORM rather than in a separate paragraph, is available in modern COBOL and produces code much closer to what a reader coming from another language expects.
Related terms
- PROCEDURE DIVISIONThe part of a COBOL program that contains the actual logic, the statements that run.
- EVALUATECOBOL's multi-way decision statement, and a clearer alternative to a long chain of nested IFs.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.
- File descriptionThe FD entry in a COBOL program that describes a file's records, connecting the program to data supplied by the JCL.