Search code examples
cobolgnucobol

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"

Solution

  • 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.