Using Visual COBOL for Visual Studio

Understanding the structure of Visual COBOL solutions

On creating a new project, the following files are created in the file system with the following structure:

...
   |_Location
     |_Solution
     | |_Name
     |   |_bin
     |   | |_x86
     |   | | |_Debug
     |   | | |_Release
     |   | |
     |   | |_x64
     |   |   |_Debug
     |   |   |_Release
     |   | 
     |   |_obj
     |   | |_x86
     |   | | |_Debug
     |   | | |_Release
     |   | |
     |   | |_x64
     |   |   |_Debug
     |   |   |_Release
     |   | 
     |   |_Properties
     |
     |_Solution.sln
     |_Name.cblproj
     |_Name.dep
     |_Program1.cbl

If you select the Create Directory for Solution option when creating a solution, the structure is slightly different.

In the Solution folder:

  • Solution.sln - a description of the solution and what it contains.
  • Name.cblproj - the project file that is opened in Visual Studio, which holds the description of the project and all its related configuration and directives information.
  • COBOL source files - when you create a project, a skeleton COBOL source file Program1.cbl is added for most of the project templates.

In the Name folder:

  • ..\bin - this is the default location of build artefacts. With this folder are the subfolders x86\Debug that contains the executables or libraries, and .idy file for each of the project's COBOL source files. The .idy files contain information required for debugging your application. When you use the Release build configuration, build output goes to a subfolder x86\Release and no .idy files are created.

    Debug and Release are standard build configurations that you launch from the Visual Studio task bar. They use a different set of compiler directives as well as outputting different files. You can create your own build configurations by clicking Build > Configuration Manager and choosing New from the Active solution configurations drop-down list.

    The x86 folder exists because the default output platform is 32-bit. If you change this to be 64-bit, you will instead find your ouptut in an x64 folder.

  • ..\obj - this also has x86\Debug subfolders, and contains an .obj file for each source file, used in intermediate build stages. The obj folder also holds supporting information such as logs and file lists.
Note: The project file .cblproj is an msbuild file, much like a makefile but consisting of XML that you can extend and modify to customise your builds. You can use this directly from command line, as it uses the same build environment as the IDE, and behavior is identical. This means you can have a single source of configuration information that makes your build process easier to maintain.

If you open a command prompt and change to the Location folder, you can execute the msbuild command, without needing to specify the .cblproj file.

Finding your way around the IDE's features

  • Solutions and projects

    A solution is a container holding one or more projects that work together to create an application. The solution has the extension .sln. A COBOL project has the extension .cblproj and a C# project has the extension .csproj.

    Solution Explorer shows the solution that is open and the projects therein.

    You can use the project's properties pages to display a list of the files in your solution with file details like output file type and location, COBOL dialect, and the number of errors generated by the file. To display the properties, click Project > Name Properties.

  • COBOL editor

    The COBOL editor provides help such as column cut and paste, and background syntax checking, which underlines errors with red wavy lines (also known as "squigglies"), which you can then hover over to display details of the syntax error.

    When you are editing, you can insert code snippets and navigate forward and backward quickly, and the Find All References option enables you to search for references of any COBOL data items, section and paragraph names in the solution.

    You can customize the editor to display line numbers, adjust colorization, tabs, and margins, from the Text Editor > Micro Focus COBOL > Advanced page in Tools > Options.

    When developing code, the editor provides IntelliSense that helps you write syntactically correct code and, in managed code, helps when you need to type more complicated constructs, such as the code to override the members that a class inherits from a base class or the code for implementing an interface.

    The Light Bulbs feature for implementing an interface helps complete incomplete interface declarations. A Light Bulbs appears at the beginning of the declaration: click it and choose the missing member(s) of the inheriting interface.

    When you encounter a COPY statement, or data item that is defined in a copybook, if you put your cursor on that code and press F12 the appropriate copybook opens in the editor at the relevant line. You can also do this by right-clicking the line and selecting Show copybook name.

  • Setting Compiler directives

    Many Compiler directives are set automatically by certain configuration options in the IDE, but you can explicitly add directives to your project. Right-click on the project in Solution Explorer and choose Properties. In 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 relative path.

  • Build Tools, the Output Pane and the Error List

    Build configurations define how to build a project or solution. There are default configurations of Debug and Release for each project type, and you can create your own specific configurations.

    The Output window shows the results of your build together with errors. You can double-click an error and navigate directly to the appropriate line in the source code. You can do the same from the Error List.

  • Debugging

    When you debug the application, you can step through the code, hover over a data item to see its value, and watch data item values in a variety of ways. You can specify breakpoints on a range of conditions, such as when an expression is true or changes, or when a line is hit a specified number of times.

    In native code, you can set COBOL watchpoints on data items and watch for changes in the area of memory associated with the watchpoints. When the memory changes or a condition associated with the watchpoint has been met, the debugger breaks on the line that follows the line on which the data change occurred.

    Also in native code, you can use the Memory window to watch the contents of the memory that is associated with data items or expressions.