Sei sulla pagina 1di 9

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

COBOL Tools that Scale


semanticdesigns.com Detect subtle problems in Apps. Off-the-shelf & Custom available

Home About Free eBook Archives Best of the Blog Contact

Cobol Hello World Example: How To Write, Compile and Execute Cobol Program on Linux OS
by Ramesh Natarajan on February 26, 2010
1 Me gusta 26 Tweet 5

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 *.

1 de 9

07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

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 dont 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!
1 Tweet 5 Me gusta 26 >

Add your comment

2 de 9

07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you dont 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..


1. 50 Linux Sysadmin Tutorials 2. 50 Most Frequently Used Linux Commands (With Examples) 3. Top 25 Best Linux Performance Monitoring and Debugging Tools 4. Mommy, I found it! 15 Practical Linux Find Command Examples 5. Linux 101 Hacks 2nd Edition eBook Awk Introduction 7 Awk Print Examples Advanced Sed Substitution Examples 8 Essential Vim Editor Navigation Fundamentals 25 Most Frequently Used Linux IPTables Rules Examples Turbocharge PuTTY with 12 Powerful Add-Ons

Tags: cobc -free, Cobol Compiler, Cobol Tutorial, Hello World Cobol Program, Hello World Examples { 18 comments read them below or add one } 1 jacobian February 26, 2010 at 4:48 am very useful.thanks for sharing.but anyway I thought cobol is an obsolete programming

3 de 9

07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

language. 2 jumpingj February 26, 2010 at 7:43 am Nice!!! 3 Catalin February 27, 2010 at 3:13 am 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 . 4 David April 30, 2010 at 7:53 am 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 5 John August 19, 2010 at 10:44 pm Compile fails with cannot find lncurses 6 Bhavesh Shah September 26, 2010 at 12:11 pm i am getting Problem while creating and using Vim,Cobol compiler. Can any one help me out. 7 BigBert December 21, 2010 at 6:39 pm 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

4 de 9

07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

8 gowri shankar February 7, 2011 at 11:38 pm how to run the cobol program in z/OS. 9 ashish March 28, 2011 at 2:02 pm program is to be currect i know but how it will run on cobol compiler plz tell me. 10 idams h. chinwe May 31, 2011 at 10:08 am 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. 11 Risk-Taker June 8, 2011 at 10:21 pm 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 12 minwet September 9, 2011 at 1:17 am The best compiler can be found in Pre historic caves package in adobe boxes. 13 sirisha October 28, 2011 at 10:48 pm how to install cobol program 14 Oguilaya fidelis February 21, 2012 at 12:20 pm I need some one to teach me a COBOL progame. 15 jha October 10, 2012 at 11:44 pm i want to learn more about cobol .and how to compile a cobol program????? 16 nardzkie October 10, 2012 at 11:48 pm nice to learn more about cobol..i love itcan you give some other example of program by using cobol.,??? 17 ATHI October 30, 2012 at 12:49 pm why only linux or unix are recommanded , if we can use in other os like windows how can we use it? 18 Eddie Sullivan Jr June 1, 2013 at 11:25 pm My I have information on how to install a cobo compiler and editor, the files Leave a Comment Name

5 de 9

07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

E-mail Website

Notify me of followup comments via e-mail

Submit
Previous post: Caught In the Loop? Awk While, Do While, For Loop, Break, Continue, Exit Examples Next post: 30 Things To Do When you are Bored and have a Computer

Search
>Email >RSS >Twitter >Facebook

COURSE
Linux Sysadmin CentOS 6 Course - Master the Tools, Configure it Right, and be Lazy

EBOOKS
Linux 101 Hacks 2nd Edition eBook - Practical Examples to Build a Strong Foundation in Linux

6 de 9

07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell Scripting Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and Awk Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive in Vim Editor Nagios Core 3 eBook - Monitor Everything, Be Proactive, and Sleep Well

POPULAR POSTS
12 Amazing and Essential Linux Books To Enrich Your Brain and Library 50 UNIX / Linux Sysadmin Tutorials 50 Most Frequently Used UNIX / Linux Commands (With Examples) How To Be Productive and Get Things Done Using GTD 30 Things To Do When you are Bored and have a Computer Linux Directory Structure (File System Structure) Explained with Examples Linux Crontab: 15 Awesome Cron Job Examples Get a Grip on the Grep! 15 Practical Grep Command Examples Unix LS Command: 15 Practical Examples 15 Examples To Master Linux Command Line History Top 10 Open Source Bug Tracking System Vi and Vim Macro Tutorial: How To Record and Play Mommy, I found it! -- 15 Practical Linux Find Command Examples 15 Awesome Gmail Tips and Tricks 15 Awesome Google Search Tips and Tricks RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams Can You Top This? 15 Practical Linux Top Command Examples Top 5 Best System Monitoring Tools Top 5 Best Linux OS Distributions How To Monitor Remote Linux Host using Nagios 3.0 Awk Introduction Tutorial 7 Awk Print Examples How to Backup Linux? 15 rsync Command Examples The Ultimate Wget Download Guide With 15 Awesome Examples Top 5 Best Linux Text Editors Packet Analyzer: 15 TCPDUMP Command Examples The Ultimate Bash Array Tutorial with 15 Examples 3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id Unix Sed Tutorial: Advanced Sed Substitution Examples UNIX / Linux: 10 Netstat Command Examples The Ultimate Guide for Creating Strong Passwords 6 Steps to Secure Your Home Wireless Network Turbocharge PuTTY with 12 Powerful Add-Ons

CATEGORIES
Linux Vim Sed Awk Bash
7 de 9 07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

Nagios OpenSSH IPTables Apache MySQL Perl Google Ubuntu PostgreSQL Hello World C Programming C++ Programming DELL Oracle VMware

About The Geek Stuff

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 Ramesh Natarajan and the blog.

Support Us
Support this blog by purchasing one of my ebooks. Bash 101 Hacks eBook Sed and Awk 101 Hacks eBook Vim 101 Hacks eBook Nagios Core 3 eBook

Contact Us
Email Me : Use this Contact Form to get in touch me with your comments, questions or suggestions about this site. You can also simply drop me a line to say hello!. Follow us on Twitter

8 de 9

07/07/13 00:52

Cobol Hello World Example: How To Write, Compile and Exe...

http://www.thegeekstuff.com/2010/02/cobol-hello-world-exa...

Become a fan on Facebook Copyright 20082013 Ramesh Natarajan. All rights reserved | Terms of Service | Advertise

9 de 9

07/07/13 00:52

Potrebbero piacerti anche