Document Number:     J4/02-0224
17 October 2002 
 
Page    1  of   3
Subject: 
Overlapping operands, replacing 02-0223
Author: 
Wim Ebbinkhuijsen
Date
2002-10-20
References:
1. 
 
 
 
COBOL 2002
2. 
 
 
 
COBOL 1985
DISCUSSION
I see an incompatibility with regard to the effect of overlapping operands for
statements in which the sending and the receiving operand are defined by the
same data description.
1. In COBOL 85 the paragraph on overlapping operands reads as follows:
"6.4.5 Overlapping Operands
When a sending and a receiving item in any statement share a part or all of
their storage areas, yet are not defined by the same data description entry, the
result of the execution of such a statement is undefined. In addition, the
results are undefined for some statements in which sending and receiving items
are defined by the same data description entry. These.cases are addressed in
the general rules associated with those statements."
2. In COBOL 2002 the paragraph on overlapping operands reads as follows:
"14.5.9 Overlapping operands
When a sending and a receiving data item in any statement share a part or all of their
storage areas, yet are not defined by the same data description entry, the result of the
execution of such a statement is undefined. For statements in which the sending and
receiving data items are defined by the same data description entry, the results of the
execution of the statement may be defined or undefined depending on the general
rules associated with the applicable statement. If there are no specific rules
addressing such overlapping operands, the results are undefined.
In the case of reference modification, the unique data item produced by reference
modification is not considered to be the same data description entry as any other data
description entry. Therefore, if an overlapping situation exists, the results of the
operation are undefined."
3. The definition of a sending and a receiving operand in COBOL 2002 is as follows:
"14.5.7 Sending and receiving operands
An operand is a sending operand if its contents prior to the execution of a statement
may be used by the execution
of the statement. An operand is a receiving operand if
its contents may be changed by the execution of the
statement. Operands may be
referenced either explicitly or implicitly by a statement. For some statements, an
Document Number:     J4/02-0224
17 October 2002 
 
Page    2  of   3
operand is both a sending operand and a receiving operand. The rules for a statement
specify whether operands
are sending operands, receiving operands, or both when
this is not clear from the context of the statement."
4. For items that are defined by the same data description there is a difference in the
two marked sentences (see items 1 and 2):
- COBOL 85 states impicitly that the results are defined
unless addressed otherwise in
the general rules for a specific statement.
- COBOL 2002 states explicitly that the results are undefined unless addressed
otherwise in the general rules for a specific statement.
4. I have checked all relevant statements to find the differences between COBOL 85
and COBOL 2002.
a. The arithmetic statements:
- The general rules for these statements in COBOL-85 refer to the paragraph on
overlapping operands (as quoted in item 1). Since there are are no specific rules on
overlapping operands specified for any of these statements, the results are defined.
- The general rules for these statements in COBOL-2002 refer to the paragraph on
overlapping operands (as quoted in item 2). Since there are are no specific rules on
overlapping operands specified for any of these statements, the results are undefined.
Therefore, the result of statements like
 
Add A to A
 
Subtract B from A giving A
 
Subtract function integer (A) from A
is defined in COBOL-85 but undefined in COBOL-2002.
It is even worse because normal statements like
 
Multiply B by A
 
Compute A = B / A
 
Add 1 to A
will also render undefined results since item A in these statements is both a sending
and a receiving operand.
b. The CALL statement:
- Neither the general rules for this statement in COBOL-85 nor in COBOL-2002 say
anything about overlapping operands. So, the results are defined in COBOL-85
(although I don't know what that means!) but undefined in COBOL-2002.
Document Number:     J4/02-0224
17 October 2002 
 
Page    3  of   3
Therefore, the result of
 
Call A using A returning A
is defined in COBOL-85 but undefined in COBOL-2002.
c. The MOVE statement:
- Neither the general rules for this statement in COBOL-85 nor in COBOL-2002 say
anything about overlapping operands. Therefore, the result of
 
Move A to A
is defined in COBOL-85 but undefined in COBOL-2002.
[For the INITIALIZE, STRING and  UNSTRING statements, both COBOL-85 and
COBOL-2002 state explicitly that the results are undefined.]
I surely hope that I see it all wrong …
Wim