Formatting COBOL code

Visual COBOL offers commands and preferences for formatting COBOL code. Formatting means applying consistent indentation and new lines, removing any extra white spaces, aligning keywords and improving the source's readability. You can format entire programs, files or a selection of code in the editor. You can also mark portions of code that are not to be formatted.

Visual COBOL offers configurable settings for formatting a number of the elements of the COBOL language in the Data, Identification and Procedure Divisions. The default settings are the ones most likely to be commonly used for COBOL code but you are free to change them as necessary in the Visual Studio options.

If you have a program that includes sections of code that you do not want to format you can use one of the following options to ensure that only the desired sections are formatted:

  • Comments - comments are not affected by formatting. In the example below the code after the comment will not be formatted:
          *> 01 var1 pic x(30).
  • cblformat - you can exclude sections of code within a program from being formatted, if you surround them with a *> cblformat statement. To indicate the start of the code area that must not be formatted, enter the following:
          *> cblformat off
          ... code below this line will not be formatted...

    To indicate the end of the area which must not be formatted, enter the following:

          *> cblformat on
          ... code below this line will be formatted...

See Known Issues for restrictions in formatting.