TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - "Hello World" Program


Let's start the coding how to display 'HELLO WORLD' in COBOL,

IDENTIFICATION DIVISION.
PROGRAM-ID. IDSAMPLE.
ENVIRONMENT DIVISION.
PROCEDURE DIVISION.
    DISPLAY 'HELLO WORLD'.
    STOP RUN.

Explanation:
  • Line 1 : IDENTIFICATION DIVISION. - this division is mandatory.

  • Line 2 : PROGRAM-ID. IDSAMPLE. - it is mandatory to declare the program id name-IDSAMPLE in indentification division. usually this name is same as PDS member name(file name).

  • Line 3 : ENVIRONMENT DIVISION. - this division is optional.

  • Line 4 : PROCEDURE DIVISION. - this division is mandatory.

  • Line 5 : DISPLAY 'HELLO WORLD'. - DISPLAY statement used to transfer the data to the output device/screen. Output device can be decided based on the SYSOUT in JCL if it is a batch program. Here display statement is used to diplay hardcoded value 'HELLO WORLD'.

  • Line 6 : STOP RUN. - End of program. It is mandatoy to add at the end of program. This is the last executable statement in the program which will returns the control back to OS. STOP RUN always coded in the main program. If STOP RUN coded in the sub program, the control will return to OS instead of returning to main program.

Let us see how the code looks in mainframe screen.

image missing

Points to remember:
  • Sequence number present in column 1-6. this is auto generated. Developer don't need to add.

  • All division name should starts from column 8(Area A). also program id.

  • DISPLAY & STOP RUN statement should starts from column 12(Area B).

  • Have you noted color of each word in the statments? It is because like other programming language mainframe(Emulator) differentiate the user word/statement by color. System defined words are in RED color. Hard coded values are in WHITE color. User defined words are in GREEN color.
Note: Colors can be modified in setting option.


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal