views:

1069

answers:

4

Why does COBOL have both SECTION and PARAGRAPH?

Can anybody explain why the designers of COBOL created both SECTIONs and PARAGRAPHs? These have been around since the initial release of COBOL so I suspect the real reason for their existence has long since gone away (similar to things like NEXT SENTENCE which are still in the language specification for backward compatibility but no longer required since the introduction of explicit scope terminators).

My guess is that SECTION may have been introduced to support program overlays. SECTION has an optional PRIORITY number associated with it to identify the program overlay it is part of. However, most modern implementations of COBOL ignore or have dropped PRIORITY numbers (and overlays).

Currently, I see that SECTIONs are still required in the DECLARATIVE part of the PROCEDURE DIVISION, but can find no justification for this. I see no semantic difference between SECTION and PARAGRAPH other than PARAGRAPH is subordinate to SECTION.

Some COBOL shops ban the use of SECTION in favour of PARAGRAPH (seems common in North America). Others ban PARAGRAPH in favour of SECTION (seems common in Europe). Still others have guidelines as to when each is appropriate. All of this seems highly arbitrary to me - which begs the question: Why were they put into the language specification in the first place? And, do they have any relevance today?

If you answer this question, it would be great if you could also point to a reference to support your answer.

Thanks

+1  A: 

For one thing, paragraph names must be unique unless they are in separate sections, so sections allow for "namespacing" of paragraphs.

If I recall correctly, the only reason you must use a SECTION is for DECLARATIVES. Aside from that they are optional and primarily useful for grouping paragraphs. I think it's common (relatively speaking, anyway) to require that PERFORM be used on paragraphs only when they are in the same section.

Tim Sylvester
I had forgotten about the "namespacing" feature that `SECTION`s provide over `PARAGRAPH`s, but was that the justification the language designers used when coming up with these constructs?J.Sammet wrote an interesting article on the Early History of COBOL some time ago where some insight was given into why certain language features are the way they are but provided no insight as to why both `SECTION` and `PARAGRAPH` were incorporated. I just don't get it - but these people were not dummies so I imagine there must have been good reasons for having them. Thanks, Neal
NealB
+1  A: 

I learned COBOL around 1978, on an ICL 2903. I have a vague memory that the SECTION headers could be assigned a number range, which meant that those SECTION headers could be swapped in and out of memory, when the program was too large for memory.

colemanj
Yup, those were PRIORITY numbers, and I bet you could give me a bunch of horror stories on having to use them too. I believe a program could get into real trouble if you ever let one independent segment (priority number >= 50) referenced another independent segment. Fortunately, those days are pretty much behind us now...
NealB
+1  A: 

A section can have several paragraphs in it. When you PERFORM a section, it executes all the paragraphs in the section. Within the section you can use PERFORM or GOTO to branch to the paragraphs within the section.

JoelFan
Hence the EXIT statement as a target for GO TOs. Today, EXIT is just a place to "hang" a paragraph name. I think some early compilers required EXIT to be the only statement in the last paragraph of a performed range of SECTIONs/PARAGRAPHs. It was required to generate code implementing the return from a PERFORMed range.Since PARAGRAPH is subordinate to SECTION, one can expect that PERFORMing a SECTION will execute all contained paragraphs. A range of paragraphs may be executed using `PERFORM para-1 THROUGH para-n` so the same functionality may be achieved using paragraphs only.
NealB
A: 

We use COBOL SECTION coding in all of our 37K MVS batch COBOL programs. We use this technique to get much faster run times and significantly reduced CPU overhead. This COBOL coding technique is very similar to high performance batch assembler.

Call it High Performance Functionally Structured COBOL programming

Once a SECTION is defined all PERFORM xxxxx will return at the next coded SECTION not the next paragraph in the SECTION. If paragraphs are coded ahead of the first SECTION then they can be executed normally. (But we don't allow this)

Using a SECTION has higher overhead than when using and PERFORM ing only paragraphs - U N L E S S - you use GOTO logic to bypass code that should be conditionally executed. Our rule is that a GOTO can only point to a Tag-Line in the same SECTION. (a paragraph) All paragraphs in a SECTION must be a sub function of the SECTION s function. The EXIT instruction is an assembler NOP instruction. It allow for a Tag-Line to be placed before the next SECTION - a fast exit/return.

Executing a PERFORM xxxx THRU yyyy has more CPU overhead than execution a SECTION without the GOTO s.

WARNING: Executing a PERFORM xxxx Tag-Line in a SECTION will fall thru all the code in the SECTION until the next SECTION is encountered. A GOTO *Tag-Line* outside of the current SECTION will fall thru all the code in the new landing SECTION until the next SECTION is encountered. (But we don't allow this)

Interesting... Have *you* done benchmark testing to demonstrate theseperformance differences? I was under the impression that the controlmechanism used in IBM compilers was *exactly* the same when PERFORMing SECTIONS andPARAGRAPHS. The control mechanism used in IBM COBOL compilers to implement the return from a PERFORM is described in [this paper](http://portal.acm.org/citation.cfm?id=381788.316163)I would not expect any difference in performing a SECTION or a PARAGRAPH.
NealB