Page 1 of 1

Sections inside Procedure division.

PostPosted: Wed May 08, 2013 8:10 pm
by gokulNmf
Hi All,

We have some old Cobol programs; we are changing a part of logic in it for another purpose. These programs have sections instead of Paras inside Procedure division. we are planning to change them to para instead of sections.

These programs call sub programs which also have sections instead of Paras inside Procedure division.

My query is; if we change it in main program and leave sub program untouched; will it affect the execution?

Re: Sections inside Procedure division.

PostPosted: Wed May 08, 2013 8:16 pm
by Akatsukami
No.

Re: Sections inside Procedure division.

PostPosted: Wed May 08, 2013 9:13 pm
by BillyBoyo
No.

Since you are going to change them in your main program, do you know the difference between a SECTION and a paragraph?

Perhaps show an example of what there is, including the PERFORM of it, and then show your replacement code. If you just change a SECTION to a paragraph you may not get what you want.

Re: Sections inside Procedure division.

PostPosted: Wed May 08, 2013 11:40 pm
by gokulNmf
Billy,

My understanding is;
On hierarchy Sections come above Paras, So When you perform a Section all the paras and other statements inside the section will execute until, a EXIT or next Section comes.

Re: Sections inside Procedure division.

PostPosted: Thu May 09, 2013 12:12 am
by dick scherrer
Hello,

Suggest you post the info BB requested . . .

Re: Sections inside Procedure division.

PostPosted: Thu May 09, 2013 2:20 pm
by BillyBoyo
Gokul,

"until EXIT or next Section comes".

Not really. EXIT does nothing.

    MOVE 1 TO A-FIELD
    PERFORM A-PARA
    DISPLAY A-FIELD
    GOBACK
    .

A-PARA.
    EXIT
    EXIT
    EXIT
    EXIT
    EXIT
    EXIT
    MOVE ZERO TO A-FIELD
    .


In changing from the use of SECTIONs just for the sake of it, you run the danger of wasting time and getting something different.

If the SECTIONs contain paragraphs, you're going to have to change to PERFORM ... THRU ... which is an ugly, inflexible, way to do it, and which is prone to several types of error.

Once a program is compiled, it is irrelevant whether there are SECTIONs or paragraphs in it. By that time it is just "object code", with Assembler versions of "go to" of various types.

The example of what you are proposing changing it to is useful to be able to highlight potential problems in making the change, which is set against none/very little benefit.

Re: Sections inside Procedure division.

PostPosted: Thu May 09, 2013 2:37 pm
by Robert Sample
SECTIONS in the PROCEDURE DIVISION were, in the early days of COBOL, used to help with overlaying code. Sections with the same priority number were kept together in the same segment so when code was swapped in and out of memory there would be less chance of memory reference errors. This is no longer part of Enterprise COBOL, but not knowing this could impact someone attempting to remove sections from a program. And gokulNmf, your understanding of sections is fatally flawed -- from the Language Reference manual 6.1.4:
A section ends immediately before the next section header, or at the end of the procedure division, or, in the declaratives portion, at the keywords END DECLARATIVES.

Segments
A segment consists of all sections in a program that have the same priority-number. Priority-number determines whether a section is stored in a fixed segment or an independent segment at run time.

Segments with a priority-number of 0 through 49 are fixed segments. Segments with a priority-number of 50 through 99 are independent segments.

The type of segment (fixed or independent) controls the segmentation feature.

In fixed segments, procedures are always in last-used state. In independent segments, procedures are in initial state each time the segment receives control from a segment with a different priority-number, except when the transfer of control results from the execution of a GOBACK or EXIT PROGRAM statement. Restrictions on the use of ALTER, SORT, and MERGE statements in independent segments are described under those statements.

Enterprise COBOL does not support the overlay feature of the Standard COBOL 85 segmentation module.
So the EXIT has nothing to do with the end of a SECTION; I've seen plenty of errors caused by code dropping through an exit paragraph because there was an improperly coded PERFORM statement.