Sunday, 22 September 2013

COBOL WORKING-STORAGE VS LOCAL-STORAGE.

WORKING-STORAGE and LOCAL-STORAGE section are two important section of COBOL program which is used for defining temporary variable used for different processing and calcualtion. But interestingly variable define in these section has different scope.
WORKING-STORAGE for programs is allocated at the start of the run unit. Any data items with 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.
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 on 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.

Created with Artisteer

No comments:

Post a Comment