Hello World in COBOL

Our first program will print the classic “hello world” message. Here’s the full source code.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. HelloWorld.
       PROCEDURE DIVISION.
           DISPLAY 'hello world'
           STOP RUN.

To run the program, compile the code into an executable using a COBOL compiler and then execute it.

$ cobc -x HelloWorld.cbl
$ ./HelloWorld
hello world

Sometimes we’ll want to build our programs into binaries that can be executed directly. Using COBOL, the cobc command allows us to compile COBOL programs.

We compile the code first and then produce the executable:

$ cobc -x HelloWorld.cbl
$ ls
HelloWorld     HelloWorld.cbl

We can then execute the built binary directly.

$ ./HelloWorld
hello world

Now that we can run and build basic COBOL programs, let’s learn more about the language.