Discussion:
COBOL in Tandem
(too old to reply)
Andre White
2016-08-31 17:58:43 UTC
Permalink
Hi Guys,

I have question about COBOL. I'm not expert in cobol . Currently i'm doing/Writing cobol program with my style. And then some people on different team, complaining my code style. My question is:

1. In my code if i call PERFORM procedure, i'm not included THRU EXIT. Because they style in current
program (COBOL). They always used PERFORM A-100-XXX THRU A-100-EXIT. If they give me the good
reason whey I "MUST" included THRU EXIT in my program, I will follow what they asking to me. I don't
know if they just COPY PASTE from the previous programmer or they don't know the reason.
2. About the Section, in my program they also complaining if i'm used SECTION in my code. for Example:

PROCEDURE DIVISION.
MAIN SECTION.
BEGIN-COBOL-SERVER.
.................
EVALUATE MSG-RQST
WHEN "RA" * If user want to retrieve all customer data *
A100-PROCESS-RET
WHEN "RC" * Just retrieve the account number *
A100-PROCESS-ACCOUNT
WHEN "RM" * Just retrieve the amount *
A100-PROCESS-RET-AMOUNT.
WHEN OTHER
..........
END-EVALUATE.
STOP.


?SECTION A100-PROCESS
A100-PROCESS-RET SECTION.
A100-PROCESS-RET-ACCOUNT.
..................................................
.................................................
.................................................
IF WS-ACCT = "S" THEN * if account is suspended, stop the process *
GOTO A100-EXIT
END-IF.
................................................
...............................................
.
* END OF PARAGRAPH A100-PROCESS-RET-ACCOUNT *

A100-PROCESS-RET-AMOUNT.
................................................
................................................
................................................
.
* END OF PARAGRAPH A100-PROCESS-RET-AMOUNT *

A100-EXIT.
EXIT.



Anybody can explain to me, is not good if i'm using section in my code.


Thanks guys for your reply.

Cheers.
Keith Dick
2016-09-01 14:27:29 UTC
Permalink
If the organization has coding standards, whether formally written down or just informally agreed on by the group, follow those standards!

The reason is so that when someone has to read or modify your code, they will not get confused because the code's style is different from all the other code they are dealing with. Understanding someone else's code is hard enough without having to deal with varying styles of coding.

The above should be enough to end your kvetching about following the style your organization uses, but I can give you at least one reason why they prefer the style they are telling you to use. The PERFORM A THRU B. form, where A and B are paragraph names, and B is an "exit paragraph" (one that contains only an EXIT statement) is preferred because if the paragraph has to be modified to include an early exit when some special condition is found, a common way to do that is to use a GO TO the exit paragraph name. If the PERFORM was set up they way you like, there would be no exit paragraph. So the programmer would have to add an exit paragraph, and then go find all of the PERFORMs of that paragraph and modify them to add the THRU part. If he misses some of the PERFORMs that should be changed, no error messages would appear to point out the problem. If a PERFORM is not changed, then when the early exit is taken, the GO TO jumps beyond the end of the PERFORMed paragraph and t
he PERFORM does not return (because control never reaches the end of the PERFORMed paragraph). It is much better to start off always using the PERFORM A THRU B form so adding an early exit does not require finding and modifying all the PERFORM statements for the paragraph.


I'm not sure I understand your example 2. It probably doesn't matter, since, as I mentioned above, if your organization's coding standard says not to use sections, you should refrain from using sections. But let's look at your example, anyway. In the EVALUATE statement are those names in the WHEN parts supposed to be PERFORM statements? I'll assume the answer is "yes". So I guess you group the individual paragraphs that each retrieve one piece of information into a section so you can retrieve all the pieces of information by performing the section. That might seem clever, however if some later modification to the program involves adding a paragraph that must be performed from one of the paragraphs that returns one piece of information, the natural place to put that new paragraph would be following the paragraph that PERFORMs it. Unfortunately, that would mess things up when you PERFORM the section to get all of the pieces of information, since that new paragraph would
get executed when it is not supposed to be executed when control falls through from the paragraph above it. So I think the idea of grouping all the individual paragraphs that return one piece of information into a section isn't so clever.

That problem could be avoided by putting the new paragraph into yet another section so it is not part of the section that groups the paragraphs that return the individual pieces of information, but for someone not used to structuring the program as you did, they easily might not think of that.

