The LOCAL-STORAGE SECTION is part of the DATA DIVISION. Data items you define there are reinitialized each time the program is entered (each time it is called). That makes LOCAL-STORAGE suitable for work areas and temporary data that should start fresh on every invocation, and for programs that must be reentrant. This page explains how LOCAL-STORAGE works and when to use it instead of WORKING-STORAGE.
WORKING-STORAGE is like a desk you keep between visits: things stay where you left them. LOCAL-STORAGE is like getting a new desk every time you enter the room: each time the program is called, you get a clean desk with the same starting setup (VALUE clauses). So if you want something to remember from call to call, use the "persistent desk" (WORKING-STORAGE). If you want a clean slate every time, use the "new desk" (LOCAL-STORAGE).
When the program is called, storage for LOCAL-STORAGE items is allocated (or made active), and each item is initialized according to its VALUE clause (or to default values if no VALUE is given). When the program exits (e.g. GOBACK, EXIT PROGRAM, STOP RUN), that storage is no longer in use for that invocation. On the next call, the program gets LOCAL-STORAGE again and it is reinitialized. So values in LOCAL-STORAGE do not carry over from one call to the next.
| Aspect | WORKING-STORAGE | LOCAL-STORAGE |
|---|---|---|
| When initialized | Once at run-unit start (or when program first loaded) | Every time the program is called |
| When values persist | Until run unit ends or program CANCELed/INITIAL | Only for the duration of that call |
| Typical use | State across calls, accumulators, flags | Fresh work areas, reentrant programs |
LOCAL-STORAGE SECTION appears in the DATA DIVISION, typically after WORKING-STORAGE SECTION and before LINKAGE SECTION. You code it like WORKING-STORAGE: level numbers, data names, PICTURE (or USAGE POINTER, etc.), and VALUE clauses. The difference is not the syntax but the lifetime and reinitialization behavior.
1234567891011121314151617DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-CALL-COUNT PIC 9(5) VALUE ZERO. *> Persists across calls LOCAL-STORAGE SECTION. 01 LS-WORK-AREA. 05 LS-TEMP PIC X(80). 05 LS-LEN PIC 9(4) VALUE 0. *> Fresh on each call LINKAGE SECTION. 01 LK-PARAM PIC X(100). PROCEDURE DIVISION USING LK-PARAM. ADD 1 TO WS-CALL-COUNT *> Keeps count across calls MOVE SPACES TO LS-TEMP *> LS- items already reinitialized *> ... use LS-WORK-AREA ... GOBACK.
1. When is LOCAL-STORAGE reinitialized?
2. You want a counter that stays across multiple CALLs to your program. Where should you define it?