PROCEDURE DIVISION
The part of a COBOL program with the logic: the statements that run, from top to bottom.
Also written PROCEDURE DIVISION
Why it matters. Everything the program does is here. When a payment is wrong, this is where you look.
See it
The code starts here and runs from the top.
Syntax
PROCEDURE DIVISION [USING data-name ...]. paragraph-name. ADD amount TO field [ROUNDED] [ON SIZE ERROR statements] [END-ADD]
- USING
- Fields passed in from a caller (a subprogram only).
- paragraph-name.
- A named block that PERFORM can run.
- ROUNDED
- Round the result instead of cutting it.
- ON SIZE ERROR
- What to do if the result does not fit the field.
- GIVING
- Put the result in another field instead of changing the first.
Try it PROCEDURE DIVISION
- 1
In the PROCEDURE DIVISION of the program ADDBAL, make the field WS-BAL bigger by 250.
COBOL ADD 250 TO WS-BAL - 2
Run ADDBAL. It shows the balance before and after your line.
RUNCOBOL 'ZB0001.DEV.COBOL(ADDBAL)'
Remember
- The PROCEDURE DIVISION holds the statements. They run from top to bottom.
- Paragraphs are named blocks inside it. PERFORM runs them.
- STOP RUN ends the run. GOBACK returns to the caller, and in a main program it ends the run too.
The usual mistake
ADD 250 TO WS-BALANCE
WS-BALANCE is not in the DATA DIVISION. The compiler stops, and the program does not run.
ADD 250 TO WS-BAL
On real z/OS
MF/OS cannot run a subprogram CALL: it prints a note and carries on. Declaratives (USE sections) aren't parsed.
Where can I practise PROCEDURE DIVISION?
Right here, at ZedBank. You take a junior job at a simulated bank and use PROCEDURE DIVISION in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- COBOL divisionsThe four fixed sections every COBOL program is built from, always in the same order.
- PERFORMThe COBOL statement that runs a paragraph and returns, and the way loops are written.
- EVALUATECOBOL's multi-way decision statement, and a clearer alternative to a long chain of nested IFs.
- WORKING-STORAGEThe section of a COBOL program that declares its internal variables: counters, totals, flags and work areas.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.