Is there any option when compiling or running DLL to prevent it from closing files opened by the caller program?
Main program opens a Log file and then it passes it to all dynamically called subprograms to write their portion of the log records.
Main program uses CANCEL statement when each subprogram execution is done.
Each subprogram has INITIAL in IDENTIFICATION division:
Suggest you remove all CANCEL statements but in any event their usage is very dependent on GC settings via conf etc.
I was told many years ago that they had no effect but that might well have now changed BUT if it really does cancel the module which will force file closures that may well be your problem and no - I have not tired it as I leave all called modules alone even if the process files that are used by others.
Note that if opening a seq file as EXTEND and the file does NOT exist it will not create it.
Likewise for open I-O - in all cases you must test for non zero after all operations as is standard - Never assume :)
Last edit: Simon Sobisch 2025-05-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If SUB1 is a subroutine then this occurs.
I would suggest the use of a first-time indicator or whatever to reset working storage fields to there initial state as required. I avoid the use of "IS INITIAL" .
In COBOL, the "IS INITIAL" clause within the PROGRAM-ID paragraph defines a program as an "initial program". This means that every time the program is called, it will be reset to its initial state, including initializing data items with VALUE clauses and closing non-EXTERNAL files. Initial programs are also removed from memory when they exit, while non-initial programs remain in memory until explicitly cancelled.
IS INITIAL Clause:
When specified in the PROGRAM-ID paragraph, this clause designates the program as an initial program.
Program Reset on Entry:
Every time an initial program is called, it is placed in its initial state
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there any option when compiling or running DLL to prevent it from closing files opened by the caller program?
Main program opens a Log file and then it passes it to all dynamically called subprograms to write their portion of the log records.
Main program uses
CANCEL
statement when each subprogram execution is done.Each subprogram has
INITIAL
inIDENTIFICATION
division:Any suggestion how to make a subprogram not to close any file it received as open one?
Last edit: Simon Sobisch 2025-05-02
Suggest you remove all CANCEL statements but in any event their usage is very dependent on GC settings via conf etc.
I was told many years ago that they had no effect but that might well have now changed BUT if it really does cancel the module which will force file closures that may well be your problem and no - I have not tired it as I leave all called modules alone even if the process files that are used by others.
Note that if opening a seq file as EXTEND and the file does NOT exist it will not create it.
Likewise for open I-O - in all cases you must test for non zero after all operations as is standard - Never assume :)
Last edit: Simon Sobisch 2025-05-02
If SUB1 is a subroutine then this occurs.
I would suggest the use of a first-time indicator or whatever to reset working storage fields to there initial state as required. I avoid the use of "IS INITIAL" .
In COBOL, the "IS INITIAL" clause within the PROGRAM-ID paragraph defines a program as an "initial program". This means that every time the program is called, it will be reset to its initial state, including initializing data items with VALUE clauses and closing non-EXTERNAL files. Initial programs are also removed from memory when they exit, while non-initial programs remain in memory until explicitly cancelled.
IS INITIAL Clause:
When specified in the PROGRAM-ID paragraph, this clause designates the program as an initial program.
Program Reset on Entry:
Every time an initial program is called, it is placed in its initial state