user3025281
user3025281

Reputation: 157

OpenCOBOL sample won't compile

I am running Ubuntu and trying to learn COBOL. I have dabbled in a few online tutorials but have had inconsistent results with certain programs.

I prefer to use vim in a bash shell; leading me to OpenCOBOL (cobc)

Is there a decent tutorial that will teach me the basics? I have been working through this one.

http://www2.southeastern.edu/Academics/Faculty/kyang/Cmps401/P2Cobol/Resources/Teach%20Yourself%20Cobol%20In%2021%20Days%20%282nd%20Ed%29.pdf

My issue is that when running some of the example source code, the compiler returns an error when trying to use a "*". It says it is expecting an end of file.

Here is my source code:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
ENVIRONMENT DIVISION.
*comment here
DATA DIVISION.
PROCEDURE DIVISION.
        DISPLAY 'HELLO WORLD!'.
        STOP RUN.

Here is the command I am running:

 cobc -x -free -o helloworld helloworld.cbl

Here is the error returned

helloworld.cbl:4: Error: syntax error, unexpected '*', expecting "end of file"

Upvotes: 4

Views: 3035

Answers (2)

Brian Tiffin
Brian Tiffin

Reputation: 4126

One of the best online COBOL learning resources is by Michael Coughlan, University of Limerick. http://www.csis.ul.ie/cobol/

Most, if not all the samples will work with GnuCOBOL, if you change the compiler directives to standard.

$ SET SOURCEFORMAT"FREE"

becomes

>>SOURCE FORMAT IS FREE

and change all the * column one comment markers to *>. If you like Vim, then those comment fixes are pretty easy

%s/^\*/\*>/gc

With those simple changes, the samples should compile clean with cobc. Michael has written one of the best beginner through advanced tutorials available on the net. Umm, that's a personal opinion.

Upvotes: 3

Joe Zitzelberger
Joe Zitzelberger

Reputation: 4263

If you are using only the '*' comment, you need to use fixed form Cobol.

That means all of your division headers would start in "Area A", from columns 8-12, and your Display and Stop Run statements would start in "Area B", from column 12 - 72.

Or you could change the comment to a free form one, using '*>' and then it should work.

Upvotes: 6

Related Questions