Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Using files defined as EXTERNAL with Visual COBOL

Using files defined as EXTERNAL with Visual COBOL

Problem:

Many Visual COBOL projects may use the same EXTERNAL data files, this usually would require setting an environment variable for each file within an Application.config.

How can these file mappings be achieved without the use of an Application.config?

Resolution:

Setting EXTERNAL file variables within a Visual COBOL project

In the example below, an entry needs to be added to an Application.config file (Environment) in order for the physical file assignment for the SELECT clause to be resolved:

 

If EXTERNAL does not appear in the SELECT statement, the program must be compiled with the directive ASSIGN(EXTERNAL):

To add an application configuration file, right-click your project in the Solution Explorer:

    Click Add > New Item

  • Select Application Configuration File
  • Specify a filename in the Name field (or leave as is)
  • Click OK


Edit the Application.config; add the variable name and file name:



Setting EXTERNAL file variables within the environment

The environment variable can be set in the environment before launching Visual COBOL. An entry in the Application.config would not be necessary.

When Visual COBOL is started, it will inherit the settings from the environment, a batch file or script can be used to set up various environment variables and file mappings etc. before launching Visual COBOL.

The most straight-forward way to set the variables externally is to start a Visual COBOL command prompt, then set the file mapping and start Visual COBOL:

 

Creating a script to set COBCPY and launch Visual Studio

REM *
REM * Set File mappings externally then start Visual Studio
REM *
REM *
REM * Call createenv.bat to set the COBOL environment
REM *
CALL "C:\Program Files (x86)\Micro Focus\Visual COBOL\createenv.bat"
REM *
REM * Add file mappings
REM *
SET MASTDAT1=C:\ExternalFilesDemo\DATA\MASTER.DAT
REM *
REM * Start Visual Studio ( use MFDEVENVnn - where nn represents version of Visual Studio)
REM * Alternatively start Visual Studio using DEVENV ("C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\DEVENV:)
REM * The example above uses Visual Studio 2015.
REM *
mfdevenv14.0
REM *
REM * Close the command prompt
REM *
EXIT

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2016-11-03 18:45
Updated by:
 
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.