Debugging the Current File

Important:
  • This functionality requires a licensed version of a Rocket Visual COBOL or Rocket Enterprise Developer product on the same machine. See Installation for details.
  • This is not supported in JVM COBOL code. Native COBOL and .NET COBOL code is supported.

Visual Studio Code displays (Debug COBOL Program)) in the top right corner of the editor task bar. This button enables you to start running or debugging the program which is currently opened in the editor as part of a folder as follows:

Before debugging starts, Visual Studio Code compiles the file, either by running the compiler using the default directives specified in the extension settings, or by using a task specified in the tasks.json file.

When no tasks.json file is available

If your workspace does not include a tasks.json file, Visual Studio Code automatically compiles the current file with the directives specified in the Micro Focus COBOL: Default Directives setting of the extension, before it starts debugging.

When tasks.json is available

If tasks.json is present, it can include a task with the suffix (compileCurrentFile) to be able to compile the active file. You need to specify any Compiler directives in the args parameter. For example:

        {
            "label": "COBOL: (compileCurrentFile)",
            "type": "COBOL-shell",
            "windows": {
                "command": "cobol.exe",
                "args": [
                    { "value": "${file}", "quoting": "escape"},
                    { "value": "anim", "quoting": "strong"},
                    { "value": "nognt", "quoting": "strong"},
                    { "value": "errformat(3)", "quoting": "strong"},
                    { "value": ";", "quoting": "strong"} 
                ]
            },
            "linux": {
                "command": "cob",
                "args": [
                    { "value": "${file}", "quoting": "escape"},
                    { "value": "-C", "quoting": "strong"},
                    { "value": "errformat(3)", "quoting": "strong"},
                ]
            },
            "problemMatcher": "$COBOLErrFormat3",
            "group": "build"
        }

In addition, if you use an MSBuild project file, you can create a build task containing compileCurrentFile that uses the MSBuild project file. This task compiles the active file in the editor. For example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "COBOL-MSBuild",
            "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\MSBuild\\Current\\Bin\\MSBuild.exe",
            "buildTarget": "${workspacefolder}/test.cblproj",
            "problemMatcher": [
                "$COBOLMSBuild"
            ],
            "group": "build",
            "label": "COBOL: MSBuild (compileCurrentFile)",
            "args": [
                "/t:CompileSelected",
                "/p:CompileItems=${fileBasename}"
            ]
        }
    ]
}