Summary -

In this topic, we described about the below sections -

  • A comment is a group of characters used to provide the notes about the code or the information about tasks coded in the program.
  • A comment can be created with a combination of any allowed computer characters. For example - A-Z, a-z, 0-9, and all computer-supported characters.
  • Comments do not affect the execution of the program.
  • The comment-entry is the sentence entered in the place of the comment.

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.
  • The entries with optional paragraphs are comment entries.
  • The optional paragraphs are - AUTHOR, INSTALLATION, DATE-WRITTEN, DATE-COMPILED, and SECURITY.
  • The usage of comment entries are -
         ----+----1----+----2----+----3----+----4----+----5
    [Optional]	AUTHOR. NameOfProgrammer.
    [Optional]	INSTALLATION. Development-center.
    [Optional]	DATE-WRITTEN. mm/dd/yy.
    [Optional]	DATE-COMPILED. mm/dd/yy. HH:MM:SS.
    [Optional]	SECURITY. Program-type.
    
  • The comment-entry can be written in more than one line. However, it should always begin or continue 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.
  • The continuation character (-) is not required while writing comments in 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 (*) in the line's indicator area (column 7).
    For example -
    ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
                                                                            
          * FULL LINE COMMENT WITH * IN COLUMN-7.
                                                                            
           DATA DIVISION.                                                   
    
  • A comment line can code anywhere in the program.

Inline comments (any division) -

  • An inline comment is identified by a floating comment indicator (*>) preceded by one or more character-strings.
  • Inline comments can write on any line in the program-text area (8-72 columns).

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.                           
                                                                        
       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