Native Mode Config file made easy
I was hoping for a way to provide configuration information without having to write my own subroutine to read a CONFIG or INI file. I did find something close, the Run-time Launch Configuration File. (while searching, I did find something called "Run-time Configuration" but it could only be set at compile-time, go figure!).
The mfdefault.exe.mfcfg (thanks for the correction, Chris Glazier) file can contain commands to set environment variables during the time the programs run. These environment varables can be easily read in the program using a DISPLAY/ACCEPT pair of commands. Individual files, <program name>.exe.mfcfg files, can be created and customized for an individual program. The syntax for the command in to the mfconfig file is "SETENV <variable name>=<variable value>" The quotes and "<>" marks are not part of the command.
Yes, mfdefault.exe.mfcfg. I must have had app.config on my mind while typing. One problem with using application.config files is that there does not appear to be an easy way to read the settings in Native code. When I searched for ways to read application.config in the documentation that came with Visual COBOL, in "Visual COBOL - A Developer's Guide to Modern COBOL", in Internet searches, in searches in the VC forum, I found no feature in Native Mode Visual COBOL to read application.config other than opening it as a text file and parsing the XML. How would I read the application.config file in a Native code program? Where is it documented? I just now added an application.config file in my Native code project and found that it is not an XML file. I cannot apply config transforms to it. I see that the "Application Settings" screen shows "Environment", "COBOL Switches", and "Run-time Configuration" all of these should provide a means for me to set options for the program without having to recompile the program. That is the purpose of having an application.config file. Is there a utility that allows me to change the settings in this file without recompiling? Where can I read about this file and how it works?
The run-time configuration file and settings is documented here.
My question to you is why would you need to read this file from within your application? The settings within it including environment variables will automatically be set in your programs environment prior to it being started. So if in application.config you are setting the environment variable dd_MYFILE=TESTFILE.dat, for example, the file handler will automatically use that value for the file assigned to external MYFILE.
Other environment variables and tunables will also be set accordingly so you shouldn't need to access them. If you do wish to check the setting of an environment variable you can do so using the DISPLAY UPON ENVIRONMENT-NAME/ACCEPT FROM ENVIRONMENT-VALUE syntax.
The downside of these types of files is that they need to be compiled first but this can also be a plus if you want to protect the files by being updated by other end-users.
Why would I want to read this file from withing my application? The only reason to have an application.config file is to be able to specify settings, at run time, and read them from within the program. Otherwise I may as well hard-code them into the program. When I first started writing COBOL programs, these settings were "COBOL SWITCHES" these were actual switches on the front panel of the computer, that we could set on the computer itself before the program ran, hence the name. This was the way the computer operator could communicate with the program. This way parameters could be set without having to change the actual program. Environment varaibles serve a similar purpose. They are a way to provide information that is not available at the time the program is compiled, to the program about the environment in which the program is running so that the program can adapt its behavior appropriately. One example would be to tell the program whether it is running in a Debug, Test, or Production environment. Another example would be to tell the program what server it is running on and where the files are that it needs to read.
Having an application.config file that is compiled and cannot be set according to the environment defeats the entire purpose of having an application.config file.
In the Visual Basic and C# environment, the application.config file can be edited according both using text editors and automated in the Build process to accomodate the different Build configurations.
For my Managed Code programs, I use an app.config file that allows me to change the database server name and other settings. In the IDE it automatically provides a Setting object that I can easily refer to in my program. I can also set up transforms in build process that change the settting values in app.config file according whether the Build configuration is Debug, Test, or Release.