Field Initialization in Called External Modules

Question: Scenario:
Execution Mode: Batch
Main pgm PLI calls COBOL. When the control return back to main program and when re-enters the same program, all the prev. declared working storage variables are still residing in memory and they are not reinitialized to the 'VALUE <data> ' given in working storage declaration.

Please let me how to resolve this issue.
Dhinakaran Annamalai

Answer: This is the way that all subroutine/function calls normally work in Cobol. The fields are initialized when the program first starts up rather than each time that the routine is called.

Other programming languages contain a method of defining whether the routine should behave like this or alternatively initialize all fields each time that the routine is called (usually by deciding whether the fields are defined static or not) but Cobol does not have this option.

The only way to reinitialize the fields in a Cobol subroutine/function is to explicitly move the appropriate initial values to each field in the code that is executed each time that the subroutine is called.

Note that this is not specific to Cobol modules called from PL/1, the same applies to all Cobol modules that are called, regardless of the language used in the calling program.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow