COBOL programming language has its own programming structure like other programming languages, and it applies to every program written in COBOL language.

The COBOL program structure is hierarchical (Top to Bottom structure).

COBOL program structure consists of Divisions, Sections, Paragraphs, Sentences, Statements, and Character strings.

A division may contain one or more sections. A section may have one or more paragraphs. A paragraph may include one or more sentences. A sentence may contain one or more statements. A statement is constructed with one or more character strings.

An element in the hierarchy at least contain one or more subordinate elements.

COBOL Program Structure

Character Set -

  • The set of valid characters creates the character-set for the COBOL programming language.
  • The COBOL character set contains 78 valid characters that contains the alphabets(A-Z/a-z), digits(0-9), and special characters.

Character Strings -

  • The character string is the least or small component in the COBOL program hierarchy.
  • A character string is formed with one more character(s).

    For example -
    WS-VAR
    ZEROES
    MOVE
    IF
    DISPLAY

Statements -

  • A statement defines an action that is to be performed.
  • The statement is a combination of COBOL verb(s), word(s), keyword(s), and operand(s).
  • Statement performs a conditional or unconditional task.
  • A statement should have a COBOL verb/ keyword.
  • A Statement may or may not be marked with a period in the end.
  • All Statements should code in AREA-B but not in AREA-A.
  • All statements are coded in the PROCEDURE DIVISION.
  • Below is the list of statements categories in COBOL -

For example -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
           MOVE WS-A TO WS-B.			-		Statement1
           DISPLAY "STATEMENT".			-		Statement2

Sentences -

  • A sentence contains two or more statements and is marked with a period at the end of the last statement.
  • If the first statement is marked with a period in the end, then it is considered a statement but not as a sentence.
  • All sentences should code in AREA-B but not in AREA-A.

For example - Sentense with two statements.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
           MOVE WS-A TO WS-B 
           DISPLAY "STATEMENT".

Paragraphs -

  • A paragraph is a block of code that contains one or more sentences or a set of statements.
  • A paragraph begins with the paragraph name and ends at the explicit scope terminator of the same paragraph or the next paragraph starts, or next section starts, or the program ends.
  • All paragraph names should code in AREA-A.

For example - 1. Paragraph with explicit scope terminator.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       PARA1.                                                      
           DISPLAY "PARAGRAPH BEGINNING".
		   DISPLAY "PARAGRAPH ENDING".
	   PARA1-EXIT.
	       EXIT.

2. PARA1 ends by PARA2 starts.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       PARA1.                                                      
           DISPLAY "PARAGRAPH1 BEGINNING".
		   DISPLAY "PARAGRAPH1 ENDING".
	   PARA2.
	       DISPLAY "PARAGRAPH2 BEGINNING".

3. PARA1 ends by SEC1 section starts.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       PARA1.                                                      
           DISPLAY "PARAGRAPH1 BEGINNING".
		   DISPLAY "PARAGRAPH1 ENDING".
	   SEC1 SECTION.
	       DISPLAY "PARAGRAPH2 BEGINNING".

4. PARA1 ends when Program ends (i.e., this is the last paragraph of the program).

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       PARA1.                                                      
           DISPLAY "PARAGRAPH1 BEGINNING".
		   DISPLAY "PARAGRAPH1 ENDING".

Sections -

  • A section is a block of code that contains one or more paragraphs or a set of sentences, or a block of statements.
  • The section begins with the section name and ends at another section starting or ending the program.
  • All sections should code in AREA-A.

For example - Section ends by another section starts

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       SEC1 SECTION.                
           DISPLAY "ENTERING INTO SEC1". 
       PARA1.                     
           DISPLAY "ENTERING INTO PARA1 OF SEC1".
       SEC2 SECTION.                
           DISPLAY "ENTERING INTO SEC2". 
       PARA2.                     
           DISPLAY "ENTERING INTO PARA2 OF SEC2".

2. SEC1 ends when Program ends (i.e., this is the last section of the program).

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       SEC1 SECTION.                
           DISPLAY "ENTERING INTO SEC1". 
       PARA1.                     
           DISPLAY "ENTERING INTO PARA1 OF SEC1".

Divisions -

  • A division is a block of code that contains one or more sections or sets of sentences or a block of statements.
  • Division begins with division name and ends at the beginning of the subsequent division or when the program ends.
  • All division headers should code in AREA-A.
  • There are four system defined divisions in COBOL -

Click on each division to get more detailed information about it.

Syntactical Hierarchy -

The syntactical hierarchy follows the below form -

Syntactical Hierarchy

Practical Example -

Scenario - Below example describes how the program structure appears in COBOL programming.

Code -

Program Structure Code
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID. PRSTRUCT.                                            
       AUTHOR. MTH.                                                     
                                                                        
       ENVIRONMENT DIVISION.                                            
       INPUT-OUTPUT SECTION.                                            
                                                                        
       DATA DIVISION.                                                   
       FILE SECTION.                                                    
       WORKING-STORAGE SECTION.                                         
       LINKAGE SECTION.                                                 
                                                                        
       PROCEDURE DIVISION.                                              
                                                                        
           DISPLAY "PROGRAM EXECUTION STARTS..."                        
           PERFORM NEW-SEC-DISP.                                        
           STOP RUN.                                                    
                                                                        
       NEW-SEC-DISP SECTION.                                            
           DISPLAY "ENTERING INTO NEW SECTION...".                      
       PARAGRAPH1.                                                      
           DISPLAY "ENTERING INTO NEW PARAGRAPH...".                    
**************************** Bottom of Data ****************************

Output -

Program Structure Output

Explaining Example -

The STATEMENT coding in the program is -

DISPLAY "PROGRAM EXECUTION STARTS..."

The SENTENCE coding in the program is (because the display statement has no period at the end) -

DISPLAY "PROGRAM EXECUTION STARTS..."                        
PERFORM NEW-SEC-DISP.

The PARAGRAPH coding in the program is -

PARAGRAPH1.                                                      
    DISPLAY "ENTERING INTO NEW PARAGRAPH...".

The SECTION calling and section coding in the program is -

NEW-SEC-DISP SECTION.                                            
    DISPLAY "ENTERING INTO NEW SECTION...". 
PARAGRAPH1.                                                      
    DISPLAY "ENTERING INTO NEW PARAGRAPH...".

Note! "ENTERING INTO PARAGRAPH..." displayed when the Section executed. Because the Section NEW-SEC-DISP has not been followed by any other section and considers its ending is when the program ends. So it considers PARAGRAPH1 as part of the Section and executes PARAGRAPH1 as well.