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

COBOL code with GO TOs


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Apr 15, 2011 9:46 am
Reply with quote

Quote:
people starting out


Unfortuntely I get the impression that they will not be reading this thread because:
    they did not start it
    they do not understand it
    their code is correct
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 15, 2011 12:10 pm
Reply with quote

Nic Clouston wrote:
Quote:
people starting out


Unfortuntely I get the impression that they will not be reading this thread because:
    they did not start it
    they do not understand it
    their code is correct


Not so sure that we've covered anything particularly difficult so that it can't be understood. If there is anything unclear, or obscure, to anyone, feel free to ask.

Do you mean they think their code is correct?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Apr 15, 2011 12:15 pm
Reply with quote

Best inovation:

end construct
expansion of file-status


things that should be removed from cobol:

declaratives.

read .... at end
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Apr 16, 2011 4:32 am
Reply with quote

OK, this is winding down now. Further comments welcome, but over the weekend I'll try to summarise what has been contributed so far.

Thanks everyone. I enjoyed it.

Now, the next is really not for those with weak hearts. Novices, do not read beyond this point.

OK, I'm sure everyone has one of these, but if you've lost yours...

I apologise, I don't have access to a m/f so I can't test it. Used to work. Optimising off (might not be necessary, I never ran this through an optimiser. Should be OK, but safer off). Possibly CMPR2 but I dont' think so. From memory, but updated for "COBOL II". Sorry if it doesn't work. I've been poring over it, and I think I got everything.


Code:

01  A1-FG PIC X VALUE SPACE.
01  B1-FG PIC X VALUE SPACE.
01  C1-FG PIC X VALUE SPACE.


    PERFORM A
    IF A1-FG EQUAL TO "Y"
        DISPLAY "DO"
        GO TO G6
    END-IF
    .
G1.
    PERFORM B
    IF B1-FG EQUAL TO "Y"
        DISPLAY "DOO"
        GO TO G5
    END-IF
    .
G2.
    PERFORM C
    IF C1-FG EQUAL TO "Y"
        DISPLAY "IN DEEP"
        GO TO G4
    END-IF
    .
G3.


OK, so far not too bad. Some GO TOs, some paragraphs that look suspicious, but straight-forward logic?


Code:

G3.
    GO TO C5
    .
G4.
    GO TO B5
    .
G5.
    GO TO A5
    .
G6.
    MOVE +11 TO RETURN-CODE
    STOP RUN
    .



What the heck is that? As my son would say, quoting the film "Robots".

Code:



A SECTION.
    GO TO G1
    .
A5.
    MOVE "Y" TO A1-FG
    .
A9.
    EXIT.
B SECTION.
    GO TO G2
    .
B5.
    MOVE "Y" TO B1-FG
    .
B9.
    EXIT.
C SECTION.
    GO TO G3
    .
C5.
    MOVE "Y" TO C1-FG
    .
C9.
    EXIT.


Well, goodnes, gracious me. Ponder. Go on, copy-and-paste. Compile. Fingers crossed. Run it.

And no, I don't code my programs like that :-)

But you can get the effect through coding error (which gave me the idea for the program). Kind of like the one Dick mentioned in the original thread.
Back to top
View user's profile Send private message
Peter Nancollis

New User


Joined: 15 Mar 2011
Posts: 47
Location: UK

PostPosted: Sat Apr 16, 2011 4:58 am
Reply with quote

I will see your :
Code:


05 WS-ONE  PIC S9(2) COMP  VALUE +2.
. . .
ADD WS-ONE to WS-COUNT


and raise you a [yes it has run in prod -sigh! ]

Code:

           PERFORM X100-INCREMENT.
....
       X100-INCREMENT SECTION.
       X110-ADD-ONE.                                                           
           ADD 1 TO WS10-COUNTER.                                     
       X199-EXIT.                                                               
           EXIT. 


When I did COBOL, though [and No, its not my code - too structured : o) ] ...In-line performs (and lots lots more that has followed) werent even a twinkle in the compiler's eye

Now if we are collecting topics for venting spleens.... can I add Nested IFs
[at the risk of re-ignition ... more of a maint problem than GOTOs <g,d,r> ]
ttfn
Back to top
View user's profile Send private message
Peter Nancollis

New User


Joined: 15 Mar 2011
Posts: 47
Location: UK

PostPosted: Sat Apr 16, 2011 5:04 am
Reply with quote

Quote:

Do you mean they think their code is correct?

If the compile/lked ends 0000/0000 doesnt that mean all is well?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sun Apr 17, 2011 5:18 am
Reply with quote

Quote:

Compile. Fingers crossed. Run it.


Compiles, and works. I'd love to watch it in a debugger.

Peter, I re-raise. You forgot the comments naming the section, listing where it is performed from, listing what it performs, describing what it does. All in a "comment box" which makes sure you don't see a single line of code when you scroll to the section name. And then, of course, a comment for each line of the code. And at least 40% of the comments should be wrong.

z 7 7#all/*#del *#z 1 *#all

Mmmm... Comments next, or Nesting?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sun Apr 17, 2011 2:05 pm
Reply with quote

In summary:

There is good code and bad code. Language constructs are not inherently good or bad, they can be used well or poorly.

If you use GO TO, don't do stupid things that are only asking for trouble (like GO TO out of a para/section which is being PERFORMed).

If you avoid using GO TO, don't make the situation as bad going the other way. If it is clearer and more appropriate and avoids more complicated code, why not use GO TO?

Generally, we do avoid/limit use of GO TO.

Thanks to (first come, first served), GuyC, Bill O'Boyle, Akatsukami, don.leahy, prino, dbzTHEdinosauer, Ronald Burr, Peter Nancollis, Nic Clouston.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Apr 19, 2011 2:40 pm
Reply with quote

@Bill Woodger

Morning Sir !

I'm very pleased when i read your diskussion-blog about using a GOTO.

As i wrote in another topic, my narrow view of a matter is, that experienced programmers, with a minimum of intellect do not need to code a GOTO.

For my own, i do not code a "Branch-Inctruction" in my assembler programms. I use the old IBM Structured Makros wherever i can.

I appreciate this diskussion. I'm allways trying to learn something from such an exchange of experience. Even though i don't know if it's worth for me to do so for the last few years i have to work.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 19, 2011 3:06 pm
Reply with quote

Thank you, UmeySam, I was hoping to attract you to the discussion after your previous comment.

As you have seen from the discussion, mostly experienced people avoid GO TOs and definitely only use them with strict criteria.

People with less experience will not, in my mind, be helped simply by telling them what pieces of language to use, or not use, as this does not in itself, necessarily, of necessity, lead to good, maintainable, code.

As you are one of the more "hard line" who have commented, perhaps you can help out by descring how you deal with the "nesting" issues in the other discussion?

Thanks again.
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 Goto page Previous  1, 2

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts run rexx code with jcl CLIST & REXX 15
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Compile rexx code with jcl CLIST & REXX 6
Search our Forums:

Back to Top