Designed primarily for business and financial applications, COBOL is a high-level programming language. COBOL has been widely used for business data processing, financial systems, and government applications for over 60 years and it is still dominating the enterprise computing. COBOL is still relevant and widely used for large-scale legacy systems and applications, especially in the financial and government sectors. COBOL is simple, robust, and easy-to-learn programming language. The following table describes these five fields.
COBOL Coding Format
|Sequence numbers or Page and line numbers||Used in the olden days for sequence checking.|
|Continuation, comment, or form feed||(-) To continue the non-numeric literals from the previous line.
(*) To comment the line.
(/) To instruct the printer to move to a new page when printing the source program.
|Area A||Used for special entries such as DIVISION, SECTION, Paragraphs names.|
|Area B||Used for most COBOL entries, including PROCEDURE DIVISION sentences.|
|Identification Area||Used in the olden days for identification purposes.|
Overview of the Program Structure in COBOL
It has four main parts: Identification, Environment, Data, and Procedure Divisions.
Identification Division contains information about the program such as the program name and the author’s name. The Identification Division is where you name your program and provide any additional identifying information that you want. It is compulsory.
Here’s an example of the Identification Division in a COBOL program:
Environment Division is an optional DIVISION. It comprises of the two sections namely CONFIGURATION SECTION and INPUT-OUTPUT SECTION. The Environment Division pertains to the computers that are used to compile the source program and execute the object program. It also encompasses the INPUT-OUTPUT section which specifies the program’s input and output files.
Here’s an example of the Environment Division in a COBOL program:
DECIMAL-POINT IS COMMA.
CURRENCY SIGN IS INR.
The Data Division contains an information about the data that is used in the program such as data names, data types, and data sizes.
Here’s an example of the Data Division in a COBOL program:
01 MY-VARIABLE PIC 9(4).
01 MY-STRING PIC X(20).
The Procedure Division is the most important section of a COBOL program as it contains the actual logic of the program such as calculations, input/output operations, and conditional statements. It is the final division in the program and is responsible for executing the program’s instructions.
Here’s an example of the Procedure Division in a COBOL program:
OPEN INPUT INPUT-FILE
READ INPUT-FILE AT END SET END-OF-FILE TO TRUE
NOT AT END
MOVE INPUT-FIELD TO OUTPUT-FIELD
How to Run Some COBOL Programs
DISPLAY "Welcome Home!".
This COBOL code basically shows how to run a COBOL program. This COBOL code uses the IDENTIFICATION DIVISION to identify the program and specify its name, “WELCOME-HOME.” The Procedure Division uses a DISPLAY statement to show the message, “Welcome Home!”
01 NUMBER1 PIC 9(4).
01 NUMBER2 PIC 9(4).
01 RESULT PIC 9(4).
DISPLAY "Enter 1st number: ".
DISPLAY "Enter 2nd number: ".
SUBTRACT NUM2 FROM NUM1 GIVING RESULT.
DISPLAY "The result of subtraction is: " RESULT.
Enter 1st number:
Enter 2nd number:
The result of subtraction is: 0020
This is a COBOL program that calculates the subtraction between two numbers that are entered by the user. It uses the DATA division to declare the variables, and the PROCEDURE division for logic, including prompting the user for input, performing the subtraction, and displaying the result.
01 WS-ADMIN-NAME .
05 WS-FIRST PIC X(10) VALUE SPACE.
05 FILLER PIC X(10) VALUE SPACE.
05 WS-LAST PIC X(15) VALUE SPACE.
MOVE 'NATH' TO WS-FIRST.
MOVE 'SOMDEB' TO WS-LAST.
DISPLAY ‘ADMIN NAME: ', WS-ADMIN-NAME
ADMIN NAME: NATH SOMDEB
This program stores and displays the name of a college administrator by declaring the name variables in the working-storage section and using two sections in Procedure Division to move the first and last names to the WS-ADMIN-NAME variable and display the name on the screen.
COBOL is still used for large-scale systems, especially in finance and government. By following the steps in this article, one can run the COBOL programs. This article explains the different sections of a COBOL program and how they work together to form a complete COBOL program. A foundation is established to write and run the COBOL programs, regardless if you are new or experienced in COBOL programming.