Comments


What is a Comment?


Comments are used to insert descriptive notes within the program. They are ignored by the COBOL compiler, meaning they have no impact on the program execution.

These comments are for the programmer's benefit. They are important for making the code understandable, allowing programmers to define the purpose, logic, or any special considerations regarding the code.

Comment Types


The comments are three types based on their usage and those are -

  • IDENTIFICATION DIVISION Comments.
  • Full line comments (any division).
  • Inline comments (any division).

IDENTIFICATION DIVISION Comments -


IDENTIFICATION DIVISION has optional paragraphs like - AUTHOR, INSTALLATION, DATE-WRITTEN, DATE-COMPILED, and SECURITY. The entries with optional paragraphs are comments.

The usage of comments in IDENTIFICATION DIVISION (All entries after keywords are comments) are -

----+----1----+----2----+----3----+----4----+----5
       AUTHOR. NameOfProgrammer.
       INSTALLATION. Development-center.
       DATE-WRITTEN. mm/dd/yy.
       DATE-COMPILED. mm/dd/yy HH:MM:SS.
       SECURITY. Program-type.

The comments can written in more than one line. However, it should always begin or continue in Area-B. The continuation character (-) is not required while writing comments in IDENTIFICATION DIVISION.

Full line comments (Comment Line)


Any line starting with an asterisk (*) in column 7 (indicator area) is considered as a full-line comment. Comments can be coded in any division. For example -

----+----1----+----2----+----3----+----4----+----5
      * FULL LINE COMMENT WITH * IN COLUMN-7.
       DATA DIVISION.

Inline comments (Floating Comment)


Comments coded in the middle of any line in between 8-72 columns. An inline comment should start with a floating comment indicator (*>).

For example -

----+----1----+----2----+----3----+----4----+----5
       01 WS-VAR        PIC X(12).  *> INLINE COMMENT   
Note! Inline comments are introduced by COBOL V5.1. Previous versions (before COBOL V5.1) do not support inline comments.

Practical Example -


Scenario - Example to describe how the comments were added in COBOL programming.

Code -

Comments program Code