Pete Dashwood
unread,Apr 25, 2013, 9:44:25 PM4/25/13You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hi Kevin,
Kerry has explained your problem, but I thought I'd add something about
nested IFs which might help you and others:
Dashwood's guidelines for NESTING COBOL IF:
1. Use nested IFs ONLY to represent a "decision tree".
2. Nest ONLY into the TRUE branches. (I confess to some rare cases where I
have used the FALSE branch but doing this is "best avoided")
3. DON"T embed other statements into the TRUE or FALSE branches. (See
example following)
4. Use scope delimiters, not periods (full stops).
5. Don't nest to too many levels. ("too many" is determined by what you can
see... if your nested IF goes over pages, rethink it.)
OK, here's a decision tree (in English):
If condition 1 is true AND condition 2 is true AND condition 3 is true, I
want to do action 1. But, if condition 1 is true AND condition 2 is true AND
condition 3 is NOT true, I want to do action 2, and if condition 1 is true
AND condition 2 is NOT true, I want to do action 3, and if condition 1 is
NOT true I just want to carry on (do nothing).
Note that there is a dependency between the conditions and we don't even
want to look at lower levels if upper levels are not true.
Here it is translated into COBOL:
IF c1
IF c2
IF c3
action 1
ELSE
action 2
END-IF
ELSE
action 3
END-IF
END-IF
Note there is no other code embedded in the IF branches... like this:
IF c1
PERFORM...
COMPUTE...
IF c2
READ... etc.
Although the above is perfectly legal and COBOL supports it well, it isn't
very long before the code becomes cluttered and error-prone. Experienced
COBOL programmers can manage it but beginners will find it bewildering and
(especially if scope delimiters haven't been used) they will make logic
errors.
I can't prove it, but I suspect that anything nested in this way could be
broken into simpler IF or EVALUATE statements and so nothing is really
gained by doing it. Perhaps the same is true for my decision tree.
Finally, an example from back in the day, before we had EVALUATE. I have a
variable (call it "ReEntryIndicator") which can have the values 1 thru 3.
This was sometimes used for switching serial reuse on re-entry. Obviously, I
used GO TO...DEPENDING, but some sites came to frown on this, so the nested
IF was one possible alternative.
(I want my decision tree to only be nested in the TRUE branches so I negate
the conditions... like this:)
IF ReEntryIndicator NOT = '1'
IF ReEntryIndicator NOT = '2'
IF ReEntryIndicator NOT = '3
' PERFORM BadReEntryIndicator
ELSE
GO TO Entry3
END-IF
ELSE
GO TO Entry2
END-IF
ELSE
GO TO Entry1
END-IF
Looking with today's eyes, this is not something you would want or need to
do, but it serves to demonstrate what I'm saying about nested IFs.
Hope this helps somebody...
Pete.
--
"I used to write COBOL...now I can do anything."