Kbase P17238: Errors 26 and 142 when trying to assign an array field or va
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  02/02/2003 |
|
Status: Unverified
SYMPTOM(s):
** Array subscript <value> is out of range. (26)
** Unable to update <filename> Field. (142)
CAUSE:
Executing code similar to the following generates the above two errors because the ARRAY field iOrdernum subscript exceeds the 200 limit.
DEFINE TEMP-TABLE myTable NO-UNDO
FIELD iItemnum LIKE item.Itemnum
FIELD iOrdernum AS INTEGER EXTENT 200.
DEFINE VARIABLE iExtent AS INTEGER NO-UNDO.
FOR EACH orderline BREAK BY Itemnum:
IF FIRST-OF(Itemnum) THEN DO:
CREATE mytable.
ASSIGN
iExtent = 1
iItemnum = Itemnum.
END.
ELSE DO:
ASSIGN
iExtent = iExtent + 1.
END.
ASSIGN
iOrdernum[iExtent] = OrderNum.
END.
FOR EACH mytable NO-LOCK:
DISPLAY iItemnum iOrdernum[1] iOrdernum[2] iOrdernum[3].
END.
FIX:
Making the number of extents in iOrdernum array large enough to equal or exceed the maximum number of orders placed for any given item eliminates the above errors.
However, a better solution is to redesign the application to eliminate all hard coded limit dependencies as these will eventually cause the application to fail when any of these limits is exceeded.
The error:
** Array subscript <value> is out of range. (26) indicates that an array limit has been breached. For example:
DEFINE VARIABLE iArray AS INTEGER EXTENT 10 NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
REPEAT:
ASSIGN
iCounter = iCounter + 1
iArray[iCounter] = iCounter.
END.
The fix here is to check that the array subscript is valid. For example:
DEFINE VARIABLE iArray AS INTEGER EXTENT 10 NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO INITIAL 1.
REPEAT WHILE iCounter LE EXTENT(iArray) :
ASSIGN
iArray[iCounter] = iCounter
iCounter = iCounter + 1.
END.
The error:
** Unable to update <filename> Field. (142) indicates an attempt to ASSIGN, SET, or otherwise change a value of a non existing field or variable. For example:
FIND FIRST customer WHERE NAME = "Customer Does Not Exist" NO-ERROR.
ASSIGN NAME = "This Will Generate Error 142".
The fix here is to check record availability before changing its field values:
FIND FIRST customer WHERE NAME = "does not exist" NO-ERROR.
IF AVAILABLE(Customer) THEN
ASSIGN NAME = "This will generate error 142".