Module 2: COBOL Overview
First simple COBOL program – HELLO WORLD
Below is simple program written in COBOL to display ‘Hello World’
000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. MFPROG1. 000300 PROCEDURE DIVISION. 000400 MAIN-PARA. 000500 DISPLAY 'HELLO WORLD' 000600 STOP RUN.
- COBOL program are always divided into four divisions, namely IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION and PROCEDURE DIVISION.
- Out of these four division IDENTIFICATION DIVISION is the only division which is mandatory to specify and we can specify other divisions only when it is needed
- In above code snippet, lines 000100 and 000200 are the IDENTIFICATION DIVISION and contains only the PROGRAM-ID which is used to specify the program name. In our case, program name specified is ‘MFPROG1’
- In our example, we have omitted ENVIRONMENT DIVISION and DATA DIVISION.
- ENVIRONMENT DIVISION is used to specify the machine on which the program is running. COBOL programs are capable of running on different types of machines, and this is the section that is used to handle differences between different computers. In our case, the program does not have any specialized machine requirement, so we have excluded it.
- DATA DIVISION in other hand is used to specify any data that the program operates on. Our sample program has no data thus DATA DIVISION is also excluded
- Next, lines 000300 to 000600 are the PROCEDURE DIVISION. This is the main part of the program as the functionality intended by the programmer is coded in this division.
- In PROCEDURE DIVISION, multiple paragraphs can be coded. In our example, we have coded only one paragraph ' MAIN-PARA ' which contains a statement on line 000500 to display ' HELLO WORLD'. Statement on line 000600, used to terminate the execution of the program
Executing COBOL program
- In order to execute and compile above COBOL program using Batch JCL, please refer Example of Running COBOL Program using JCL
- If you do not have mainframe system, you can use any available mainframe emulators. Hercules is one of such emulator which is freely available and you can follow download and installation instruction from their website:- http://www.hercules-390.eu/ . Hercules can be used on Linux, Windows, Solaris, FreeBSD, and Mac OS X.
- Note:- We will be also explaining COBOL program compilation and execution process in here