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?
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.
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.
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.
----------------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With