Writing Code Efficiently in the COBOL Editor

The COBOL editor is the default editor for editing files with extensions associated with COBOL. It offers a variety of features to help you write code quickly and efficiently.

AutoCorrect

Enables you to specify a list of words and their commonly mistyped versions. When you type the misspelled version in the editor, AutoCorrect automatically corrects them. By default, AutoCorrect is enabled and contains a predefined list of commonly misspelled words. You can edit and add to the predefined list of words and their misspelled versions from Window > Preferences > Micro Focus > COBOL > Editor > AutoCorrect. You can also export or import lists allowing you to apply bulk edits and share with colleagues. To disable AutoCorrect, uncheck Enable AutoCorrect. See Configuring AutoCorrect for more information.

Note: AutoCorrect does not correct text in comments or strings.

Block selection

Allows you to select specific blocks of text from your code. The selection mode is toggled using the button from the toolbar or shortcut key Alt+Shift+A.

Call Hierarchy view

You can open the Call Hierarchy view for JVM COBOL programs. To open the view, right-click in the editor, and then click Open Call Hierarchy. Alternatively, press Ctrl+Alt+H. The view enables you to see the callers and callees hierarchy for the selected JVM COBOL member.

COBOL Copy view

COBOL Copy view allows inline expansion of copybooks so you are able to see your code and copybooks in a single view. While some of the features available in the COBOL editor, including finding references and locating definitions, are available in COBOL Copy view, it is a read-only source viewer and you cannot use it to edit code. You also use the debugging facilities from this view.

You can open COBOL Copy view when working in the COBOL Editor view by pressing F4. Pressing F4 again switches you back to the COBOL Editor. You can open COBOL Copy view when editing either a program or a copybook; if you open it when editing a copybook, it shows the content of the copybook inside the program you have chosen to be its default context. You choose this context by right-clicking the copybook in COBOL Explorer and selecting Open In Context.

Code templates

Provides you a snippet of code for the statement you are typing. Press Ctrl+Space to see content assist proposals that include the available code templates. Select and insert a code snippet and it gives you an outline of the syntax for you to fill in the blanks. You can add more templates from the IDE preferences - Window > Preferences > Micro Focus > COBOL > Editor > Templates.

Content Assist

Content assist provides writing assistance that enables you to write syntactically correct code quickly. Content assists provides proposal lists that include procedural and managed COBOL keywords and data items as well as Java types. You can configure the preferences for content assist in COBOL from Window > Preferences > Micro Focus > COBOL > Editor > Content Assist.

For full description about how content assist works, see Editing Assistance in the COBOL Editor.

Copybook Dependency view

Use the Copybook Dependency view to show where in the source file's structure the COPY statements appear, and which copybooks they reference.

Click a copybook reference in the Copybook Dependency view to locate the associated COPY statement at the appropriate line in the source code.

Editing standalone files

This only applies to native COBOL. The recommended way to work with Enterprise Developer is to include all source files in a project because this enables full support for the IDE editing, compiling and debugging features. There is limited support in the IDE for standalone files - such that are not part of a project.

To open a file in the IDE without a project, click File > Open File.

The IDE searches the Program Symbols (.IDY) page in Window > Preferences > Micro Focus > COBOL > Standalone Files

Edit the file in the usual way. Note, however, that background syntax checking is not available so no errors are reported as you type. You need to recompile in order for the IDE to check your code and report any issues.

When starting the IDE from the command line, also set the COBCPY environment variable to point to the folders where the IDE should search for copybooks.

To specify the locations of any copybooks used by the standalone file when the copybooks are not in the same location, set the COPYPATH Compiler directive in the IDE on the Compile page in Window > Preferences > Micro Focus > COBOL > Standalone Files as COPYPATH(<location1>;<location2>;...). You then need to recompile the file.

Check Known Errors and Restrictions for information about the level of support for standalone files.

Extracting COBOL code to a copybook

You can extract highlighted lines to a copybook by right-click in the editor, and clicking Refactor > Extract to Copybook. See Extracting COBOL code to a copybook for more information.

Folding

Hides or shows sections of the program, such as the File section, Linkage section and so on. You can hover over a collapsed section to show it expanded. You can configure your folding preferences from Window > Preferences > Micro Focus > COBOL > Editor > Folding.

Go To Definition

You can use this feature in both native and JVM COBOL projects to find where an item is defined. Right-click an item and click Go To Definition. Alternatively, press F3. The cursor moves to the line of code where the item is defined. The item is also highlighted in the Outline view. You can find the definition for fields, events, types, methods and properties.

You can also navigate to an item that has been declared in Java from a JVM COBOL source. This applies to fields, types and methods.

Go to Matching Block/Bracket

You can use this feature to locate the bracket that matches the one at your current cursor position. To move the cursor to the matching bracket, right-click in the COBOL editor, and then click Go to Matching Block/Bracket. Alternatively, press Ctrl+Shift+P.

Mark occurrences

Marks the occurrences of the selected element (data item or section) in the current file. You can switch this feature on/off when a COBOL Editor/Copy view is opened by pressing Alt+Shift+O.

Open Type

Brings up the Open Type dialog to open a type in the editor. The Open Type selection dialog shows all types existing in the workspace. It's accessible from Navigate > Open Type, or by pressing Ctrl+Shift+T.

