Skip to main content

COBOL Tutorial 000100 – the ‘Hello World’

Due to a new project at work, I'm starting to learn COBOL (not the sexiest language, I know). I found the hardest part about learning COBOL for me is to know what COBOL keywords mean in terms of more modern programming languages. Therefore, I thought I’ll write a couple of short tutorials here to explain some of these differences in case some other programmers are interested in learning this 50+ years old programming language.

As with learning any other programming language, the first example has to be the “Hello World” and here’s the source code:

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

Every COBOL program needs an IDENFICATION DIVISION and the PROGRAM-ID (which is HELLOWORLD in our example). All program logic will sit under the PROCEDURE DIVISION. The rest of the program should be pretty self-explanatory.

The full stop (.) is the equivalent of semi-colon (;) in C-derived programming languages, which denotes the end of a coding line.

To compile this code, I used the OpenCOBOL compiler. You can install it under Ubuntu 10.04 by typing the following command in the shell:

sudo apt-get install open-cobol

After installing the compiler, you can then compile the program by running (assuming that you’ve saved the source code in a file called helloworld.cob):

cobc -x -free helloworld.cob

The -free compiler flag tells the cobc compiler to use the free source code format. Without it, the compiler will require you to enter 7 spaces at the beginning of each line. The –x flag, on the other hand, tells the compiler to produce an executable rather than a .so file (we’ll talk about .so files later).

Finally, the compiler may produce few warnings about “dereferencing type-punned pointer” but you can just ignore them. After the compilation finishes, you will find the executable helloworld in your directory.

Comments

Popular posts from this blog

Load Testing ASP.NET Sites with JMeter

Following my previous post about using JMeter to test MOSS, I tried to figure out what are the bare minimum requirements of using JMeter against a plain ASP.NET website. I wrote a very simple ASP.NET web application with just a button, a text fields and a static label. This application displays the content of a text file in the static label when it loads and write content of the text field back to the file when the button is clicked.I found all I need to do in order to script this using JMeter is to extract __VIEWSTATE and __EVENTVALIDATION fields then send them back in the update request. My JMeter test plain looks like this:

Load Testing SharePoint (MOSS) Sites with JMeter

I have used JMeter for load testing few non-ASP.NET web sites before, however I could not get it to work with ASP.NET web sites. This is mainly due to ASP.NET ViewState and event validations, which stops a recorded JMeter script from being played back.Recently I worked on a MOSS project and we were looking for tools to perform load testing on the server. Many people said the load testing tool in Microsoft Team System for Testers works well with MOSS. However, it is quite expensive so I decided to give JMeter another go. After several hours of hacking, I actually got it to work and here’s how I did it.My test page is the pretty standard MOSS edit document property screen with few extra text fields added and the goal here is to use a JMeter script to change the document properties. Once I have a working script, I can configure JMeter to fire hundreds of instances of this script simultaneously to simulate the user workload.As shown in the screenshot below, the test plan contains two HTTP…

Installing the WTL Application Wizard in Visual C++ 2008 Express Edition

I love Google Chrome, it is fast, elegant and beautiful. After I realized that it was written using WTL, I felt quite keen to learn about this library.I downloaded WTL 8.0 from SourceForge.net and Visual C++ 2008 Express Edition from Microsoft.com only to realise that there is no WTL Wizard support for Visual C++ 2008 Express Edition. WTL 8.0 ships with WTL/ATL application wizard but the setup script only supports the Visual C++ 2005 Express Edition (setup80x.js). However, the good news is that you can make it work with Visual C++ 2008 Express Edition in few simple steps:Make a copy of the setup80x.js and rename it to setup90x.js. Open setup90x.js up and do a global search and replace from “8.0” to “9.0”.
Save the file and execute it. If you are as lucky as I am, you should see a dialog that tells you that the wizard has been successfully installed.Now, when you run Visual C++ 2008 Express Edition and go File –> New –> Project… you should now see the new WTL/ATL Application…