In my code, I observed weird program flow when I added the keyword “SECTION” to a paragraph. Consider the following code as an example:
GO TO 100-EXIT.
In this code, the keyword “SECTION” is not used in 100-ERROR. In this case, when the control reaches GO TO 100-EXIT, it executes the 100-EXIT and returns to the next line from where 100-PROCESS section was called.
But when I added the keyword “SECTION” after 100-ERROR (so it will appear as 100-ERROR SECTION), the flow of the program changed. In this case, when the control reaches GO TO 100-EXIT, it executes the 100-EXIT, but after that it executes 200-PROCESS section, then 300-PROCESS section and so on.
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
Its been sometime since i have come across SECTION concept. I will tell what i remember.
SECTIONs can be considered to logical parititions within a DIVISION. In your case here SECTION is supposed to be logical divisions to your PROCEDURE division.
Now I hope u know the general difference between GOTO and PERFORM. The general idea is when we do a PERFORM statement to call a paragraph it executes the same and control returns back. When we do a GOTO para it executes the same para but continues the execution with the next paragraph in line.
When a PERFORM to a section is done ( in this case 100-PROCESS ), if i remember correctly, the whole SECTION is executed. In the example given above, you have basically given a GOTO within the SECTION. As far as the initial PERFORM is concerned the control is still within the SECTION hence after executing 100-EXIT it returns back to the statment after the PERFORM 100-PROCESS statement. Please note that if there were other paragraphs after 100-EXIT ( before the next SECTION ) it would execute those paragraphs also and then only return back to the initial PERFORM statment.
In the second case you have mentioned when you are doing a GOTO to a completely new SECTION, the initial PERFORM looses its flow as it has come out of the expected flow and hence the initial PERFORM is terminated. Hence after executing the 100-EXIT SECTION it continues on with the next paragraph.
Joined: 14 Jan 2008 Posts: 2504 Location: Atlanta, Georgia, USA
Procedure Division "SECTIONS" have been steadily falling out of favor, except when they are mandated, such as COBOL INPUT and OUTPUT SORT PROCEDURE SECTIONS. However, USING and GIVING t/w the FASTSRT compile option instead, seems to be more of the rule.
When compiling a program which uses SECTIONS and specifying the OPT compiler option, you'll find that the generated Load Module tends to be slightly larger than a program without SECTIONS, excluding the SORT PROCEDURE SECTIONS as outlined above.
FWIW, INPUT and OUTPUT SORT PROCEDURE SECTIONS are akin to E15 and E35 Sort Exits, respectively.
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix
However, USING and GIVING t/w the FASTSRT compile option instead, seems to be more of the rule.
Lots of code specifies using/giving - with or without fastsrt. This is usually because the people who implemented these did not understand input/output procedure or they had an extract process a sort and an output process and combined them into one set of code so they would not be required to document 3 steps or they were just plain lazy.
All of the timing tests i've seen or conducted show that input/out procedure performs better than using/giving. One reason is that using/giving requires at least 2 complete extra passes of all of the data.
FASTSRT can help the performance of code with using/giving but it does nothing for input/output procedure (at least not that i've seen).