Do you see a common theme here? The reason for having and following coding standards is to avoid problems when the code has to be worked on later. The group decides on certain ways of doing things so that anyone reading the code can understand what it does quickly (because it follows the common style) and so that when changes are made to the code, there are fewer chances for the change to break something.
Post by Andre White
Hi Guys,
1. In my code if i call PERFORM procedure, i'm not included THRU EXIT. Because they style in current
program (COBOL). They always used PERFORM A-100-XXX THRU A-100-EXIT. If they give me the good
reason whey I "MUST" included THRU EXIT in my program, I will follow what they asking to me. I don't
know if they just COPY PASTE from the previous programmer or they don't know the reason.
PROCEDURE DIVISION.
MAIN SECTION.
BEGIN-COBOL-SERVER.
.................
EVALUATE MSG-RQST
WHEN "RA" * If user want to retrieve all customer data *
A100-PROCESS-RET
WHEN "RC" * Just retrieve the account number *
A100-PROCESS-ACCOUNT
WHEN "RM" * Just retrieve the amount *
A100-PROCESS-RET-AMOUNT.
WHEN OTHER
..........
END-EVALUATE.
STOP.
?SECTION A100-PROCESS
A100-PROCESS-RET SECTION.
A100-PROCESS-RET-ACCOUNT.
..................................................
.................................................
.................................................
IF WS-ACCT = "S" THEN * if account is suspended, stop the process *
GOTO A100-EXIT
END-IF.
................................................
...............................................
.
* END OF PARAGRAPH A100-PROCESS-RET-ACCOUNT *
A100-PROCESS-RET-AMOUNT.
................................................
................................................
................................................
.
* END OF PARAGRAPH A100-PROCESS-RET-AMOUNT *
A100-EXIT.
EXIT.
Anybody can explain to me, is not good if i'm using section in my code.
Thanks guys for your reply.
Cheers.
Rich S.
2016-09-15 13:44:26 UTC
Permalink
Post by Keith Dick
If the organization has coding standards, whether formally written down or just informally agreed on by the group, follow those standards!
The reason is so that when someone has to read or modify your code, they will not get confused because the code's style is different from all the other code they are dealing with. Understanding someone else's code is hard enough without having to deal with varying styles of coding.
The above should be enough to end your kvetching about following the style your organization uses, but I can give you at least one reason why they prefer the style they are telling you to use. The PERFORM A THRU B. form, where A and B are paragraph names, and B is an "exit paragraph" (one that contains only an EXIT statement) is preferred because if the paragraph has to be modified to include an early exit when some special condition is found, a common way to do that is to use a GO TO the exit paragraph name. If the PERFORM was set up they way you like, there would be no exit paragraph. So the programmer would have to add an exit paragraph, and then go find all of the PERFORMs of that paragraph and modify them to add the THRU part. If he misses some of the PERFORMs that should be changed, no error messages would appear to point out the problem. If a PERFORM is not changed, then when the early exit is taken, the GO TO jumps beyond the end of the PERFORMed paragraph and t
he PERFORM does not return (because control never reaches the end of the PERFORMed paragraph). It is much better to start off always using the PERFORM A THRU B form so adding an early exit does not require finding and modifying all the PERFORM statements for the paragraph.
I'm not sure I understand your example 2. It probably doesn't matter, since, as I mentioned above, if your organization's coding standard says not to use sections, you should refrain from using sections. But let's look at your example, anyway. In the EVALUATE statement are those names in the WHEN parts supposed to be PERFORM statements? I'll assume the answer is "yes". So I guess you group the individual paragraphs that each retrieve one piece of information into a section so you can retrieve all the pieces of information by performing the section. That might seem clever, however if some later modification to the program involves adding a paragraph that must be performed from one of the paragraphs that returns one piece of information, the natural place to put that new paragraph would be following the paragraph that PERFORMs it. Unfortunately, that would mess things up when you PERFORM the section to get all of the pieces of information, since that new paragraph would
get executed when it is not supposed to be executed when control falls through from the paragraph above it. So I think the idea of grouping all the individual paragraphs that return one piece of information into a section isn't so clever.
That problem could be avoided by putting the new paragraph into yet another section so it is not part of the section that groups the paragraphs that return the individual pieces of information, but for someone not used to structuring the program as you did, they easily might not think of that.
Do you see a common theme here? The reason for having and following coding standards is to avoid problems when the code has to be worked on later. The group decides on certain ways of doing things so that anyone reading the code can understand what it does quickly (because it follows the common style) and so that when changes are made to the code, there are fewer chances for the change to break something.
Post by Andre White
Hi Guys,
1. In my code if i call PERFORM procedure, i'm not included THRU EXIT. Because they style in current
program (COBOL). They always used PERFORM A-100-XXX THRU A-100-EXIT. If they give me the good
reason whey I "MUST" included THRU EXIT in my program, I will follow what they asking to me. I don't
know if they just COPY PASTE from the previous programmer or they don't know the reason.
PROCEDURE DIVISION.
MAIN SECTION.
BEGIN-COBOL-SERVER.
.................
EVALUATE MSG-RQST
WHEN "RA" * If user want to retrieve all customer data *
A100-PROCESS-RET
WHEN "RC" * Just retrieve the account number *
A100-PROCESS-ACCOUNT
WHEN "RM" * Just retrieve the amount *
A100-PROCESS-RET-AMOUNT.
WHEN OTHER
..........
END-EVALUATE.
STOP.
?SECTION A100-PROCESS
A100-PROCESS-RET SECTION.
A100-PROCESS-RET-ACCOUNT.
..................................................
.................................................
.................................................
IF WS-ACCT = "S" THEN * if account is suspended, stop the process *
GOTO A100-EXIT
END-IF.
................................................
...............................................
.
* END OF PARAGRAPH A100-PROCESS-RET-ACCOUNT *
A100-PROCESS-RET-AMOUNT.
................................................
................................................
................................................
.
* END OF PARAGRAPH A100-PROCESS-RET-AMOUNT *
A100-EXIT.
EXIT.
Anybody can explain to me, is not good if i'm using section in my code.
Thanks guys for your reply.
Cheers.
FWIW and IMHO When I coded COBOL on NonStop, I would never use PERFORM A THRU B. I fixed too many cases where someone copied a paragraph and forgot to change a GOTO within the block. Instead I would just use the EXIT PARAGRAPH statement if it was necessary to leave the paragraph early.
wbreidbach
2016-09-16 07:29:19 UTC
Permalink
Post by Rich S.
Post by Keith Dick
If the organization has coding standards, whether formally written down or just informally agreed on by the group, follow those standards!
The reason is so that when someone has to read or modify your code, they will not get confused because the code's style is different from all the other code they are dealing with. Understanding someone else's code is hard enough without having to deal with varying styles of coding.
The above should be enough to end your kvetching about following the style your organization uses, but I can give you at least one reason why they prefer the style they are telling you to use. The PERFORM A THRU B. form, where A and B are paragraph names, and B is an "exit paragraph" (one that contains only an EXIT statement) is preferred because if the paragraph has to be modified to include an early exit when some special condition is found, a common way to do that is to use a GO TO the exit paragraph name. If the PERFORM was set up they way you like, there would be no exit paragraph. So the programmer would have to add an exit paragraph, and then go find all of the PERFORMs of that paragraph and modify them to add the THRU part. If he misses some of the PERFORMs that should be changed, no error messages would appear to point out the problem. If a PERFORM is not changed, then when the early exit is taken, the GO TO jumps beyond the end of the PERFORMed paragraph and t
he PERFORM does not return (because control never reaches the end of the PERFORMed paragraph). It is much better to start off always using the PERFORM A THRU B form so adding an early exit does not require finding and modifying all the PERFORM statements for the paragraph.
I'm not sure I understand your example 2. It probably doesn't matter, since, as I mentioned above, if your organization's coding standard says not to use sections, you should refrain from using sections. But let's look at your example, anyway. In the EVALUATE statement are those names in the WHEN parts supposed to be PERFORM statements? I'll assume the answer is "yes". So I guess you group the individual paragraphs that each retrieve one piece of information into a section so you can retrieve all the pieces of information by performing the section. That might seem clever, however if some later modification to the program involves adding a paragraph that must be performed from one of the paragraphs that returns one piece of information, the natural place to put that new paragraph would be following the paragraph that PERFORMs it. Unfortunately, that would mess things up when you PERFORM the section to get all of the pieces of information, since that new paragraph would
get executed when it is not supposed to be executed when control falls through from the paragraph above it. So I think the idea of grouping all the individual paragraphs that return one piece of information into a section isn't so clever.
That problem could be avoided by putting the new paragraph into yet another section so it is not part of the section that groups the paragraphs that return the individual pieces of information, but for someone not used to structuring the program as you did, they easily might not think of that.
Do you see a common theme here? The reason for having and following coding standards is to avoid problems when the code has to be worked on later. The group decides on certain ways of doing things so that anyone reading the code can understand what it does quickly (because it follows the common style) and so that when changes are made to the code, there are fewer chances for the change to break something.
Post by Andre White
Hi Guys,
1. In my code if i call PERFORM procedure, i'm not included THRU EXIT. Because they style in current
program (COBOL). They always used PERFORM A-100-XXX THRU A-100-EXIT. If they give me the good
reason whey I "MUST" included THRU EXIT in my program, I will follow what they asking to me. I don't
know if they just COPY PASTE from the previous programmer or they don't know the reason.
PROCEDURE DIVISION.
MAIN SECTION.
BEGIN-COBOL-SERVER.
.................
EVALUATE MSG-RQST
WHEN "RA" * If user want to retrieve all customer data *
A100-PROCESS-RET
WHEN "RC" * Just retrieve the account number *
A100-PROCESS-ACCOUNT
WHEN "RM" * Just retrieve the amount *
A100-PROCESS-RET-AMOUNT.
WHEN OTHER
..........
END-EVALUATE.
STOP.
?SECTION A100-PROCESS
A100-PROCESS-RET SECTION.
A100-PROCESS-RET-ACCOUNT.
..................................................
.................................................
.................................................
IF WS-ACCT = "S" THEN * if account is suspended, stop the process *
GOTO A100-EXIT
END-IF.
................................................
...............................................
.
* END OF PARAGRAPH A100-PROCESS-RET-ACCOUNT *
A100-PROCESS-RET-AMOUNT.
................................................
................................................
................................................
.
* END OF PARAGRAPH A100-PROCESS-RET-AMOUNT *
A100-EXIT.
EXIT.
Anybody can explain to me, is not good if i'm using section in my code.
Thanks guys for your reply.
Cheers.
FWIW and IMHO When I coded COBOL on NonStop, I would never use PERFORM A THRU B. I fixed too many cases where someone copied a paragraph and forgot to change a GOTO within the block. Instead I would just use the EXIT PARAGRAPH statement if it was necessary to leave the paragraph early.
I have never used "Perform <paragraph>", I always used "Perform <section>" and GO TO was strictly forbidden. If you want to leave the section "exit section" will do. And I totally agree to Rich that copying a paragraph (same with a section) that contains a GO TO can lead to a completely unexpected behaviour.
Andre White
2016-09-18 16:01:51 UTC
Permalink
Hi Keith, Rich, and wbreidbach thanks for your's reply.

