View previous topic :: View next topic
|
Author |
Message |
tecnokrat Warnings : 1 Active User
Joined: 22 May 2009 Posts: 160 Location: Bangalore
|
|
|
|
Hi i have a problem in coding
Requirement is that LINK to a module should be made only if Flag1 is set
if the flag2 is set the whole para is to be skipped.
Code: |
XXXX-PARA.
EVALUATE TRUE
WHEN FLAG1
<<parms of called program is filled pertained to falg1>>
WHEN FLAG2
<<parms of called program is filled pertained to flag2>>
WHEN OTHER
continue
END-EVALUATE.
EXEC CICS
LINK PROG(PRG1)
COMMAREA
LENGTH
END-EXEC.
XXX-PARA-END. |
Now here the program prg1 is to be linked only if the Flag1 is set flag2 is to be removed.
i can get a solution by placing a GO TO statement but that is not preferrable as its a coding standard.
can you please help me for placing me other function which bypasses the and reaches XXX-PARA-END.
Code: |
XXXX-PARA.
EVALUATE TRUE
WHEN FLAG1
<<parms of called program is filled pertained to falg1>>
WHEN FLAG2
GO TO XXXX-PARA-END
WHEN OTHER
continue
END-EVALUATE.
EXEC CICS
LINK PROG(PRG1)
COMMAREA
LENGTH
END-EXEC.
XXX-PARA-END.
|
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
I'm not sure if I get it correctly what you actually mean. To me, it looks like that if you use the below code, you are actually done with what you're looking for:
Code: |
XXXX-PARA.
EVALUATE TRUE
WHEN FLAG1
<<parms of called program is filled pertained to falg1>>
EXEC CICS
LINK PROG(PRG1)
COMMAREA
LENGTH
END-EXEC
WHEN FLAG2
continue
WHEN OTHER
continue
END-EVALUATE.
XXX-PARA-END. |
|
|
Back to top |
|
|
CaptBill
New User
Joined: 28 May 2009 Posts: 20 Location: Oklahoma City, OK USA
|
|
|
|
Edsger Dijkstra in his paper "A Case Against The GO TO Statement" said:
"The unbridled use of the go to statement has as an immediate consequence that it becomes terribly hard to find a meaningful set of coordinates in which to describe the process progress." [Bolding is mine]
This does not mean you cannot use GO TO, it means you should control it very tightly. Using GO TO to exit a module to an exit paragraph is perfectly valid. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Bill I agree with what you have said, however, what would you do with the "site-standards"!? At one of my sites, even if I've written the COBOL code with best usage of GO TO - they will just reject my code during code-reviews because they made a rule not-to-use Go To at all. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Anuj,
to quote CaptBill from a couple of years ago,
'People who don't allow goto statements are idiots'.
(approx quote).
i, by the way, am one of those idiots, but when I am in a legacy module,
i refuse to rewrite all the spegetti code and will resort to goto's myself.
for new development, I perfer small modules, that perform 1 function.
need for goto is small.
only problem with goto exit is that some many idiots perform thru the exit.
and for that reason, many installations do not allow goto's. |
|
Back to top |
|
|
CaptBill
New User
Joined: 28 May 2009 Posts: 20 Location: Oklahoma City, OK USA
|
|
|
|
Anuj Dhawan wrote: |
Bill I agree with what you have said, however, what would you do with the "site-standards"!? At one of my sites, even if I've written the COBOL code with best usage of GO TO - they will just reject my code during code-reviews because they made a rule not-to-use Go To at all. |
Since your example code is from a CICS program, scan it to see where GO TO is used. CICS makes use of lots of GO TO's. Scan the generated code listing, not the source code to the compile. Making rules that are like the one you have is an example of poor management misreading the paper by Dijkstra. Again the uncontrolled use of GO TO is bad, but not all uses of GO TO are bad.
dbzTHEdinosauer wrote: |
Posted: Tue Oct 26, 2010 8:46 pm Post subject:
--------------------------------------------------------------------------------
Anuj,
to quote CaptBill from a couple of years ago,
'People who don't allow goto statements are idiots'.
(approx quote). |
I tried to find this quote but couldn't. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Making rules that are like the one you have is an example of poor management |
And most of these never heard of Dijkstra. . .
Once upon a time (35 years ago or so) many became completely enamored with "Structured Programming" (one of the better concepts to appear - imho). Unfortunately very many well-meaning fools decided that Structured = GOTOless. And this was foisted on mony organizations and training classes.
All i can say from experience is that i've seen some exceptionally well-structured code that contains GO TOs. The single worst piece of spaghetti i've ever seen contained NO GO TOs, but did contain more than 20 "switches" to control processing. It was basically a 2-file match/update (master and transacton in, new master out with audit trail. It had 7 reads of the master file and 5 of the transacton file and was quite fragile. The developer left the company and i told his boss that i'd re-write it but wouldn't maintain it. . . The original program was about 4500 "cards" and the re-write was less than 1000.
As part of the standards development group, i still like the GO TO rules we established:
. To a label when a file reached EOF.
. To the EXIT of a performed routine.
. To the top of the same routine performed routine.
. To an abend routine (that actually abends after any "cleanup" like a backout).
. To prevent the unbearable paging of very large modules
We didn't dictate whether PERFORM THRU was acceptable - just that the code be consistent. Those that hated THRU didn't have to use it - those that preferred THRU could. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
just nitpicking : evaluate could be replaced by a simple IF
Code: |
XXXX-PARA.
IF FLAG1
<<parms of called program is filled pertained to falg1>>
EXEC CICS
LINK PROG(PRG1)
COMMAREA
LENGTH
END-EXEC
END-IF.
XXX-PARA-END. |
To add to the discussion: There 's nothing wrong with good go to's,
as long as you have single-entry, single-exit (besides abend).
unfortunately good goto's can turn sour very fast, when they start violating the single-exit rule |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
CaptBill wrote: |
Since your example code is from a CICS program, scan it to see where GO TO is used. |
I'm not the Origianl Poster, Bill. Just chipped in the thread...
And thanks for brining in the discussion on "Dijkstra". |
|
Back to top |
|
|
mtaylor
Active User
Joined: 20 Feb 2009 Posts: 108 Location: Kansas City
|
|
|
|
Re Goto: the uses where goto is "acceptable" have been integrated into new languages with keywords like continue (jump to the end of a loop), break (exit a loop), and try/catch/finally blocks for exception handling. For example, Java doesn't have a goto, but it has all the above which are essentially goto's. I think C# has a goto, but I'm not sure what it's semantics are. C/C++/Obj C all have goto.
So the case can be made that goto is very much alive and well only it's not recognized as such. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
And it is so much fun to say "Dijkstra".
(I looked for a pronunciation tag but couldn't find it.) |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Phrzby Phil wrote: |
And it is so much fun to say "Dijkstra".
(I looked for a pronunciation tag but couldn't find it.) |
Its never fun to talk in such a way about Dutch people, most of the time
people show lots of respect for us the Dutch (by bowing, taking hats of,
paying lots of money etc). |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
according to some formal language theory
the COME FROM construct is more structured than the GO TO
meditate folks, meditate |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Enrico,
the word COME always has a emotionally charged meaning. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Quote: |
... most of the time people show lots of respect for us the Dutch
(by bowing, taking hats of, paying lots of money etc). |
Nahhh
it related to the Flying Dutchman syndrome
it' a play safe behavior ...
it better to bow, take hats off, paying a bit of money rather than
being beaten to death and robbed of everything |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Enrico,
you are rigth there, robbing was something we almost invented |
|
Back to top |
|
|
|