COBOL Notebooks

The Rocket COBOL extension supports COBOL notebooks, which have the file extension .cblnb. COBOL notebooks enable you to write executable COBOL code cells and Markdown cells in one document. Notebooks can compile either as native COBOL or as .NET COBOL code. You can configure certain settings to apply to individual cells or to the notebook as a whole.

Note: The COBOL Language Server features are available to use within COBOL notebooks if you have a licensed Visual COBOL or Enterprise Developer product release 9.0 or later installed on your machine

Create a COBOL notebook

In Visual Studio Code:

  1. Click File > New File.
  2. Select New COBOL Notebook from the drop-down list of file types. If it is not listed, type COBOL Notebook. Alternatively, in the EXPLORER view, click New File to create a new file. When naming the file, add the .cblnb extension and the editor will change accordingly to show the layout for a blank COBOL notebook.

Add code and Markdown cells

To add a cell to a COBOL notebook:

  1. Click Add Code Cell at the top-left of the notebook or in the center of the editor to add a COBOL code cell.
  2. Click Add Markdown Cell at the top-left of the notebook or in the center of the editor to add a Markdown cell.

The cell type is labelled in the bottom right corner of each cell. Markdown cells are blank, whereas code cells contain the four division lines characteristic of COBOL programs.

Add and remove Compiler directives

To add a compiler directive on a notebook level:

  1. In the toolbar of the notebook, click Add directive .
  2. Type your directive in the Add directive box at the top of the editor.
  3. After you have added a new directive, the option to remove that directive becomes visible. Click Select directive(s) to delete in the notebook toolbar to remove a directive from the drop-down list.
To add a compiler directive for a specific code cell inside a notebook:
  1. At the bottom of the code cell, click Add directive .
  2. Type your directive in the Add directive box at the top of the editor.
  3. After you have added a new directive, the option to remove that directive becomes visible. Click Select directive(s) to delete in the cell to remove a directive from the Select directive(s) to delete drop-down list.

Editing cells

  1. To edit a code cell, click anywhere in the cell, and begin typing.
  2. To edit a Markdown cell, double-click the cell or press enter.

If you have a licensed Visual COBOL or Enterprise Developer product release 9.0 or later, you will have access to the following COBOL Language Server functionality within notebooks:

  • Context-aware code completion
  • Hover pop-ups for data items
  • Collapsible regions in code cells
  • Error highlighting and reporting
  • Rename Symbol
  • Go to/Find/Peek definition and references

Run code cells

There are multiple ways to execute a cell. You have the option of running all cells within a notebook or running individual cells.

  1. Click Run to run to the left of a code cell to run it.
  2. Click Run All in the notebook toolbar to run all cells in a notebook.

The output of a code cell is shown directly below the cell.

COBOL notebooks can compile native and .NET COBOL. By default, the code type is set to native. To change to .NET COBOL:

  1. Click Cell type for run/debug at the bottom of an individual code cell, or click Cell type for run/debug in the notebook toolbar to set all code cells.

    This opens the drop-down list at the top of the editor.

  2. Select .NET code from the drop-down list.
  3. Run the cell(s).

Debug code cells

Note: You need to run a cell before you can debug it.

Debugging a COBOL notebook follows the same procedures as debugging a COBOL program in Visual Studio Code. For more information on debugging, see the Debugging section.

  1. Set any breakpoint(s) in a code cell by clicking to the left of the line number.
  2. Click Run > Debug Cell to the left of the cell to start debugging.

    This opens the Debug widget, which enables you to step into and through your code.

  3. In the Activity bar, click Run and Debug to open the Run and Debug view. The breakpoint information is visible in the Breakpoints panel.
  4. Step through the code using the Debug widget.

Other options

You can manipulate cells by clicking More Actions in the top right corner of a cell. Additional commands available for COBOL notebooks include:

  • More Actions > Edit Cell Command Line Arguments - add command line arguments in the Add Command Line Argument box. If you select the Edit Cell Command Line Arguments option again you can delete the previously specified argument(s).
  • More Actions > Edit Cell ACCEPT Values - provide a value for ACCEPT statements in the Add ACCEPT Value box. If you select the Edit Cell ACCEPT Values option again you can delete the previously specified value.
  • Provide Input to Cell - click Provide Input to Cell if you are required to enter a value when running a code cell, and type the value in the Provide Input box. Use this as an alternative to the Add ACCEPT Value option.

Restrictions

  • COPY statements do not resolve copybooks in a workspace.
  • The Debug Cell or Step into Cell commands might not work if the cell has not been run first. You can also manually select Notebook: COBOL Notebook Kernel from the Task Picker (Ctrl+Shift+P) to enable debugging.
  • Output is displayed in the debugger output window when debugging rather than in the notebook itself.