Consultor Eletrônico



Kbase P110932: Comparing characters returns the wrong result
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   17/11/2005
Status: Unverified

SYMPTOM(s):

Comparing characters returns the wrong result

High values character no longer is the highest value.

DISPLAY CHR(254) < CHR(255) returns NO.

CAUSE:

The comparison is done via the sort weight of the character based on the current collation and not the position of the character within the code page.

FIX:

The sort weight of the character is defined in the collation table for the specific code page in use.

A way to work around this is to use the COMPARE function. For example:

COMPARE(CHR(254), "<", CHR(255), "RAW")

This give the expected YES result since RAW (the comparison strength) comparisons use numeric values in the current code page. However, with the COMPARE function other comparison strengths are available along with specific collation comparisons.

Another possible solution to the problem would be to loop through each character in the code page trying to find the highest value. For example:

DEFINE VARIABLE iHighest AS INTEGER NO-UNDO INITIAL 1.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO 255:
IF CHR(iHighest) < CHR(i) THEN
iHighest = i.
END.
MESSAGE iHighest VIEW-AS ALERT-BOX.