Summary -

In this topic, we described about the Comment Line with detailed example.

A comment line is any line with the below indicators at indicator area (column 7) of the line -

  • an asterisk (*)
  • slash (/)

A comment line also having a floating comment indicator (*>) as the first character-string in the program text area (either in Area A or Area B).

For example -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- 
       01 WS-VAR        PIC X(12).    *> INLINE COMMENT                 
	   
	    *> INLINE COMMENT

A comment line can consist of any combination of characters of the computer.

For example -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
                                                                        
      * daakfa;kfaf *&%$#2)() - Valid Comment                          
                                                                        
       DATA DIVISION.                                                   

Comment lines can be placed anywhere in a program.

For example -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      * THIS IS COMMENT1                        
                                                                        
       DATA DIVISION.  
       WORKING-STORAGE SECTION.

      * THIS IS COMMENT2 

       PROCEDURE DIVISION.

      * THIS IS COMMENT3 	   

Each comment lines must begin with an asterisk (*) or a slash (/) in the indicator area, or with a floating comment indicator (*>).

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.                                                   
       WORKING-STORAGE SECTION.
	   
       01 WS-VAR        PIC X(12).    *> INLINE COMMENT  

The compiler treats a comment line as documentation and does not check it syntactically.

Practical Example -

Scenario - Below example describes how the comments 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 ****************************

Explaining Example -

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