For Programmers: Free Programming Magazines  


Home > Archive > Cobol > June 2004 > COBOL ABBREVIATED CONDITION









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author COBOL ABBREVIATED CONDITION
Thomas A. Li

2004-06-16, 8:55 pm

I'm reading COBOL program and can't make sure the meaning of the following
abbreviated condition:

If A NOT = B AND NOT C

Is it equivalent to

If A NOT = B AND A = C

or

If A NOT = B AND A NOT = C ???



Thanks in advance.



Thomas Li




Hugh Candlin

2004-06-16, 8:55 pm


Thomas A. Li <tli@corporola.com> wrote in message news:SN1Ac.4490$7C%1.498@news04.bloor.is.net.cable.rogers.com...
> I'm reading COBOL program and can't make sure the meaning of the following
> abbreviated condition:
>
> If A NOT = B AND NOT C
>
> Is it equivalent to
>
> If A NOT = B AND A = C


No

>
> or
>
> If A NOT = B AND A NOT = C ???


Yes


Now try

IF NOT A = B OR C

This ambiguity should convince you NOT to use abbreviation. It can be fatal.


Howard Brazee

2004-06-16, 8:55 pm


On 16-Jun-2004, "Thomas A. Li" <tli@corporola.com> wrote:

> I'm reading COBOL program and can't make sure the meaning of the following
> abbreviated condition:


Remember this. If the code isn't obvious, then the programmer should have made
it obvious. That's a major feature of good CoBOL design.


> If A NOT = B AND NOT C
>
> Is it equivalent to
>
> If A NOT = B AND A = C
>
> or
>
> If A NOT = B AND A NOT = C ???


See if this link helps:
http://publibz.boulder.ibm.com/cgi-...927030801&CASE=


Unless modified by parentheses, the following precedence rules (from
highest to lowest) apply:



Arithmetic operations
Simple conditions
NOT
AND
OR
Mike

2004-06-16, 8:55 pm

Nope... try it... these are all true.


identification division.
program-id. testit.
environment division.
working-storage section.
01 .
05 A pic 9 value 1.
05 B pic 9 value 2.
05 C pic 9 value 1.
procedure division.
000-main.
if A not = B and not C
display 'True'.
if not A = B or C
display 'True'.
if A not = B and A = C
display 'True'.
goback.


Chuck Stevens

2004-06-16, 8:55 pm

All three standards have an example of an Abbreviated Combined Relation
Condition that can be used to figure this out definitively. This example
appears in ISO/IEC 1989:2002 on Page 137; in ANSI X3.23-1985 on Page VI-61;
and in ANSI X3.23-1974 on Page II-48.

This example is the last in a group of Abbreviated Combined Relation
Condition examples:
NOT (a NOT > b AND c AND NOT d)
and it is explicitly described as equivalent to
NOT ((((a NOT > b) AND (a NOT > c)) AND (NOT (a NOT > d))))

As I see it:

Dropping the outer NOT, this becomes:
a NOT > b AND c AND NOT d
which is interpreted as
(((a NOT > b) AND (a NOT > c)) AND (NOT (a NOT > d )))

Dropping the inner "AND c", we get
a NOT > b AND NOT d
which is interpreted as
((a NOT > b) AND (NOT (a NOT > d)))

Now, making the appropriate operator and letter substitutions in the
example,
A NOT = B AND NOT C
is correctly interpreted as
(A NOT = B) AND (NOT (A NOT = C)).

Because "NOT (A NOT = C) is the same as "A = C" in this case, the original
IF becomes
IF (A NOT = B) AND (A = C) ...
which is, of course.
IF A NOT = B AND A = C ...

Many people assume that abbreviation implies some sort of override of the
normal precedence rules that doesn't apply when the full specification
(without parentheses) is used. 'T'aint so. "NOT =" is a *simple*
relational operator in 2002-speak. "NOT [implied subject] [implied
relational] C" is "NOT (A NOT = C)" when [implied subject] is "A" and
[implied relational] is "NOT =".

Lest anyone misunderstand: I Do Not Like Abbreviated Combined Relation
Conditions.

The 2002 standard warns, just before the examples of abbreviated combined
relation conditions: "NOTE The use of NOT often leads to results that are
not intuitive and therefore it should be avoided."

-Chuck Stevens

"Thomas A. Li" <tli@corporola.com> wrote in message
news:SN1Ac.4490$7C%1.498@news04.bloor.is.net.cable.rogers.com...
> I'm reading COBOL program and can't make sure the meaning of the following
> abbreviated condition:
>
> If A NOT = B AND NOT C
>
> Is it equivalent to
>
> If A NOT = B AND A = C
>
> or
>
> If A NOT = B AND A NOT = C ???
>
>
>
> Thanks in advance.
>
>
>
> Thomas Li
>
>
>
>



Charles W. Cribbs II

2004-06-16, 8:55 pm

Well you could also interpret it this way:

if (value 1 not = value 2) and
(not condition c)

We have programs that are doing something like:

if (field 1 not = field 2) and
(not print-detail)
do procedure
end-if.

