COBOL Tutorial

Progress0 of 0 lessons

COBOL WORKING-STORAGE

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.

Where it goes

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.

cobol
1
2
3
4
5
6
7
8
9
10
DATA 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

Common usage

WORKING-STORAGE examples
ExampleMeaning
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

When to use WORKING-STORAGE

  • Counters, flags, and accumulators used only inside this program.
  • Constants and literals you refer to by name.
  • Work areas and temporary fields for calculations or formatting.
  • Data that must keep its value for the whole run (or across calls in a subprogram).

Explain like I'm five

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.

Test Your Knowledge

1. In which division does WORKING-STORAGE SECTION appear?

  • IDENTIFICATION DIVISION
  • ENVIRONMENT DIVISION
  • DATA DIVISION
  • PROCEDURE DIVISION

2. How long do WORKING-STORAGE items persist?

  • Only during the current paragraph
  • Until the next PERFORM
  • For the entire program execution
  • Only until the next MOVE

Related Concepts

Related Pages