Summary -

In this topic, we described about the below sections -

A comment is a character-string with a combination of any characters of the computer. It does not affect the execution of the program.

The comment-entry can be any combination of characters allowed on the computer. For example - A-Z, a-z, 0-9, and all computer-supported characters.

Below are the three forms of comments –

  • IDENTIFICATION DIVISION Comment entry
  • Comment line (any division)
  • Inline comments (any division)

IDENTIFICATION DIVISION Comment entry -

IDENTIFICATION DIVISION has some optional paragraphs that can omit. The optional entries are - AUTHOR, INSTALLATION, DATE-WRITTEN, DATE-COMPILED, and SECURITY. The entries of optional entries are comment entries.

The usage of comment entries are -

 AUTHOR. comment-entry.
 INSTALLATION. comment-entry.
 DATE-WRITTEN. comment-entry.
 DATE-COMPILED. comment-entry.
 SECURITY. comment-entry.

The comment-entry is written in one or more lines in Area B.
For example -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       AUTHOR. THE PROGRAM WRITTEN BY MAINFRAMESTECHHELP FOR            
               EXPLAINING ABOUT COMMENTS IN DETAIL.                     

Comment-entries are only for documentation, and they do not affect the meaning of the program.

A hyphen(-) in the indicator area (column 7) is not allowed in comment-entries. i.e., the continuation character (-) is not required while writing comments that are split more than one line.
For example -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       AUTHOR. THE PROGRAM WRITTEN BY MAINFRAMESTECHHELP FOR            
      -        EXPLAINING ABOUT COMMENTS IN DETAIL.                     

Comment line (any division) -

A comment line is any line with an asterisk (*) or slash (/) in the indicator area (column 7) of the line.
For example -

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

Inline comments (any division) -

An inline comment is identified by a floating comment indicator (*>) preceded by one or more character-strings in the program-text area. Inline comments can be written on any line of a compilation group.

For example -

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

Practical Example -

Scenario - The below example describes how the comments were added in COBOL programming.

Code -

Comments program Code
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID. COMMENTS.                                            
                                                                        
       AUTHOR. THE PROGRAM WRITTEN BY MAINFRAMESTECHHELP FOR            
               EXPLAINING ABOUT COMMENTS IN DETAIL.                     
       INSTALLATION. 01-JAN-2000.                                       
       DATE-WRITTEN. 11-MAY-2021.                                       
       DATE-COMPILED. 11-MAY-2021.                                      
       SECURITY. NORMAL.                                                
                                                                        
       DATA DIVISION.                                                   
       WORKING-STORAGE SECTION.                                         
                                                                        
      * FULL LINE COMMENT WITH * IN COLUMN-7.                           
      / FULL LINE COMMENT WITH / IN COLUMN-7.                           
                                                                        
       01 WS-VAR        PIC X(12).                                      
                                                                        
       PROCEDURE DIVISION.                                              
                                                                        
      * FULL LINE COMMENT IN THE PROCEDURE DIVISION                     
           DISPLAY "SPECIFYING COMMENTS IN THE PROGRAM".                
                                                                        
           STOP RUN.                                                    
**************************** Bottom of Data ****************************

Output -

Comments program Output

Explaining Example -

In the above example, different types of comments are coded to explain how those are used in the COBOL program. The various comments are self-explanatory in the program.