Document Number: J4/02-0126
July 7, 2002
Page 1 of 3
Subject:
SET statement problems - indexes
Author:
Don Schricker
References:
1.
Base Document: FDIS, April 2002
a.
8.4.1.2, Subscripts, general rules 1 and 2
b.
13.16.36, OCCURS clause, general rule 2
c.
14.8.35, SET statement, general rules 2 and 3
DISCUSSION:
Wim Ebbinkhuijsen reported the following problems with reference 1c:
In GR 2.a.1 there is no reference to the situation where the evaluation of the arithmetic
expression does not result into a valid subscript.
In GR 2.a.3 there is no reference to the situation where the occurrence number of the table
element referenced by index-name-2 is too large to be a valid occurrence number for the table
referenced by index-name-1.
On the other hand, GR's 3.a and 3.b do cover these situations.
I think that GR 2 on page 89, 8.4.1.2 Subscripts, covers this. But I don't think that the GR's 2
and 3 are consistent
Initial response from Don Schricker:
No exception would be raised by the SET statement here, but if you use the invalid index as a
subscript without using relative indexing, 8.4.1.2 specifies the exception condition that would
result.
You are correct that GR 2.a.3 should specify an exception because the SET statement
could try to set the index to a value outside the range that can be physically stored in the index.
Note: I see other holes, too. Like SET does not allow an index to be set to zero or to even one
greater than the max.
Direction from Don Schricker for 02-0126 after giving the subject due consideration:
There are several problems with reference 1c:
the rules allow some situations that should result in runtime exceptions
the rules prohibit some situations that should be allowed.
I think that reference 1b, the OCCURS clause, provides the direction for what should be allowed in an
index as a result of the execution of a SET statement. That is, any value that fits within the range that
an implementor has specified can be contained in the index. Of course, when an index is used as a
subscript, it must reference, possibly with relative indexing, a valid occurrence of the table.
Rule 3b of the SET statement is too restrictive, because it requires the SET statement to set the index to
a valid occurrence number. Admittedly, the rule has to be reworded entirely because it relies on the
subscript being valid to describe the effect of the statement. When the index points to occurrence zero,
Document Number: J4/02-0126
July 7, 2002
Page 2 of 3
or the occurrence that is one larger than the actual size of the table, the description of the effect of the
SET statement needs to be changed. There is a similar problem with SET statement GR 2a1.
On the other hand, SET statement GR 2a3b could set the value of an index outside the range of
allowable values, and there is nothing in the SET statement prohibiting this. Perhaps nothing needs to
be said in the SET statement, because this situation is covered by GR2 of the OCCURS clause, but
then there needs to be a reference here to the OCCURS clause.
One problem with the rules as structured is that the SET statement refers to the rules for subscripting
just to avoid saying that the arithmetic expression must result in an integer or else the EC-BOUND-
SUBSCRIPT exception is set to exist. This could be repeated and avoid reference to other restrictions
that apply when subscripting, but not when setting the index.
I have reworded general rules 2 and 3 of the SET statement in the changes needed section. This is how
they appear in the draft so you can compare the two versions:
2) The following occurs for each recurrence of index-name-1 or identifier-1. Each time, the value of the sending
operand is used as it was at the beginning of the execution of the statement. Item identification of the data item
referenced by identifier-1 is done immediately before the value of that data item is changed:
a) If index-name-1 is specified:
1. If arithmetic-expression-1 is specified, a subscript is determined by evaluating arithmetic-expression-1
as described in 8.4.1.2, Subscripts. If the evaluation of that subscript is successful, index-name-1 is set to
a value causing it to refer to the table element that corresponds in occurrence number to that subscript;
otherwise the execution of the SET statement is unsuccessful and the content of the receiving operand is
unchanged.
2. If identifier-2 is specified, the content of the data item referenced by identifier-2 is placed in the index
referenced by index-name-1 unchanged.
3. If index-name-2 is specified:
a. If index-name-2 is associated with the same table as index-name-1, the content of the index
referenced by index-name-2 is placed in the index referenced by index-name-1 unchanged.
b. Otherwise, index-name-1 is set to a value causing it to refer to the table element that corresponds in
occurrence number to the table element associated with index-name-2.
b) If identifier-1 references an index data item, the content of index-name-2 or of the data item referenced by
identifier-2 is placed in the index referenced by index-name-1 unchanged.
c) If identifier-1 references a numeric data item, that item is set to the occurrence number of the table element
referenced by index-name-2.
3) The following occurs for each recurrence of index-name-3. Each time, the value of arithmetic-expression-2 is
used as it was at the beginning of the execution of the statement::
a) If arithmetic-expression-2 does not evaluate to an integer, the EC-BOUND-SUBSCRIPT exception
condition is set to exist, the execution of the SET statement is unsuccessful, and the content of the receiving
operand is unchanged.
b) If the occurrence number represented by the content of index-name-3 incremented (UP BY) or
decremented (DOWN BY) the result of the evaluation of arithmetic-expression-2 is a valid subscript for the
table associated with index-name-3 according to the constraints described in 8.4.1.2, Subscripts, index-
name-3 is set to a value causing it to refer to the table element that corresponds in occurrence number to that
subscript; otherwise the EC-BOUND-SUBSCRIPT exception condition is set to exist, the execution of the SET
statement is unsuccessful, and the content of the receiving operand is unchanged.
Document Number: J4/02-0126
July 7, 2002
Page 3 of 3
Changes needed in standard:
1. Change SET statement, general rules 2 and 3 to read as follows:
[DAS: I'm not sure whether we need the parts that I've highlighted with yellow. They help to clarify what
has changed, but they may not be needed in the specificatin.]]
"2) The following occurs for each recurrence of index-name-1 or identifier-1. Each time, the value of the sending
operand is used as it was at the beginning of the execution of the statement. Item identification of the data item
referenced by identifier-1 is done immediately before the value of that data item is changed:
a) If index-name-1 is specified:
1. If arithmetic-expression-1 is specified, a value is determined by evaluating arithmetic-expression-1. If
the evaluation of arithmetic-expression-1 does not result in an integer, the EC-BOUND-SUBSCRIPT
exception condition is set to exist, the execution of the SET statement is unsuccessful and the content of
the receiving operand is unchanged. Further constraints on the value of the expression are specified in
general rule 2 of 13.16.36, OCCURS clause. If the evaluation of the expression is successful, index-
name-1 is set to a value causing it to refer to the table element that corresponds in occurrence number to
that expression, even if that value is outside of the range of valid subscripts for the table.
2. If identifier-2 is specified, the content of the data item referenced by identifier-2 is placed in the index
referenced by index-name-1 unchanged.
3. If index-name-2 is specified:
a. If index-name-2 is associated with the same table as index-name-1, the content of the index
referenced by index-name-2 is placed in the index referenced by index-name-1 unchanged.
b. Otherwise, a value is used that corresponds to the occurrence number of the table element
associated with index-name-2. Constraints on that value are specified in general rule 2 of 13.16.36,
OCCURS clause. If these constraints are satisfied, index-name-1 is set to refer to the table element
that corresponds in occurrence number to that value, even if that value is outside of the range of valid
subscripts for the table.
b) If identifier-1 references an index data item, the content of index-name-2 or of the data item referenced by
identifier-2 is placed in the index referenced by index-name-1 unchanged.
c) If identifier-1 references a numeric data item, that item is set to the occurrence number of the table element
referenced by index-name-2.
3) The following occurs for each recurrence of index-name-3. Each time, the value of arithmetic-expression-2 is
used as it was at the beginning of the execution of the statement::
a) If arithmetic-expression-2 does not evaluate to an integer, the EC-BOUND-SUBSCRIPT exception
condition is set to exist, the execution of the SET statement is unsuccessful, and the content of the receiving
operand is unchanged.
b) If the occurrence number represented by the content of index-name-3 incremented (UP BY) or
decremented (DOWN BY) the result of the evaluation of arithmetic-expression-2 is a valid index for the table
associated with index-name-3 according to the constraints specified in general rule 2 of 13.16.13, OCCURS
clause, index-name-3 is set to a value causing it to refer to the table element that corresponds to that
occurrence number, even if that occurrence number is outside of the range of valid subscripts for the table.
"
Open Issues:
1. See note in proposal item 1 about the portions in yellow.