WORKING-STORAGE
The section where a program declares its own fields: counters, totals and flags.
Also written WORKING-STORAGE SECTION
Why it matters. Every program needs somewhere to keep its running total. This is that place.
See it
Variables are declared here, before the code that uses them.
Syntax
WORKING-STORAGE SECTION. 01 field-name PIC picture VALUE literal.
- VALUE
- The start value, set when the program begins.
- ZERO / ZEROS
- Start a number at zero.
- SPACES
- Start text as blanks.
- INITIALIZE
- A statement that sets fields back to start values while running.
Try it WORKING-STORAGE
- 1
In the WORKING-STORAGE SECTION of the program TOTAL, declare WS-TOTAL: 5 digits, then 2 decimals. It must start at zero.
COBOL 01 WS-TOTAL PIC 9(5)V99 VALUE ZERO. - 2
Run TOTAL. It adds two payments, 120.50 and 79.50, and shows the total.
RUNCOBOL 'ZB0001.DEV.COBOL(TOTAL)'
Remember
- WORKING-STORAGE holds the program's own fields: counters, totals and flags.
- VALUE sets the start. Always give a total or a counter a VALUE.
- A field keeps its value until the program changes it or ends. In a called program it keeps it between calls too.
The usual mistake
01 WS-TOTAL PIC 9(5)V99.
There is no start value. The total starts with whatever was in that storage, often binary zeros, which are not a valid number. The first ADD can abend with S0C7.
01 WS-TOTAL PIC 9(5)V99 VALUE ZERO.
On real z/OS
MF/OS gives a field with no VALUE a clean start, so a missing VALUE seldom shows. On real z/OS the content can be anything, and a number may abend with S0C7 when first used.
Where can I practise WORKING-STORAGE?
Right here, at ZedBank. You take a junior job at a simulated bank and use WORKING-STORAGE in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.
- PICTURE clauseThe COBOL declaration that says what kind of data a field holds and how long it is, written as PIC.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.
- PROCEDURE DIVISIONThe part of a COBOL program that contains the actual logic, the statements that run.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.