Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with OpenCOBOL! ("Hello world!")

Tags:

cobol

gnucobol

I'm trying to make a very simple COBOL program. I've gotten my directory, configurations, etc. all set up, but when I go to compile it I get this error:

sampleCOBOL.cbl: In paragraph 'Main-Paragraph' :
sampleCOBOL.cbl:9: Error: syntax error, unexpected "end of file"

("sampleCOBOL.cbl" is my file name)

This is what my file contains:

   Identification Division.
   Program-ID. sampleCOBOL.

   Data Division.

   Procedure Division.
   Main-Paragraph.
       Display "Hello World!"
       Stop Run.

I know that the error is occurring on Line#9 ("Stop Run."). However, why?

like image 352
Bryan Strobehn Avatar asked Jan 28 '14 18:01

Bryan Strobehn


3 Answers

There is support for GNU COBOL (formerly OpenCOBOL) at SourgeForge.

From there, here is answer for the same error message: https://sourceforge.net/p/open-cobol/discussion/109660/thread/cdfe04a5/#0996

You can have you COBOL program obey the traditional fixed-column starts/ends, our you can put this, >>SOURCE FORMAT IS FREE in line one, column 12 of your program. You can then code without reference to column numbers.

If using column numbers, columns 1-6 are not used for code, column seven is for the comment, debugging, or new-page marker, or, rarely, continuing a literal which cannot fit on the previous line.

Code then either starts in columns 8-11 (aka "area a") or columnn 12-71 ("area b").

You do not need a full-stop/period in the PROCEDURE DIVISION except to end the PROCEDURE DIVISION header, before a paragraph/SECTION name and before the end of the program. In the distant past, you used to need lots of full-stops/periods, but not needed for many years (although many still code them).

Seeing your comment on the other answer and NealB's comment on your question, if you scroll down the linked-to discussion:

I have used Notepad++ for a lot of my own coding. You can set the EOL to use UNIX instead of windows or UTF encoding. This will also resolve EOF issues. Also, you will need to ensure you set "Use Spaces" when tabbing. cobc has an issue when tabs are used from windows editors.

Putting that together, you are using Windows, tabs, and a version of OpenCOBOL which doesn't like tabs in source. You have two things to do directly to get it working, and you may want to get the latest version of GNU COBOL when it is convenient for you.

I suggest you go here, http://sourceforge.net/p/open-cobol/discussion/2526793/. Join, if you don't have a SourceForge account, or login if you do, and post in Help getting started. There are people there using Windows (which I don't) who should be able to help. The reason for login/join is that otherwise you will wait hours for your question to be "moderated" first, and you'll appear as Annonymous.

like image 59
Bill Woodger Avatar answered Oct 17 '22 00:10

Bill Woodger


Figured out what was wrong. I had an extra line in between "Identification Division" and "Program-ID."

I have no idea how I missed that.

Boy, do I feel stupid.

like image 2
Bryan Strobehn Avatar answered Oct 17 '22 00:10

Bryan Strobehn


The I of IDENTIFICATION must be at the column 8 ( 7 spaces before ).

   ---- sampleCOBOL.cob -------------------------
         * Sample COBOL program
          IDENTIFICATION DIVISION.
          PROGRAM-ID. sampleCOBOL.
          PROCEDURE DIVISION.
          DISPLAY "Hello World!".
          STOP RUN.
    ----------------------------------------
like image 1
M.Ali Avatar answered Oct 16 '22 22:10

M.Ali