Comparison of WORKING-STORAGE and LOCAL-STORAGE

How data items are allocated and initialized varies depending on whether the items are in the WORKING-STORAGE SECTION or LOCAL-STORAGE SECTION.

WORKING-STORAGE for programs is allocated when the run unit is started.

Any data items that have VALUE clauses are initialized to the appropriate value at that time. For the duration of the run unit, WORKING-STORAGE items persist in their last-used state. Exceptions are:

  • A program with INITIAL specified in the PROGRAM-ID paragraph

    In this case, WORKING-STORAGE data items are reinitialized each time that the program is entered.

  • A subprogram that is dynamically called and then canceled

    In this case, WORKING-STORAGE data items are reinitialized on the first reentry into the program following the CANCEL.

WORKING-STORAGE is deallocated at the termination of the run unit.

See the related tasks for information about WORKING-STORAGE in COBOL class definitions.

A separate copy of LOCAL-STORAGE data is allocated for each call of a program or invocation of a method, and is freed on return from the program or method. If you specify a VALUE clause for a LOCAL-STORAGE item, the item is initialized to that value on each call or invocation. If a VALUE clause is not specified, the initial value of the item is undefined.

Threading: Each invocation of a program that runs simultaneously on multiple threads shares access to a single copy of WORKING-STORAGE data. Each invocation has a separate copy of LOCAL-STORAGE data.

Example: storage sections

related references  
WORKING-STORAGE SECTION (Enterprise COBOL for z/OS Language Reference)  
LOCAL-STORAGE SECTION (Enterprise COBOL for z/OS Language Reference)