I agree with Rich and wbreidbach. Because after I learn cobol, I don't want to use PERFORM A THRU B. But my leader said I must follow the existing style(If she a good programmer or she previous worked in NonStop, IBM, ACI Omaha(not ACI from ASIA), etc. I will follow her, but she just programmer "COPY PASTE" ). And then I must recode my coded from SECTION and changed use PARAGRAPH. I hope she will read my post, if she in this group.
d***@gmail.com
2016-09-19 10:21:54 UTC
Permalink
In 30+ years of Cobol coding I have never used a SECTION statement, only PERFORM <paragraph> and the paragraphs were preceded by numbers to visibly group them together for ease of reading. Early exit from a paragraph is handled by well designed code. I agree with Keith that if there is a formal coding standard or even an existing code base, you should not express your artistic skills, just conform to the norm.
wbreidbach
2016-09-19 11:58:56 UTC
Permalink
Post by d***@gmail.com
In 30+ years of Cobol coding I have never used a SECTION statement, only PERFORM <paragraph> and the paragraphs were preceded by numbers to visibly group them together for ease of reading. Early exit from a paragraph is handled by well designed code. I agree with Keith that if there is a formal coding standard or even an existing code base, you should not express your artistic skills, just conform to the norm.
It has been a while ago that I wrote my last COBOL program, I wrote my first COBOL program more than 40 years ago. During those years I have worked for several companies and most of these companies had a specific "standard". And if there is such a standard you have to create the programs according to it.
That is just the way it is.
In my eyes the most important thing is that the code is "readable", maybe I (or worse someone else) need to understand the program I created 5 or more years ago.
Wolfgang

Loading...