Evaluating single characters for collating sequence

To find out the ordinal position of a given alphabetic or alphanumeric character in the collating sequence, use the ORD function with the character as the argument. ORD returns an integer that represents that ordinal position.

You can use a one-character substring of a data item as the argument to ORD:


IF Function Ord(Customer-record(1:1)) IS > 194 THEN . . .

If you know the ordinal position in the collating sequence of a character, and want to find the character that it corresponds to, use the CHAR function with the integer ordinal position as the argument. CHAR returns the required character. For example:


INITIALIZE Customer-Name REPLACING ALPHABETIC BY Function Char(65)

Start of changeThe ordinal number associated with a character is not the same as the numeric value (in decimal) of the hex value of the character. For example, if you are using the EBCDIC collating sequence, the ordinal number of X'00' is one instead of zero. Similarly, the ordinal number of X'FF' is 256 instead of 255. Therefore, the ordinal values returned from the ORD intrinsic function when using the EBCDIC collating sequence range from 1 - 256, not 0 - 255 that are the decimal values of the hex values of the valid EBCDIC characters.End of change

related references  
CHAR (Enterprise COBOL for z/OS® Language Reference)  
ORD (Enterprise COBOL for z/OS Language Reference)