View previous topic :: View next topic
|
Author |
Message |
nirmal arthur
New User
Joined: 26 Jun 2008 Posts: 8 Location: Hyderabad
|
|
|
|
Hi, Please look at the code snippets below.
Code 1:
Para1 section.
perform para2 until count>10.
Para2 section.
move ws-data to ws-load(count)
add 1 to count.
Para3.
Code 2:
Para1 section.
perform para2 until count>10.
Para2.
move ws-data to ws-load(count)
add 1 to count.
Para3.
Code 3:
Para1.
perform para2 until count>10.
Para2.
move ws-data to s-load(count)
add 1 to count.
Para3.
For code 1 and code 2 the control is not returning to para 1 after executing para 2. It would just increment the count by 1 for the first time and then execute para 3. Only for code 3 would the control return to para 1. But i was under the impression that the control would return to para 1 even when a para is defined as a section. Please correct me if iamb wrong. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Whenever a section is PERFORMed COBOL will generate its own (hidden) EXIT instruction when the next section-name is encountered....
If a section-name in your source file has the word SECTION missing, COBOL will treat it as a continuation of the preceding section ... here para 3 does not have a section verb with it ..so cobol will treat it to be a continuation to para2 section .... |
|
Back to top |
|
|
nirmal arthur
New User
Joined: 26 Jun 2008 Posts: 8 Location: Hyderabad
|
|
|
|
Thanks ashimer. But in code 2 also the control wasn't returning to para 1 after executing para 2. Here para 2 is not defined as a section. Can you tell me why this was happening? |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
in code 2 para 2 will be considered as continuation to para 1 as para 2 is not mentioned as a section and it executes para 2 followed by para 3 .... |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
try specifying EXIT for each section ...
para1 section.
....
...
exit para1.
para2.
....
.... |
|
Back to top |
|
|
nirmal arthur
New User
Joined: 26 Jun 2008 Posts: 8 Location: Hyderabad
|
|
|
|
Yeah but there is a perform in para 1 and the control was going to para 2. So the control wont come back to para 1 since it is defined as a section?? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
How can you tell it's not returning to para1? And if the code is specified as you have it, how do you prevent the program from doing the perform, returning to para1, and then falling through into para2 again? |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Use exit for each section ..it will work ..or else dont define any para ..define all as sections.... |
|
Back to top |
|
|
nirmal arthur
New User
Joined: 26 Jun 2008 Posts: 8 Location: Hyderabad
|
|
|
|
Hi Robert,
I had put it through intertest and thus i know that the control is not returning to para 1.
You are right. The code will come to para 2 once para 1 is done. I know this is a bad code according to the standards. But im not looking for a solution. I already have the code up and working as per the requirement. Thing is i want to know the reason. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Thing is i want to know the reason |
Probably not the answer you want, but the reason is that the code is functioning exactly as it was written. . . and as it is supposed to according to the rules of cobol. . .
If you use the "IBM Manuals" link at the top of the page, there is much more info in the COBOL documentation. If you find something in the manual(s) that is not clear, post it here and we may be able to help clarify. |
|
Back to top |
|
|
nirmal arthur
New User
Joined: 26 Jun 2008 Posts: 8 Location: Hyderabad
|
|
|
|
Thanks dick. I did look up in the manuals for 'section' and 'para' but nothing was said about when the control would return and when it wouldn't. If only you would give me the right link.... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Did you follow the test through a few iterations? Perform control works by jumping to the paragraph, executing, then jumping back to the calling PERFORM to do the UNTIL logic check. Then if the logic says to perform again (UNTIL not satisfied), the jump to the paragraph occurs again. This repeats until the UNTIL clause is satisfied. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what is the value of count at the begining of the start of code 2?????????do you ever initialize count???? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
In code 1 para2 is a section so when you perform para2 that includes para2 and para3 since para3 is part of para2 section.
In code 2 and code 3 para2 is paragraph so when you perform para2 that is all that gets performed. |
|
Back to top |
|
|
|