4

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"
Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
user3025281
  • 157
  • 2
  • 10
  • OpenCOBOL is now GnuCOBOL. OpenCOBOL is no longer maintained. If you find the GnuCOBOL site (currently at SourceForge) you can install GnuCOBOL 1.1 or, if you are feeling adventurous, the "nightly tarball". There is an active discussion area for all issues, however small – Bill Woodger Sep 05 '15 at 20:04
  • 5
    And to fix your problem, use `*>` to indicate comments when using -free, `*` in column 7 when using fixed-column layouts. – Bill Woodger Sep 05 '15 at 20:11
  • Note that the document you are reading shows all of the COBOL programs using the traditional fixed format in which the first 7 columns consist of 6 columns where you can put things like a sequence number (which they do in their examples), and a comment indicator (`*`) in column 7. Then each line of actual code starts in column 8. This is explained (a little) on pages 20 & 24 of the document you're reading. If you copy their example including the sequence numbers as-is and omit the `-free` option, it should compile and run. – lurker Sep 10 '15 at 12:48

2 Answers2

6

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.

Joe Zitzelberger
  • 4,238
  • 2
  • 28
  • 42
3

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.

Brian Tiffin
  • 3,978
  • 1
  • 24
  • 34