Highlighted
Trusted Contributor.
Trusted Contributor.
355 views

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.

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Thanks Lee.

A slight correction; the name of the file is actually mfdefault.exe.mfcfg or <program-name>.exe.mfcfg.

This is known as a run-time launch configuration file and although it can be used to set environment variables for a program run it's main purpose is to allow you to specify a non-default location to search for the COBOL run-time system when an application is linked as dynamic. Normally dynamically linked applications will look in the Visual COBOL/COBOL Server registry settings to find the location of the install folder and will load the run-time from that location. Its other purpose is to allow you to run an application from a network server without the need to install COBOL Server or licensing components on a workstation machine.

This is covered in the docs here

You can set environment variables as well as other run-time switches and tunables by adding an application.config file to your native project. You can select this from the Add-->New Item dialog. If you right-click on this file in Solution Explorer you can select Edit and bring up a small editor window that lets you add options to the file. When this is compiled it will have the name <program-name>.exe.mfgcf and it can be deployed along with your application in the same folder.

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

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?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

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.

 

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

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. 

 

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.