Question: I would like to understand the basics of how to write and execute Cobol program on Linux OS. Can you explain it with a simple example?
Answer: In this article, let us review very quickly how to write a basic Hello World Cobol program and execute cobol program on Linux or Unix OS.
1. Write a Hello World Cobol Program
Create the helloworld program using the Vim editor as shown below.
$ vim helloworld
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
* simple hello world program
PROCEDURE DIVISION.
DISPLAY 'Hello world!'.
STOP RUN.
Note: Comment in Cobol starts with *.
2. Make sure Cobol Compiler is installed on your system
Make sure Cobol compiler is installed on your system as shown below.
$ whereis cobc cobc: /usr/bin/cobc /usr/share/man/man1/cobc.1.gz $ which cobc /usr/bin/cobc
Installing cobc compiler
If you don’t have cobol compiler, install it as shown below.
$ sudo apt-get install open-cobol
3. Compile the cobol program
Compile the HelloWorld which will create the HelloWorld executable.
$ cobc -free -x -o helloworld-exe helloworld $ ls helloworld helloworld-exe*
- -free – use free source format. Without this option cobol program requires certain format.
- -x – build executable program.
- -o FILE – place the output file into the specified FILE.
4. Execute the cobol Program
Execute by mentioning the program name.
$./helloworld-exe Hello World!
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 17 comments… read them below or add one }
very useful.thanks for sharing.but anyway I thought cobol is an obsolete programming language.
Nice!!!
Cobol is not very old programming language. I see on http://en.wikipedia.org/wiki/COBOL. I think is more useful to try python … Anyway is a nice article .
Ramesh as always great post,
Two quick question:
Does this compiler include Runtime? If not would you happen to know if there is any free Cobol Runtime licenses?
Thanks in advance
David
Compile fails with
“cannot find lncurses”
i am getting Problem while creating and using Vim,Cobol compiler.
Can any one help me out.
Important note on Debian / Ubuntu machines:
OpenCobol cannot find ncurse, so compile will fail. To fix this:
Edit ld.so:
sudo gedit /etc/ld.so.conf
and add ‘/usr/local/lib’
to the file.
eg:
include /etc/ld.so.conf.d/*.conf /usr/local/lib
Create symbolic link to ncurses:
sudo ln /lib/libncurses.so.5.7 /lib/libncurses.so
Re-run ld config:
sudo ldconfig
how to run the cobol program in z/OS.
program is to be currect i know but how it will run on cobol compiler plz tell me.
A lot of lecturers make it difficult for students to learn COBOL but it will be easy if you allow student to learn directly via the way you solved that very simple HELLO program. I bet i learn’ t a bit from that program you just wrote.
Just wandering what is the best COBOL Compiler for college students? how to compile COBOL program and can you please give me a sample program based on that version of COBOL. Tnx
The best compiler can be found in Pre historic caves package in adobe boxes.
how to install cobol program
I need some one to teach me a COBOL progame.
i want to learn more about cobol ….and how to compile a cobol program?????
nice to learn more about cobol..i love it…can you give some other example of program by using cobol.,???
why only linux or unix are recommanded , if we can use in other os like windows how can we use it?