Editing Code

The Micro Focus COBOL extension offers editing support for COBOL (including native, native Object-Oriented COBOL, .NET COBOL and JVM COBOL) code.

You edit source code in Visual Studio Code by opening it either as individual files or as part of a folder. Visual Studio Code does not support projects out of the box.

To edit your sources:

  1. Open the folder that contains your sources inside Visual Studio Code.
  2. Open the file you want to edit.

    Visual Studio Code offers colorization of the code in the editor.

    For COBOL code, the editor applies the default source format and dialect from the Visual Studio Code settings. However, if a specific source format or dialect has been set for the active document, Visual Studio Code applies those instead.

Writing efficiently with COBOL code snippets

Insert the code constructs for elements of the COBOL language, for example for classes, methods and delegates in .NET COBOL.

To insert a code snippet:

  1. Display a drop-down list of suggested code snippets in your code in one of the following ways:
    • Start typing in the Visual Studio Code editor in your COBOL file.
    • Alternatively, press CTRL+Space to open the drop-down list with the available code snippets.

    The snippets in the drop-down list are prefixed by a square icon.

  2. Use the arrow buttons to select the snippet you want to use from the list, then press Enter to insert the code.

Commenting out lines of code in COBOL files

  1. Open a COBOL file in the editor and either click on a line you want to comment, or select a few lines to comment out.
  2. Click View > Command Palette, and select Add COBOL line comment or Toggle COBOL line comment.
    • For fixed and variable source format code, this inserts an * in column 7 of the lines you have selected which comments out the code in areas A and AB.
    • For free source format code, this inserts *> at the start of the code on the selected lines.

To remove the line comments, use the Remove COBOL line comment command from the Command Palette.

File encodings

Visual Studio Code uses UTF8 by default when opening or creating files. To change the encoding used for COBOL files you can add the required encoding to the settings.json file as follows:

{
    "[cobol]": {
        "files.encoding": "utf8bom"
    }
}

When utf8bom is set, the Compiler will recognise the file encoding as UTF8.