Consultor Eletrônico



Kbase P8610: 4GL/ABL: Error (78) is NOT generated in some 4GL code resulting in some INTEGER value to wrap to the
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   11/4/2008
Status: Verified

SYMPTOM(s):

4GL/ABL: Error (78) is NOT generated in some 4GL code resulting in some INTEGER value to wrap to the minimum negative INTEGER values.

** Value too large for integer. (78)

When an INTEGER variable is continuously incremented and reaches its upper limit of +2,147,483,647, it proceeds counting from the lower limit until it reaches zero and then goes to the upper limit again without generating an error message indicating that the INTEGER variable has exceeded its upper limit.

When an INTEGER variable is continuously decremented and reaches its lower limit of -2,147,483,648, it proceeds counting from the upper limit until it reaches zero and then goes to the lower limit again without generating an error message indicating that the INTEGER variable has exceeded its lower limit.

The following code demonstrates the issue. In this snippet, the INTEGER variable iVariable is incremented by 9 which makes it exceeds its upper limit of +2147483647 and silently wraps around to its negative lower limit resulting with the wrong negative value of -2147483646 without generating an error message indicating the variable has exceeded its upper limit of +2147483647:

DEFINE VARIABLE iVariable AS INTEGER INITIAL 2147483640 NO-UNDO.
ASSIGN
iVariable = iVariable + 9.
MESSAGE iVariable
VIEW-AS ALERT-BOX INFO BUTTONS OK.

FACT(s) (Environment):

All Supported Operating Systems
Progress 8.0x
Progress 9.1x
OpenEdge 10.0x

CAUSE:

Progress does not issue the maximum or minimum integer overflow errors when the integer results from incrementing an already existing integer. However, assigning a value more than the upper limit of the INTEGER data type, +2147483647, or less than the lower limit of the INTEGER data type,-2147483648, causes the overflow error to be generated.

FIX:

Use a temporary decimal variable to do the incrementing and assign the decimal result to the integer variable. If the result is outside the limits of the INTEGER data type, the error ?** Value too large for integer. (78)? will be generated as desired. For example:

DEFINE VARIABLE dVariable AS DECIMAL INITIAL 2147483640 NO-UNDO.
DEFINE VARIABLE iVariable AS INTEGER NO-UNDO.
ASSIGN
dVariable = dVariable + 9
iVariable = dVariable.
MESSAGE iVariable
VIEW-AS ALERT-BOX INFO BUTTONS OK.