IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How and when to use keyword "SECTION"?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ankit.jain

New User


Joined: 02 Jul 2009
Posts: 18
Location: Mumbai

PostPosted: Thu Jul 02, 2009 11:19 am
Reply with quote

Hi,

In my code, I observed weird program flow when I added the keyword “SECTION” to a paragraph. Consider the following code as an example:

100-PROCESS SECTION.
<steps>
GO TO 100-EXIT.
100-ERROR.
<steps>
100-EXIT.
EXIT.

200-PROCESS SECTION.
<steps>
200-EXIT.
EXIT.

300-PROCESS SECTION.
<steps>
300-EXIT.
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.

Is this correct and why does it happen?

Thanks in advance,
Ankit Jain
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Jul 02, 2009 12:27 pm
Reply with quote

Hi Ankit,

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.

Hope i have been of help.
Back to top
View user's profile Send private message
ankit.jain

New User


Joined: 02 Jul 2009
Posts: 18
Location: Mumbai

PostPosted: Thu Jul 02, 2009 1:53 pm
Reply with quote

Thanks a lot Binop, your explanation is really helpful and I appreciate the way you explained it.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Jul 02, 2009 1:57 pm
Reply with quote

Nice to hear that... icon_biggrin.gif
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 02, 2009 4:45 pm
Reply with quote

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.

Regards,
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jul 02, 2009 8:22 pm
Reply with quote

Hello,

Quote:
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).
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 02, 2009 8:32 pm
Reply with quote

Thanks Dick. I had thought just the opposite in regards to performance as IBM touts USING/GIVING as a faster way to perform sorts in COBOL.

Yes and that's a true statement that FASTSRT has no effect on INPUT and OUTPUT Procedures.

Heaven forbid, but do you think they've not been entirely forthcoming regarding USING/GIVING? icon_rolleyes.gif

Never would have thunk it.... icon_eek.gif

Regards,
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 02, 2009 8:49 pm
Reply with quote

IBM touting something that increases the need for hardware? Who woulda thunk it? icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts PuTTY - "User is not a surrogate... IBM Tools 5
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts Newbie Stuck on "Duplicate Datas... TSO/ISPF 5
No new posts RABBIT HOLE NEEDED - "Live"... All Other Mainframe Topics 0
Search our Forums:

Back to Top