Search code examples
linuxsyntaxcobolgnucobol

Cobol - syntax error, unexpected $undefined, expecting "end of file"


I have a problem with syntax in cobol. I'm using open-cobol package on Ubuntu 4.2.0-16-generic, and i've got error:

~/cobol$ cobc -free -x -o cal cal.cbl
cal.cbl:6: Error: syntax error, unexpected $undefined, expecting "end of file"

My cal.cbl file:

IDENTIFICATION DIVISION.
PROGRAM-ID. cal.
ENVIRONMENT DIVISION.

DATA DIVISION.   
?? OPTION PIC 9 VALUE ZERO.
?? NUM1   PIC 9(5)V9(2) VALUE ZERO.
?? NUM2   PIC 9(5)V9(2) VALUE ZERO.
?? RESULT PIC 9(10)V9(2) VALUE ZERO.

PROCEDURE DIVISION.
ACCEPT OPTION.

DISPLAY "INSERT FIRST OPTION".
ACCEPT NUM1.
DISPLAY "INSERT SECOND OPTION".
ACCEPT NUM2.

STOP RUN.

I'm new in cobolt, i know something about columns and thats why I'm using -free flag to compile, but this error have no sense for me.

Why this error occurs, please help:)


Solution

  • ?? is no valid COBOL word and no level number (which is needed in line 6). These messages come from OpenCOBOL/GnuCOBOL 1.1.

    Newer GnuCOBOL versions are much better in many ways, including user messages (here with GC 2.2):

    cal.cob: 6: Error: Invalid symbol: ? - Skipping word
    cal.cob: 6: Error: PROCEDURE DIVISION header missing
    cal.cob: 6: Error: syntax error, unexpected Identifier
    cal.cob: 7: Error: Invalid symbol: ? - Skipping word
    cal.cob: 7: Error: syntax error, unexpected Identifier
    cal.cob: 8: Error: Invalid symbol: ? - Skipping word
    cal.cob: 8: Error: syntax error, unexpected Identifier
    cal.cob: 9: Error: Invalid symbol: ? - Skipping word
    cal.cob: 9: Error: syntax error, unexpected Identifier
    cal.cob: 11: Error: syntax error, unexpected PROCEDURE
    cal.cob: 12: Error: 'OPTION' is not defined
    cal.cob: 15: Error: 'NUM1' is not defined
    cal.cob: 17: Error: 'NUM2' is not defined
    

    Change ?? to 01 or 77 and you don't have the error any more. Insert WORKING-STORAGE SECTION or LOCAL-STORAGE SECTION after DATA DIVISION and your program compiles fine.

    Get the Programmer's Guide for knowing more about COBOL.