How that may be interpreted is you are doing a variable comparison and you
are checking for false condition. Usually with an 88 level condition you
are checking for true or a true condition but in the statement above you are
checking for a false condition. I was dealing with a program statement
similar to this last w.


"Thomas A. Li" <tli@corporola.com> wrote in message
news:SN1Ac.4490$7C%1.498@news04.bloor.is.net.cable.rogers.com...
> I'm reading COBOL program and can't make sure the meaning of the following
> abbreviated condition:
>
> If A NOT = B AND NOT C
>
> Is it equivalent to
>
> If A NOT = B AND A = C
>
> or
>
> If A NOT = B AND A NOT = C ???
>
>
>
> Thanks in advance.
>
>
>
> Thomas Li
>
>
>
>



Richard

2004-06-17, 3:55 am

"Chuck Stevens" <charles.stevens@unisys.com> wrote

> "NOTE The use of NOT often leads to results that are
> not intuitive and therefore it should be avoided."


I am not quite understanding that, does it mean ?:

NOT ( intuitive and therefore it should be avoided )

-> ( NOT intuitive ) OR ( should NOT be avoided )
Robert Wagner

2004-06-17, 8:55 am

"Chuck Stevens" <charles.stevens@unisys.com> wrote:

>The 2002 standard warns, just before the examples of abbreviated combined
>relation conditions: "NOTE The use of NOT often leads to results that are
>not intuitive and therefore it should be avoided."


One of the Great Problems in programming is that intuition is fails us on logic
problems even slightly complex, especially when they include NOT.

People who argue for 'the best tool for the job' ignore their own advice when
they stubbornly try to handle such problems with Common Sense and refuse to
learn Boolean Algebra.

If we are going to spend our lives dealing with logic problems, it seems
reasonable to expect the necessary skills. Conversational English is simply
inadequate.

Chuck Stevens

2004-06-17, 3:55 pm

So long as you use parentheses to establish the relation conditions and to
define their precedence, that's not a problem. The issue is the
sometimes-counterintuitive rules surrounding NOT in an *abbreviated combined
relation condition* in combination with the fact that abbreviation does not
impact precedence at all. It is in the smaller context of abbreviated
conditions that the suggestion to avoid NOT is made in the 2002 standard.

-Chuck Stevens


"Charles W. Cribbs II" <charlescribbs@earthlink.net> wrote in message
news:Ip5Ac.13505$Y3.100@newsread2.news.atl.earthlink.net...
> Well you could also interpret it this way:
>
> if (value 1 not = value 2) and
> (not condition c)
>
> We have programs that are doing something like:
>
> if (field 1 not = field 2) and
> (not print-detail)
> do procedure
> end-if.
>
> How that may be interpreted is you are doing a variable comparison and you
> are checking for false condition. Usually with an 88 level condition you
> are checking for true or a true condition but in the statement above you

are
> checking for a false condition. I was dealing with a program statement
> similar to this last w.
>
>
> "Thomas A. Li" <tli@corporola.com> wrote in message
> news:SN1Ac.4490$7C%1.498@news04.bloor.is.net.cable.rogers.com...
following[color=darkred]
>
>



LX-i

2004-06-27, 3:55 am

Thomas A. Li wrote:
> I'm reading COBOL program and can't make sure the meaning of the following
> abbreviated condition:
>
> If A NOT = B AND NOT C


Is this an abbreviated condition? It looks like "C" is a condition
name, not another variable with a value. It's missing the "=" between
"NOT" and "C".

> Is it equivalent to
>
> If A NOT = B AND A = C
>
> or
>
> If A NOT = B AND A NOT = C ???


So, if my above premise is true, no, they are not equivalent. If it
said something like

If A NOT = B AND C

then your restatement #2 above would be equivalent.


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ LXi0007@Netscape.net ~
~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~

Chuck Stevens

2004-06-29, 8:55 pm


"LX-i" <lxi0007@netscape.net> wrote in message
news:10dsfobpd5iqacd@corp.supernews.com...

regarding "IF A NOT = B AND NOT C":

> Is this an abbreviated condition? It looks like "C" is a condition
> name, not another variable with a value. It's missing the "=" between
> "NOT" and "C".


Actually, it could be either a condition-name or a variable. An "="
wouldn't be allowed before C were C a condition-name in this context, but
were C a variable the "=" would be permitted, but not required, before C
(the rules of abbreviation would allow elision of the relational operator if
the subject were also elided).

Thus, if C is indeed a variable,
IF A NOT = B AND NOT C ...
is an Abbreviated Combined Relation Condition which, when the abbreviations
are expanded, evaluates to
IF (A NOT = B) AND NOT (A NOT = C) ..
which condenses to
IF (A NOT = B) AND (A = C) ...

On the other hand, if C is a condition-name, the same expression is merely a
Combined Relation Condition and evaluates to
IF (A NOT = B) and (NOT C) ...

Yet another example of good reasons to avoid Abbreviated Combined Relation
Conditions, and to use parentheses to eliminate ambiguity in relation
conditions!

-Chuck Stevens


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com