Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cobol sections or paragraphs

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can someone please give me a valid reason for using sections when developing new cobol programs. I have read in many books and forums that the use of sections is no longer required or needed and only adds extra confusion to code. Is this correct or just people's opinions. We are trying to set some coding standards for a new project and no one can decide on wether to use paragraphs or sections.
 
The only time you must use a SECTION rather than a paragraph is inside the DECLARATIVES portion of your code. That is if you choose to use any DECLARATIVES at all.

PARAGRAPHs do everything I need in the PROCEDURE DIVISION. SECTIONs would only add possible bugs as in this example:

PERFORM chunk-of-code.

chunk-of-code SECTION.
bit-of-code-par.
<...>

more-code-par.
<...>

When chunk-of-code is performed, all PARAGRAPHs inside that SECTION are supposed to be executed. SECTION only gives you a handful of trouble with no obvious gain.

Dimandja
 
Hi McChaddy,
In most installations that I have worked in SECTIONs are performed rather than PARAGRAPHs. I'm not sure I agree with Dimandja's statement that sections only give you a handful of trouble with no obvious gain and will play devil's advocate and argue for sections over paragraphs.

Paragraphs can be abused by use of the GO TO statement, Sections cannot.
Inexperienced programmers may not realise when a paragraph exits, particularly if exit paragraphs are not used.
Sections are more widely used and understood.

Basically it's a matter of choice, but what I would suggest is that you have a clearly defined exit point, and that if you are going to use sections, then do not have multiple paragraphs within it. For example:

A0010-CONTROL (SECTION).

PERFORM B0010-PROCESS.

A9999-EXIT.
GOBACK.

B0010-PROCESS (SECTION).

process

B9999-EXIT.
EXIT.

In this example the paragraphs can be sections, as you prefer, but with clearly defined exit points it is easy to understand what is happening.

Hope this helps.
Marc
 
Sorry to disagree, Marc, but in 25 years of COBOL programming, I have seen SECTIONs rarely PEFORMED, and they are being used less and less. As a consultant, I've been in a LOT of shops, so I'm basing my comments not on a few installations. I find it true not only in IBM COBOL, but DEC, NCR, Burroughs and mini/micro.
Sections can certainly be abused with GOTOs, even more than paragraphs ... you can go back and forth in the section with GO TO, as well as going ouside the section.

If you are adopting standards, prohibit the use of GO TO. (Many shops do this, and their are tools to enforce it.) I have finally been convinced that if you make it a shop standard, you can do away with the EXIT paragraph, if ALL performs are only one paragraph, and there are no GOTOs.

By the way, the new standard introduduces several new EXIT statements:
EXIT PERFORM
EXIT PERFORM CYCLE
EXIT PARAGRAPH
EXIT SECTION.

They are ALL disguised GO TO statements! Prohibit them all! They will make your code unstructured!

The complete draft can be downloaded from

Stephen J Spiro
ANSI COBOL Standards Committee

Check it out at
 
Hi Stephen,
I'm going to assume that you are US based and that it may therefore be a preference of country as over here in the UK, where I been programming with Cobol since 1979, it tends to be Sections rather than Paragraphs which are performed. I've worked for many of the big players here and only one (Ford, I think) performed paragraphs rather than sections. You're right that sections can be abused by adding paragraphs into them, which was why I said that you should not have multpile paragraphs within a section. Of course, what I am describing is a section used as a paragraph! I agree totally that GO TO's should be banned and can remember debugging programs back in the 80's that had GO TO DEPENDING ON RECORD-TYPE statements. Ugh!

The idea of the new EXIT statements fills me with horror. Some may consider them useful, but I, like you, can see further problems when used in the wrong hands.
Marc
 
In the good ol' days when memory was at a premium we would need to break a program into sections if it was too large to load into the available memory. On the Burroughs/Unisys systems that I worked on (and I don't know if IBM is/was the same way) only the section of the program being referenced was loaded into memory.

Crackerjack
 
I love discussions where opinions matter more than fact!

As a consultant, I have witnessed employers stressing either method (sections or no sections) with vigor!

My opinion? If you want to see a logical program, one that you can debug at 3:00 am, then selection SECTIONS.

Even the section names tend to be logical:
perform open-section.
perform read-section.
perform loop-section while there-is-data.
perform close-and-clean-up-section.

While go to's are more likely to occur in sections
(go to end-of-section type logic), they TEND to show cleaner thinking going on.

And that, my friends, is purely my humble opinion.
cobol vax vms ingres and recruiting schiffkey@cfl.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top