Getting started
Hello, world!
This is a sample program that displays “Hello, world!”:
---- hello.cob -------------------------
* Sample COBOL program
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.
----------------------------------------
The compiler, cobc, is executed as follows:
$ cobc -x hello.cob
$ ./hello
Hello, world!
The executable file name (
hello
in this case) isdetermined by removing the extension from the source file name.
You can specify the executable file name by specifying the compiler
option -o
as follows:
$ cobc -x -o hello-world hello.cob
$ ./hello-world
Hello, world!
The program can be written in a more modern style, with free format code,
inline comments, the GOBACK
verb and an optional END-DISPLAY
terminator:
---- hellonew.cob ----------------
*> Sample GnuCOBOL program
identification division.
program-id. hellonew.
procedure division.
display
"Hello, new world!"
end-display
goback.
----------------------------------
To compile free-format code, you must use the compiler option -free
.
$ cobc -x -free hellonew.cob
$ ./hellonew
Hello, new world!