Getting started with OpenCOBOL! ("Hello world!")
Asked Answered
E

4

7

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?

Emmittemmons answered 28/1, 2014 at 18:28 Comment(12)
I guess you are missing a dot after Display "Hello World!"Strauss
Are you using spaces or tabs to indent your code? If using tabs, try switching to spaces. If that doesn't work try viewing the file in hex and replace not-printable characters with spaces.Costive
I think that's probably it, or at least pointing in the correct direction, @NealB. Probably both tabs and Windows end-of-lines. The link in my answer has details, and was also a problem from someone using Notepad++. I've updated to put the details in the body.Orography
@LucM all the necessary full-stops/periods/dots are in the example program. Adding further ones is just clutter, though some do, from habit. After the 1985 standard, many fewer are mandatory in the Procedure Division, and new learners should not bother with them.Orography
@NealB: how do I switch to hex-view? Is this something I can do in Notepad++? Also, to Bill: I have Notepad++ set up to change tabs into spaces, of size 4, etc.. However, I just tried using spaces instead and I'm still getting the same error. Compiler is saying that the error is happening on "Line #9" (I'm assuming), which is the "Stop Run." line.Emmittemmons
The program you have in your question is clean of tabs or other non-display characters. I would paste into Notepad, the standard, delivered-with-Windows one, and Save, then run the compile. If still acting up, I'd add another paragraph-name after STOP RUN, PERFORM that-paragraph-name and put the DISPLAY in there and see if you can get the error message to "move".Orography
I've compiled and run your code using GNU COBOL 2, not under Windows, and everything is fine with it. Note that SPFLITE emulates an IBM Mainframe editor, so if you have not used SPF/ISPF on an IBM Mainframe, it may be a little "non-intuitive" to you. HEX ON will put the display in HEX mode, and HEX OFF will turn it off again. Non-display characters will appear as "dots", so look for those in the text display, then HEX ON if needed.Orography
@BillWoodger: I tried what you suggested (using "regular" Notepad), and I received the same error. Then, I tried adding another paragraph - same thing. I'm thinking now that it has to be something with Windows EOL/EOF characters that the compiler is not liking. FINALLY, I made Notepad++ "Show All Characters" (from the View menu), and Line 9 has 2 characters: [CR][LF] it looks like. I removed them, but the error is still occurring.Emmittemmons
What about the other lines?Orography
I've uploaded an image of what I see in Notepad++. See here: skydrive.live.com/… (on another note: how do I "embed" images into these comments? Is that something that can be done?)Emmittemmons
You seem to have a mixture of LF-only and CR-LF lines. I don't know if that matters. I would paste your original from the question into Windows Notepad. Add the ensure seven leading blanks on each line with text. Save. Try that. Also see updated answer in a couple of minutes.Orography
Just to add, in defense of GNU Cobol. We are working out the issue on SourceForge, and it is line-ending related. I sent a copy of the program saved in Vim and it compiled fine. We'll help Bryan work out the other issues as well.Cookbook
O
2

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.

Orography answered 28/1, 2014 at 20:33 Comment(2)
I tried the various solutions mentioned there, except for using a new editor. Still no luck! SPFLite is downloading right now, and I'm going to retry it using that program instead.Emmittemmons
First, thank you for your patience and your help thus far! I've tried what you suggested (above comment), but I'm still getting the same error. I'm going to ask on the SourceForge page and see if I can get some help there. If I figure it out, I'll return with an update.Emmittemmons
E
2

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.

Emmittemmons answered 30/1, 2014 at 2:14 Comment(1)
Actually, no need to feel stupid. You could have four hundred blank lines there, and it should still compile. I think what you've done is remove a line ending in LineFeed with no CarriageReturn. If you have no lines like that left in your program, then you have an answer. It is not the blank line itself that is the problem directly.Orography
R
1

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.
    ----------------------------------------
Reaves answered 28/1, 2014 at 18:39 Comment(2)
Notepad++ is telling me that it does indeed start at column 8. It says "Col: 8" on the bottom of the screen when my cursor is BEFORE the "I". Does this mean that my cursor has "passed" the I, or that it is "at" the I?Emmittemmons
you are also missing a . after the "Hello World!".<--Reaves
O
0

I faced the same problem recently when I just started learning COBOL. The point is each line should end with CRLF. You can refer here to see how you can achieve this.

Orthogenetic answered 22/1, 2015 at 7:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.