If you don’t know COBOL (and I clearly don’t know it well enough), you probably won’t spot that there’s a syntax error here:
IDENTIFICATION DIVISION. PROGRAM-ID. BLAH. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. PROCEDURE DIVISION. DISPLAY 'BLAH.' UPON CONSOLE. STOP-RUN.
The C equivalent to this program is:
but it is meant to have an exit(0), so we want:
Translating that back into COBOL, we need the STOP-RUN statement to say STOP RUN (no dash). With the -, this gets interpreted as a paragraph label (i.e. STOP-RUN delimits a new function) with no statements in it. What I did was something akin to:
The final program doesn’t have the required ‘return 0’ or ‘exit(0)’ and blows up with a “No stop run nor go back” error condition. Logically, what I really wanted was:
IDENTIFICATION DIVISION. PROGRAM-ID. BLAH. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. PROCEDURE DIVISION. DISPLAY 'BLAH.' UPON CONSOLE STOP RUN .
This time I’ve left off the period that I had after CONSOLE (which was superfluous and should really only be used at the end of the paragraph (end of “function”)), and also fixes the STOP-RUN -> STOP RUN typo.
This is not the first time I’ve gotten mixed up on when to use DASHES or not. For example, even above, I’d not expect a programmer to know or remember that you need to know to use dashes for WORKING-STORAGE and PROGRAM-ID but not for PROCEDURE DIVISION, nor some of the other space delimited fields.
My eyes are burning, and I left my COBOL programmer safety gear at home.
Hmm, that original code works fine, I copied and pasted it into a test.cbl file, compiled it with open cobol and it worked ok (for me at least);
Cobol$ cobc -x ./Source/test.cbl
Cobol$ ./test
BLAH.
Cobol$
But this on the other hand, is incorrect;
PROCEDURE DIVISION.
DISPLAY ‘BLAH.’ UPON CONSOLE
STOP RUN
The new cobol allows for the use of the full stop at the last statement or sentence of the paragraph, so a full stop is needed after “STOP RUN.” but not needed after CONSOLE – This is because they introduced block commands like PERFORM VARYING etc now uses a END-PERFORM instead of having to perform a paragraph.
So simple rule in PROCEDURE DIVISION, no full stops until the last statement in the paragraph, for example;
B000-INITIALISATION SECTION.
B000.
some statement
some statement
some statement.
B100.
some statement
some statement.
B200.
some statement.
Interesting, thanks Paul. I’ll have to go back and try the original on an actual mainframe with a variety of COBOL compiler versions (4,5,6) and see if there are any semantic differences.
My testing wasn’t with open cobol, but with an in-house COBOL compiler (not yet released.)
Interesting, an in-house COBOL compiler (not yet released). Well, your original code looks fine and hopefully, the issues identified may relate to an issue with the in-house compiler. If it complies with ANSI-74, the full stops at the end of each statement are mandatory. I suspect they may have simply “forgot” the premise behind of the full stop being a way of ending a command (or as it was, back in the day) as latter compilers, with the introduction of ANSI-85 using blocked commands, e.g. IF with END-IF, PERFORM with END-PERFORM. With these latter changes to the COBOL langiuage, they probably decided the humble full stop was not needed, i.e. commands within a paragraph end with a new paragraph, programs end with the end of the program file etc.
Please post how you get on with the mainframe, I will be intrigued but I suspect the issue is in-house intrepretation of the language and its nuances rather than not your code, which makes learning the language harder.
Hi Paul,
I’m still learning the COBOL lingo.
By full stops, do you mean the periods that end the paragraph? In my case, in the original program, I meant there to be one paragraph with a DISPLAY and a STOP RUN. i.e.:
I’d coded an unnecessary period after the DISPLAY out of habit because of writing C and C++ for 20+ years. That effectively ended my paragraph, and since I’d made the typo in my ‘STOP RUN.’ statement (i.e. I wrote ‘STOP-RUN.’ which got interpreted as an empty paragraph label), resulted in a “no stop-run or go back runtime error” that occurs when the program falls off the world. Our compiler+runtime also abends in such a circumstance for mainframe compatibility.
You say that cobc allows a program to exit cleanly without a stoprun or goback, and theorize that newer mainframe COBOL compilers+runtime may also allow that (perhaps with special options to use newer language levels). That would certainly be a bit more programmer friendly!
There is a good reference book called “Beginning COBOL for Programmers” by Michael Coughlan (Allpress, ISBN 978-1-4302-6254-1) and it some comments on the use of full stops.
Prior to ANS85 (I was taught ANS74), the period (or full stop) was used to delimit scope and it was used at end of each statement. But periods are hard to see on a printed listings, so this changed in ANS85, since there were alot of errors generated by missing a period or full-stop. With the newer compilers, I now simply have one period or full stop at the end of the last statement within a paragraph.
From Coughlan; “A COBOL program is divided into distinct parts called divisions. A division may contain one or more sections. A section may contain one or more paragraphs. A paragraph may contain one or more sentences, and a sentence one or more statements.” (page 21).
So, if your compiler requires no periods (full stops) at end of the sentences in a paragraph, you may need to remove them but various COBOL books may state they are needed.