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.

Automatically close parentheses and quoted strings

By default, the editor automatically-closes parenthesis and quotes when they are opened and are immediately followed by whitespace. In addition, smart overtyping of brackets and string delimiters enables you to type the opening quote or bracket and the cursor will move past the automatically-inserted closing quote or parenthesis. The smart deletion option enables simultaneous deletion of opening/closing quotes or parentheses. To configure the automatically close preferences, click Windows > Preferences > Micro Focus > COBOL > Editor > Typing. In the Automatically close group, choose your preference.

Block selection

Allows you to select specific blocks of text from your code. The selection mode is toggled using the The Block text selection icon 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 mining

Code minings are additional content shown in the editor for native and procedural JVM COBOL code, to give extra context to certain code elements. The following code elements can be mined:
  • The number of references to a section or a paragraph. An indicator, showing the number of times that a section or a paragraph is called, is displayed above the section/paragraph title within the code. Select the link to show a list of references in the Search view, where you can use the matches shown to jump to the call within the code.

    Code mining section references

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 JVM 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.

Copybook structure example

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 Program Symbols (.IDY) page in Window > Preferences > Micro Focus > COBOL > Standalone Files enables you to specify the location of the program's .idy file, which is to be used when debugging. The locations (possibly represented by environment variables) on this page are searched in order until a correctly named file is located. (The '.' entry indicates the location in which the source program is opened.)

The Copybook Paths page works in a similar way to the Program Symbols (.IDY) page. It is used to locate copybook files when debugging a standalone file. If copybook files do not reside in the location in which the source program is opened, add the correct location to the list on this page, and move it to the top of the list. This location can be a local one or one on a remote server if you have a remote host connection configured: use the setting displayed above the list to specify the host to which the path relates.

When simply running the program or application, set the COPYPATH Compiler directive on the Compile page in Window > Preferences > Micro Focus > COBOL > Standalone Files as COPYPATH(<location1>;<location2>;...) if the location of any copybooks differ to the location of the standalone source file(s). You will 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 when a program is first opened in the editor. You can apply preferences to such elements as the File section, Linkage section and so on. Whilst a section is collapsed, you can hover over it to show its contents. You can also elect to expand all 01 group level items, or load the program with the groups collapsed. You can configure all folding preferences from Window > Preferences > Micro Focus > COBOL > Editor > Folding.

Format COBOL code

Click Source and either Format or Format Program to apply consistent formatting and indentation to your sources. The preferences about COBOL formatting are in: Window > Preferences > Micro Focus > COBOL > Code Style > Formatter.

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; for example, showing all references of a particular item throughout a project or entire workspace; these results are displayed in the Search view.

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.