AMC Tech Tips: Creating COBOL code snippets

by Micro Focus Employee in Application Modernization & Connectivity

Introduction: Code Snippets

The Micro Focus application development products from our Application Modernization and Connectivity business offer a range of capabilities for rapid application development. One example is our Code Snippets. This blog outlines how to use and create COBOL code snippets in Visual Studio, one of the two popular IDEs supported by Micro Focus Visual COBOL and Enterprise Developer.

A code snippet is a chunk of code developers can easily insert into their programs with a couple of keystrokes. This makes coding quicker and less prone to error.

There are already pre-defined COBOL code snippets available in Visual COBOL and Enterprise Developer which cover the most common COBOL code constructs. Developers can also create their own snippets which is useful if they have a favourite code pattern they regularly use or if they have coding standards to conform to. And – once they’ve created their own snippets they can share them with the rest of their team.

Getting Started with Code Snippets

For the application developer, code snippets are really easy to use. There are several ways to insert a code snippet from the COBOL editor.

- the editor context menu (right-click) or shortcut (Ctrl K, Ctrl X)
- the Intellisense list (Ctrl Space)
- the menu bar, choose Edit > IntelliSense

The developer has 2 options:
- Insert Snippet – these snippets are inserted at the cursor location
- Surround With – these snippets incorporate the code block selected in the editor in the snippet
This example shows inserting a “Surround With” snippet, the new $region code snippet and auto-formatting.

Creating Code Snippets

Developers can create their own code snippets and import them into Visual Studio via the Code Snippets Manager, which is on the Tools menu.

The snippet file is an XML file which the developer can create, fill in the appropriate XML elements and add their code. There is a standard Visual Studio Walkthrough available online, which gives step-by-step instructions on how to do this.

Coming Up

We’re currently working on some enhancements in this area which will be available in the next product release. Let’s take a look…

1) Using the COBOL margin

Developers can now write snippet text which will display in the COBOL margin. We added this enhancement following a request from a customer whose coding standards dictated that they insert a standard comment block before each section. This means all developers can use the same snippet which includes their standard section header, so it will be quicker to insert code and they have guaranteed consistency.

The following example shows a code snippet I’ve created being inserted. The snippet is a new section with a header. The section name and description are replaceable parameters.

2) Auto-formatting

We’ve also added functionality to auto-format your inserted snippet code block. This features takes advantage of the new COBOL Formatting functionality which is a major new feature in the next product release.

3) New Snippets

And the new snippets are
$if … $end                             for conditional compilation
$region … $end-region       sets a region in the editor which can be collapsed
*cblformat                             sets a code block for the formatter to ignore


Snippets are just one facility available to developers in our application development technologies, part of our Application Modernization & Connectivity solution. For more information, please download the trial product for distributed Micro Focus Visual COBOL or Enterprise Developer for mainframe environments.


Visual COBOL
Enterprise Developer