When user clicks the red X ...

Does the ACUCOBOL runtime for Windows (wrun32.exe) provide any support for gracefully exiting a COBOL program when the user closes the console window? The two ways that they might do this are by pressing Alt F4 or clicking the red X in the title bar.

For example, in a particular program we would like to be able to save changes before exiting when the user kills the window. We've trained the users to never do this, but old habits die hard.

Similar problems can also occur in Linux if the user closes the terminal window before exiting their COBOL program. We'd be interested in a solution for Linux as well, but the immediate need is on the Windows side.

We're currently using ACU 9.2.1 in this office. Some facilities are running ACU 8 and possibly 7.

Thank you!

  • Verified Answer

    If you display the window with the correct options you can get the Red X to not appear.

    For example, if you are displaying an "Initial Graphical Window"

    And do not include the options:

       WITH SYSTEM MENU

    or

      AUTO-MINIMIZE

    you should get a window sans the red X

  • Verified Answer

    If you display the window with the correct options you can get the Red X to not appear.

    For example, if you are displaying an "Initial Graphical Window"

    And do not include the options:

       WITH SYSTEM MENU

    or

      AUTO-MINIMIZE

    you should get a window sans the red X

  • Sounds promising. Is there any similar feature for non-graphical windows?

  • Verified Answer

    I'm not sure what all you are looking for with "gracefully exit", but if you are primarily concerned with files being closed properly, check out CLOSE_ON_EXIT.  We've set this environment variable to "2" by default for many years.  While you can use some settings to hide the "X" that closes the program, that doesn't stop someone from using Alt F4 or breaking out of the program on Linux.

    This won't help in all circumstances.  If you kill the runtime using task manager in Windows or a "kill -9" in UNIX/Linux, the runtime isn't given the opportunity to properly close the files.  As long as your program isn't in a non-responsive loop, it will still close the files with a "kill -1" or Alt F4.

    From the 7.0.0 documentation:

    CLOSE_ON_EXIT

    When set to "1" (on, true, yes), this variable enables the automatic closing of all files except print files when a program performs an EXIT PROGRAM statement. When set to "2" it enables the automatic closing of all files when a program exits. When set to "0" (off, false, no), no files will be automatically closed. For more information, see the User's Guide, section 2.7.5, "File Handling Options." The default value is "0".

  • @ShanePrice: I wasn't aware of the CLOSE_ON_EXIT option, but will check whether it's set in our configuration file. Closing Vision files properly would definitely be a good practice, but in this case I'm also concerned with being able to save changes in a .NET Windows form that's interoperating with COBOL.

    COBOL should ideally tell .NET to save its own changes to disk before everything comes crashing down. Our "end of job" procedure in COBOL does include a MODIFY statement that calls an existing C# function to save changes to the plain text file in question.

    However ... The .NET object is instantiated by COBOL. When the user kills the COBOL console window (whether by red X, alt F4, or "end process"), our end of job procedure is skipped, and the Windows form simply vanishes without an "on closed" event that .NET itself could detect and handle.

    If we can detect the on closing event in COBOL, and call the C# "save changes" function at that time, that would be ideal.

    If we can only hide the red X, that also be of interest as a partial defense against an unclean shutdown. Clicking the red X is our most common use case for an unclean exit. However, it's not clear to me how to hide the red X if we're only using a text-based SCREEN SECTION with no ACUGUI, ActiveX, or .NET controls.

    I'll leave this question open over the weekend, and will then mark any helpful answers as answers. I'll also check out the Micro Focus documentation on SCREEN SECTION options to see if there's some option that I overlooked.

    Thanks!

  • @ShanePrice: I wasn't aware of the CLOSE_ON_EXIT option, but will check whether it's set in our configuration file. Closing Vision files properly would definitely be a good practice, but in this case I'm also concerned with being able to save changes in a .NET Windows form that's interoperating with COBOL.

    COBOL should ideally tell .NET to save its own changes to disk before everything comes crashing down. Our "end of job" procedure in COBOL does include a MODIFY statement that calls an existing C# function to save changes to the plain text file in question.

    However ... The .NET object is instantiated by COBOL. When the user kills the COBOL console window (whether by red X, alt F4, or "end process"), our end of job procedure is skipped, and the Windows form simply vanishes without an "on closed" event that .NET itself could detect and handle.

    If we can detect the on closing event in COBOL, and call the C# "save changes" function at that time, that would be ideal.

    If we can only hide the red X, that also be of interest as a partial defense against an unclean shutdown. Clicking the red X is our most common use case for an unclean exit. However, it's not clear to me how to hide the red X if we're only using a text-based SCREEN SECTION with no ACUGUI, ActiveX, or .NET controls.

    I'll leave this question open over the weekend, and will then mark any helpful answers as answers. I'll also check out the Micro Focus documentation on SCREEN SECTION options to see if there's some option that I overlooked.

    Thanks!

  • This worked as described, even in a non-graphical application. Thanks!

  • This was also helpful supplementary information. Thanks!

  • I would also look at some of the Events for your screen. If all you want to do is close files you can use After-Routine or After-Program.  If you want to capture the close event and do other things before the screen is gone, then look at events like "Link To" and check for the EVENT-TYPE = CMD-CLOSE and/or KEY-STATUS = 27. There are many ways to know if the window is being closed by clicking on the X and/or pressing Alt-F4