Menu

When GnuCOBOL DLL is called it closes all open files on exit even if these files were open in a caller program

Gary
2025-04-30
2025-05-01
  • Gary

    Gary - 2025-04-30

    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:

    IDENTIFICATION DIVISION. 
       PROGRAM-ID.  SUB1 IS INITIAL PROGRAM.
    

    Any suggestion how to make a subprogram not to close any file it received as open one?

     

    Last edit: Simon Sobisch 2025-05-02
    • Vincent (Bryan) Coen

      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
    • Ralph Linkletter

      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

       

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.