Previous Topic Next topic Print topic


Using IntelliSense to Write COBOL Code Efficiently

IntelliSense is the collective term for a number of Visual Studio features - List Members, Parameter Info, Quick Info, and Complete Word.

In Visual COBOL, IntelliSense provides writing assistance for both native and managed COBOL.

IntelliSense support for COBOL is configurable. You can change your preferences for IntelliSense from within the IDE in the Tools > Options > Text Editor > Micro Focus COBOL > IntelliSense section and specify options such as the case of the inserted words, whether to show the completion lists or insert single suggestions automatically, or whether suggestions should be added in overwrite mode or as insertions. See Configuring IntelliSense for COBOL for details.

IntelliSense in native COBOL

The following describes the writing assistance that IntelliSense provides in native COBOL.

IntelliSense provides editing features to help you write syntactically correct code. It enables you to complete words quickly and to look up available elements.

IntelliSense only offers assistance for the data items that are in scope based on the current position of the cursor.

Features include:

Completion lists
By default, IntelliSense displays a completion list (a pop-up with suggestions) immediately after you start typing. To see the completion list if it does not pop up automatically, press Ctrl+Space to show it. You can do this if you have not started typing yet or if the automatic display of completion lists is disabled.

The following list summarizes how completion lists work:

  • Suggestions are context sensitive - the completion lists only include suggestions that are relevant to the position of the cursor in the code and the type of project.

    For example, completion lists only show COBOL verbs in the Procedure Division section and not in the Working-Storage section, and the verbs are only relevant to native code.

  • Suggestions start with the letters you entered with the best match highlighted in the IntelliSense pop-up. The list auto-updates as you type.
  • Suggestions may include COBOL verbs, clauses and words (keyword), copybooks (Copybook) in the completion lists for the COPY statement, code snippets (code snippet), variables (variable), 78 level items (78 level item), or sections and paragraphs (section) .
  • Completion lists include the COPY statement.
  • Completion lists are available both in a program and in copybooks in the program that are shown in the expanded copybook view.
Completing statements
IntelliSense provides intelligent assistance for completing COBOL statements. When you are entering a statement, IntelliSense shows suggestions for the relevant clauses and the identifiers that you can use to complete the statement. The suggestions take into account the syntax rules that apply to the statement in the selected COBOL dialect and the identifiers in scope.

To complete a statement:

  1. Type the initial verb of a COBOL statement and press Space.

    By default, IntelliSense automatically pops up a completion list that includes the clauses and identifiers that you can use.

  2. Choose a suggestion from the list and press either Enter, Tab or Space to insert it in the code.
  3. Press Space to see further suggestions.
Completing COPY statements
After entering a COPY statement and pressing Space, the first completion list that appears includes any copybooks.

You need to choose a copybook from the list for IntelliSense to insert after the COPY statement. After the copybook is inserted, the completion list that appears gives you the option of terminating the statement with a period (.) or continuing it with one of the clauses IN, OF, REPLACING or SUPPRESS.

By default, suggestions for COPY statements only include the copybooks that are part of the current project or are found in the directories specified on the Copybooks tab of the project's properties, but you can change this so that the suggestions also include system copybooks. System copybooks are ones that are not included in the project but are defined using the COBCPY variable. You can change your preferences from the Tools > Options > Text Editor > Micro Focus COBOL > IntelliSense section.

Automatic completion
If a completion list includes a single suggestion, pressing Ctrl+space automatically inserts that suggestion in the code. You can turn off this option from the change the behavior from the IDE preferences (go to the Tools > Options > Text Editor > Micro Focus COBOL > IntelliSense section).
Qualifying non-unique names
If variable names are not unique, IntelliSense qualifies the names.

Consider the example of a program that defines two group items - StudentRecord and TeacherRecord. Both group items include a number of PIC X elementary items with the same names - for example, FirstName, Surname, Phone and so on. In such a case, IntelliSense qualifies the elementary items as follows:

  1. In the Procedure Division, type move and press Space.

    The completion list that pops-up includes COBOL keywords, the group items defined in your program, and the elementary items that are present in both group items.

  2. Select one of the elementary items, for example Surname of StudentRecord, and insert it in your code.
  3. Press Space which offers to insert the TO clause.

    IntelliSense has helped you specify the exact elementary item to use in your code:

    move Surname of StudentRecord to...

IntelliSense in .NET managed COBOL

Note: The following applies to .NET managed COBOL only.

In managed .NET COBOL, IntelliSense shows suggestions that include any methods, fields, properties, types and so on that are available when you declare items or type an object name followed by a double colon or an opening bracket in the Procedure Division.

You can choose an item from the list to complete the code rather than typing it yourself.

The following are examples of where IntelliSense pops up:

  • Type Listings - When you start declaring a type, such as 01 my-string type , IntelliSense pops up a list of the namespaces and types available to your program, as soon as you enter the keyword type and press Space. These namespaces are obtained from each of the references you’ve added to your project. As you type a namespace, IntelliSense shows all the types within that namespace. For example, when you type:
    • 01 my-string type - all the available namespaces are listed.
    • 01 my-string type System. - all the types within the System namespace are listed.
    • 01 my-string type System.IO. - all the types within the System.IO namespace are listed.
  • Member Listings - when you invoke an object, IntelliSense pops up a list of methods, fields, properties and events that are available for that object. This happens when you use inline style of invoke statements (with the double colons ::), such as:
    invoke my-string::
Previous Topic Next topic Print topic