Create a project and import source

Follow these steps to use your source files in a new project in Visual COBOL.

  1. In Visual Studio, click File > New > Project.
  2. In the Create a new project dialog box, select COBOL from the Language drop-down list.
    This gives you a list of the following project types. The main difference between these types is the nature of the artefacts they build, and after creating a project, you can easily change its type and output accordingly.
    • Windows Application - creates a project that builds a single executable .exe by default, and is best used for graphical applications.
    • Console Application - creates a project that builds a single executable .exe, and is best used for character-based applications that use the console subsystem. You can configure it to build an .exe file for each source program.
    • Link Library - creates a project that builds a single .dll file.
    • INT/GNT - creates a project that, by default, outputs one .int file for each of your source programs. You can change the build order to .gnt by right-clicking the project in Solution Explorer and choose Properties, select the COBOL tab, and choose Compile to .gnt.
    The other fields in this dialog box specify the folder structure in which your project will be placed:
    • Project name - the name of the project.
    • Location - the folder in which the project will be created. If you specify a folder that doesn't exist, Visual Studio will create it.
    • Solution name - a solution is a container in which you can group logically-related projects. Only one solution can be open in Visual Studio at a time. At this stage you can either create a new solution that will use the name specified, or add the project to the solution currently open in Visual Studio.

      You can check Place solution and project in the same directory in order to give the solution a different name to the project name. This is useful when you are likely to have several projects in the same solution.

  3. Right-click your project in Solution Explorer and select Add > Existing Item.
  4. Click Add and navigate to the folder containing the files you want to add to the project.
  5. Choose the files you want to add and then click Add.

    Those files are then added to the project in Solution Explorer. These files are copied, not moved, to the project folder in the file system. If you click the down arrow on the Add button, you can choose Add as Link, which adds a reference to the file in the project but neither moves or copies the original. Added files have the icon ; linked files are indicated by the icon .

    Note: If you right-click your project in Solution Explorer and choose Add Existing COBOL Items, you choose a folder instead of individual files. All files in that folder with the extensions listed in the Specify Source Files page of the import wizard are then added to the project in Solution Explorer. You can only add files as links using this method.

Adding copybooks

You can add copybooks to your projects in the same way as COBOL files, by right-clicking your program, choosing Add > Existing Item and browsing to a copybook. However, it is not compulsory to add copybooks to your project. You can set the copybook dependency paths for your project from the Project Properties > Copybook Paths page. Copybooks are not compiled at build time due to the file's Build Action property being automatically set to None. (You can also set this property for COBOL source files too, to keep a file in the project but not include a built version in any output.)

By default, Visual COBOL identifies files as copybooks by their .cpy extension. You can specify other file extensions as copybooks in the IDE preferences - click Tools > Options > Text Editor > Micro Focus COBOL > Advanced > Copybook Extensions, and enter the additional values in the text box. Alternatively, you can add the copybook with unknown extension to your project and then reference the file from within a COBOL program using the COPY statement. Visual COBOL then recognizes that extension as a copybook but only across the current solution.

Setting Compiler directives

Some Compiler directives are set on project creation, and differ between the Debug and the Release configurations. To add directive to your project, right-click on the project in Solution Explorer and choose Properties. On the COBOL tab, you can see directives that are set by the IDE in the Build Settings text box. Enter others in the Additional Directives text box as a space-separated list.

If you use a separate text file to manage your directives, you can reference this instead by entering the USE"directives file" directive. You should enter a path relative to the project directory.

Building the project

Having added all the files and made any necessary configuration changes, you can compile and link the COBOL source and generate the output. Right-click the project in Solution Explorer and click Build.

If your source code contains tab stops compilation might fail, as while a COBOL tab is eight characters long, the IDE's tab is four characters long, and lines of code might be starting in the sequence number and indicator areas section (columns one to seven) of the program instead of from column eight.

You can fix this problem using the SOURCETABSTOP(n) compiler directive, where n is the number of space characters by which to expand tab characters during compilation.