Enter a type name, or prefix, or the first characters of the type you want to select. It is displayed in the list. When you select it and double click it you see it displayed in the COBOL editor.

Open Type in Hierarchy

Brings up the Open Type dialog to open a type in the editor and the Type Hierarchy view. The Open Type selection dialog shows all types that exist in the workspace. It's accessible from Navigate > Open Type in Hierarchy or by pressing Ctrl+Shift+H. This option lets you see where a selected type stands in the type hierarchy.

Outline view

Shows the structure of the program you are editing. This is useful for navigating large programs, for example by clicking on a Data Division item, a COBOL section or a paragraph to go to it in the code. You can also right-click an item and choose from a range of relevant options.

The Outline view shows only items from the current editor - if the program is opened in the COBOL editor only items from the current program are visible and not from its copybooks. If the program is opened in the Copy view all items are visible in the editor (the Copy view is a read-only editor) and in the outline.

Program Outline view

Similar to Outline view. When you click a data item declaration in the Program Outline view and this opens the relevant copybook and goes to the relevant line. The Program Outline view always shows the whole program structure, including the elements that are in other files.

Quick Outline view

Similar to Outline view. To start it press Ctrl+O or select Navigate > Quick Outline for an in-place outline of the current source file. When you type while Quick Outline view is displayed you filter the list of displayed elements for easier navigation. Pressing Ctrl+O while Quick Outline view is active displays the same information as in Program Outline.

Read-Only background colorization

When you open a file in read-only mode (in the editor or if you open the COBOL Copy View), the background is colored in light yellow to remind you that you cannot use it for editing files.

Light yellow is the default color but you can change it according your personal preference. To do so, open Window > Preferences > Micro Focus > COBOL > Editor, select a background color from the palette in the Read-Only mode section of the page. Click Apply and then OK.

References

You can use this feature in both native and JVM COBOL projects to find references to an item.

In a native COBOL project, place the cursor on the item, right-click, and select References. Alternatively, press Ctrl+Shift+G. The Search tab displays all the references found in the search. You can explore the results returned, double-clicking on the item moves the cursor to that position in the relevant file.

In a JVM COBOL project you can also specify the scope of the search. Place the cursor on the item being referenced, right-click, and select References. Choose the scope of the search; Workspace, Project or Hierarchy. The Search tab displays all the references found in the scope of the search, with default grouping by package.
Note: The Hierarchy relates to the type or class.

Remove Trailing Whitespace

By default, trailing whitespace is not removed when you save a COBOL file. You can remove trailing whitespace after column 80 or remove all trailing whitespace when you save your file. To configure your preferences to remove trailing whitespace, click Window > Preferences > Micro Focus > COBOL > Editor. In the Remove trailing whitespace group, click your preference, and then click Remove trailing whitespace on save.

To remove all trailing whitespace, click Source > Remove Trailing Whitespace. Alternatively, right-click in the COBOL editor, and then click Source > Remove Trailing Whitespace.

Rename refactoring

Rename refactoring enables you to rename all or selected occurrences of a variable, a paragraph or a section name or an identifier in your code. Right-click the name to change in the editor and click Refactor > Rename. To configure the IDE preferences for rename refactoring, click Window > Preferences > Micro Focus > COBOL > Editor and either check or uncheck Rename in editor without dialog.

Syntax Coloring

Syntax coloring enables you to choose from a list of predefined syntax coloring schemes. You can customize a coloring scheme by specifying your preferred color and style for a particular code element, such as Compiler directives, reserved words, data items and so on.

You can configure your syntax coloring preferences from Window > Preferences > Micro Focus > COBOL > Editor > Syntax Coloring. By default, inactive code is colored the same as compiler directive elements. Inactive code is defined as code within conditional blocks that can never evaluate to true. An example of this is provided in the Preview pane:
      $if 1 = 0
           MOVE 1 TO var-1
      $else
           MOVE 2 TO var-1
      $end
If you want to disable colorization of inactive code, uncheck Colorize inactive code as directive. See Configuring Syntax Coloring for more information.

Tasks

You can manage tasks by adding the default TODO or FIXME tags in the COBOL code comments. Eclipse visualizes these tags in the Task tab. Any text that follows the TODO or FIXME tags appears in the task description. To view the Task tab, click Window > Show View > Tasks or Windows > Show View > Other, expand General, click Tasks, then click OK. Double-clicking on the line in the Task tab takes you to the highlighted line in the editor.

Both TODO and FIXME tag lines are marked on the left margin of the editor with a clipboard icon (). Rows in the Task tab that are tagged TODO are high priority tasks and are highlighted with an exclamation point ().

You can customize the tags from Window > Preferences > Micro Focus > COBOL > Editor > Task Tags. You can add, remove or edit tags, specifying their priority as high, normal or low.

Toggle Comments

Enables you to toggle single or multiple lines between a commented and uncommented state. Pressing Ctrl+/ toggles the highlighted lines between states. Commenting a line applies a leading asterisk, uncommenting removes the leading asterisk.

Type Hierarchy view

You can open the Type Hierarchy view for JVM COBOL programs. To open the view, right-click in the editor, and then click Open Type Hierarchy. Alternatively, press Alt+Shift+H. The view enables you to see classes, subclasses and members and their supertypes, or their subtypes.