WORKING-STORAGE is the DATA DIVISION section where you define program-owned variables, constants, and work areas. Unlike the LINKAGE SECTION (parameters from the caller) or FILE SECTION (record layouts), WORKING-STORAGE holds data that is private to the program and persists for the whole run. For a full tutorial see WORKING-STORAGE SECTION.
WORKING-STORAGE SECTION. appears once in the DATA DIVISION, usually after FILE SECTION (if you have files) and before LINKAGE SECTION (if the program receives parameters). After the section header you list 01-level and subordinate data description entries.
12345678910DATA DIVISION. FILE SECTION. *> file records here if needed WORKING-STORAGE SECTION. 01 WS-COUNTER PIC 9(5) VALUE ZEROS. 01 WS-NAME PIC X(30) VALUE SPACES. 01 WS-GROUP. 05 WS-FIELD-A PIC X(10). 05 WS-FIELD-B PIC 9(4). *> LINKAGE SECTION next if program is called
| Example | Meaning |
|---|---|
| WORKING-STORAGE SECTION. | Starts the section; follows FILE SECTION if present |
| 01 WS-ITEM PIC X(20). | Single 20-character alphanumeric variable |
| 01 WS-NUM PIC 9(5) VALUE ZEROS. | Numeric field initialized to zero |
| 01 WS-GROUP. 05 WS-A PIC X(10). 05 WS-B PIC 9(4). | Group item with two elementary fields |
WORKING-STORAGE is the program's own notepad: boxes (variables) that only this program uses and that stay there until the program finishes. The caller's data lives in LINKAGE; the program's internal scratch space lives in WORKING-STORAGE.
1. In which division does WORKING-STORAGE SECTION appear?
2. How long do WORKING-STORAGE items persist?