Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Replacement for GO TO

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
tecnokrat
Warnings : 1

Active User


Joined: 22 May 2009
Posts: 158
Location: Bangalore

PostPosted: Mon Oct 25, 2010 3:39 pm    Post subject: Replacement for GO TO
Reply with quote

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
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Oct 25, 2010 3:49 pm    Post subject:
Reply with quote

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
View user's profile Send private message
CaptBill

New User


Joined: 28 May 2009
Posts: 15
Location: Oklahoma City, OK USA

PostPosted: Tue Oct 26, 2010 8:16 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Tue Oct 26, 2010 8:28 pm    Post subject:
Reply with quote

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. icon_cry.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Oct 26, 2010 8:46 pm    Post subject:
Reply with quote

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
View user's profile Send private message
CaptBill

New User


Joined: 28 May 2009
Posts: 15
Location: Oklahoma City, OK USA

PostPosted: Wed Oct 27, 2010 4:08 am    Post subject:
Reply with quote

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. icon_cry.gif


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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Oct 27, 2010 5:32 am    Post subject:
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Wed Oct 27, 2010 1:45 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Wed Oct 27, 2010 3:06 pm    Post subject:
Reply with quote

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". icon_smile.gif
Back to top
View user's profile Send private message
mtaylor

Active User


Joined: 20 Feb 2009
Posts: 108
Location: Kansas City

PostPosted: Wed Oct 27, 2010 6:28 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Wed Oct 27, 2010 6:53 pm    Post subject:
Reply with quote

And it is so much fun to say "Dijkstra".

(I looked for a pronunciation tag but couldn't find it.)
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Oct 27, 2010 6:56 pm    Post subject:
Reply with quote

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). icon_eek.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Wed Oct 27, 2010 6:59 pm    Post subject: Reply to: Replacement for GO TO
Reply with quote

according to some formal language theory
the COME FROM construct is more structured than the GO TO
meditate folks, meditate icon_biggrin.gif
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Oct 27, 2010 7:01 pm    Post subject:
Reply with quote

Enrico,

the word COME always has a emotionally charged meaning. icon_redface.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Wed Oct 27, 2010 7:03 pm    Post subject: Reply to: Replacement for GO TO
Reply with quote

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 icon_biggrin.gif
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Oct 27, 2010 7:06 pm    Post subject:
Reply with quote

Enrico,

you are rigth there, robbing was something we almost invented 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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Replacement FTP to SFTP Vasili Koipish All Other Mainframe Topics 1 Wed May 11, 2016 3:10 pm
No new posts DFHEMTA replacement Praveenkumar Natarajan CICS 8 Thu Feb 28, 2013 3:08 pm
No new posts Conditional replacement of output file gcicchet JCL & VSAM 2 Fri Apr 29, 2011 10:05 am
No new posts outrec character replacement John Howard JCL & VSAM 10 Wed May 12, 2010 7:15 pm
No new posts substring replacement in a record sudarsanreddyk DFSORT/ICETOOL 3 Mon Mar 23, 2009 11:17 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us