Rename Refactoring

Visual COBOL enables you to rename variables, section and paragraph names in native COBOL as well as of identifiers in managed COBOL.

To rename:

  1. Right-click the item you want to rename in the editor, and click Rename.

    This highlights all occurrences of the variable in the editor and opens the Rename widget.

  2. Specify whether to rename only in the current project or across the entire solution - set the Search Scope as follows:
    • Current COBOL program
    • Current project only
    • All COBOL projects in solution
  3. Check Preview to be able to review and approve the suggested changes.
  4. Start typing a new name over one instance of the variable you want to rename.
  5. Click Apply in the Rename widget.

    If you checked Preview, this now shows a list of all files and occurrences of the variable that will be renamed.

  6. Click Apply again.

After applying any of the changes, you can click Edit > Undo or Edit > Global Undo *Global Rename to revert them.

To perform an inline rename:

  1. Start typing over the variable that you want to rename.
  2. This displays a lightbulb in the margin on the line where you are making a change.
  3. Click the lightbulb to display the available quick actions.
  4. Select one of the available actions to rename either in the current project or across the entire solution.

To rename class files in managed projects from Solution Explorer:

  1. Right-click a class file in your project in Solution Explorer and click Rename.
  2. Specify a new filename and press Enter.

    This opens the Suggested Rename dialog box offering to also rename all instances of the class name you are changing in the code.

  3. Specify whether you want to rename any references to the class in the current project only or in the entire solution, and click Yes.
    Tip: Micro Focus recommends that you always rename the identifier across the entire solution to help avoid introducing errors.

Renaming to a COBOL reserved word

You can specify a new name which is also a COBOL reserved word. Visual COBOL inserts such names in the code and escapes them with a # as a prefix. For example, if you want to rename your variable or identifier with the word name, renaming replaces the old name with #name.

An escape character is not needed if the identifier is referenced in the code through the :: notation. The following example shows a class in which two variables have been given new names that are COBOL reserved words. The code references the variables directly and with :::

       class-id SomeClass.
       working-storage section.
       01 #name   binary-long.
       01 #accept binary-long.
       01 var-a   binary-long.

       method-id SomeMethod.
           set #name to 0
           set self::accept to 0
           set var-a to 0
           set self::var-a to 0

           declare x as type SomeClass.
           set x::name to 0
       end method.
       end class.

When you are exposing your COBOL applications to other languages, the escape character, #, is not taken into account. For example, from C# you can access the two variables as name and accept.

Restrictions

The following restrictions apply to rename refactoring:

  • When renaming variables in a copybook, the copybook must be shown inline in the referencing program in the expanded copybook view. It is not possible to rename in copybooks opened as stand-alone files in the editor.
  • It is not possible to rename identifiers in copybooks referenced using a COPY... REPLACING statement.
  • It is not possible to rename typedef members.
  • It is not possible to rename identifiers in any resources that are outside the current solution.

The following restrictions apply to native COBOL only:

  • Renaming only works in the current program.
  • It is not possible to rename a program or an entry-point.
  • It is not possible to rename copybooks from the editor. You can rename copybooks from Solution Explorer. This, however, does not change any of the references to the copybooks in the code.

The following restrictions apply to managed COBOL only:

  • It is only possible to rename identifiers that are defined in the COBOL projects within the current solution.
  • It is not possible to rename namespaces.
  • It is not possible to rename a COBOL type from another .NET language and vice versa - it is not possible to rename .NET types from a COBOL project.