as robert stated, when not using the exit statement the possibility exist for falling through the perform exit paragraph (especially so when using goto's).
What Robert actually wrote:
If a program contains GO TO and PERFORM statements, the possibility exists for falling through PERFORM EXIT paragraphs. In fact, a poorly written program can even fall through PERFORM EXIT paragraphs without a single GO TO statement in it -- we've seen examples on this forum.
Quite a different thing.
using the "thru ..-exit" will make life easier when debugging.
Can you explain how?
Can you explain, leaving aside all the other stuff, what you think
PERFORM A-PARAGRAPH THRU A-PARAGRAPH-EXIT
does for you? How does it protect you from GO TOs? How does it aid you at all? Leaving out all the rest, just sticking to the subject. You gave it as general advice, best practice, so...
5.7.1 PERFORM <section>
Even though COBOL allows the PERFORM command to be used on paragraphs as well as sections, its use should be limited to sections only. If necessary make the offending paragraph into a self-contained section, or an in-line PERFORM (if it is small enough). This guideline then avoids the possibility that someone may split the paragraph in two, thereby causing the PERFORM to terminate at the new paragraph name.
Please note that if the word SECTION is missed out on a section name it will be treated as a paragraph. As there is usually nothing but comments between the section name and the next paragraph it means that no code will actually be executed by that PERFORM statement. Unfortunately the code WILL be included in the PERFORM of the preceding section. This usually causes lots of confusion.
5.7.2 PERFORM ... THROUGH ...
Avoid the use of PERFORM <procedure-A> THROUGH <procedure-Z>. It is good practice to name each procedure (section) explicitly - this makes it easier to search a source file for all occurrences of PERFORM <sectionname>, and also avoids the possibility that someone may add a new section between existing sections without realising that it now falls within the bounds of the PERFORM <A> THROUGH <C> statement. A program can produce some very peculiar results if a section is `accidentally' performed out of sequence, and is not easy to debug.
5.7.3 The EXIT statement
The EXIT verb in COBOL does not produce an EXIT instruction in the object program - it is ignored, but is maintained for documentation purposes only. Whenever a section is PERFORMed COBOL will generate its own (hidden) EXIT instruction when the next section-name is encountered. If a section-name in your source file has the word SECTION missing, COBOL will treat it as a continuation of the preceding section - this can cause some very peculiar results (refer to PERFORM <section>).
5.7.4 The GO TO statement
Do not use the GO TO verb to transfer control to a point which is outside the current section as any implied EXIT points will be ignored. This means that the program will go where it thinks it should go, which is probably NOT where it is supposed to go.
Guess i am not alone in my opinion on what is best practise am I ?
You seem to stubborn to convince though.
Joined: 06 Jun 2008 Posts: 8491 Location: Dubuque, Iowa, USA
coboljoost, if those are the standards your site follows, then follow them. Or, if they are the standards YOU want to follow, follow them. However, be aware that what you are quoting is more than 25 years old at this point, and COBOL is a dynamic language that changes over time. Since your link was last updated in 1993, I sincerely doubt it includes much about the COBOL 2002 changes, whether or not the standards are relevant any more. And of course there will be nothing about in-line PERFORM statements in those standards. But don't expect people on this forum, especially those of us with 25 ... 30 ... 35 or more years of COBOL coding experience, to agree with your opinions about what should be standards.
Furthermore, your post made extensive comments about SECTIONS -- which haven't been mentioned before in this thread. I have seen some really strange and difficult-to-debug errors arise from mixing PERFORM sections and PERFORM paragraphs in COBOL programs. Using SECTION names in a PROCEDURE DIVISION imposed an additional hierarchy on a program, a hierarchy that may -- or may not -- be intended.