compareBytes()

The system function VGLib.compareBytes compares two fields, byte by byte.

As is true in StrLib.compareStr, the source and target may be of a character type. In the current function, the source also may be any of the following types:
  StrLib.compareBytes(
    target a character type  in,
    targetIndex INT in,
    targetSubLength INT in,
    source BIN, DECIMAL, NUM, NUMC, PACF, or a character type in,
    sourceIndex INT in,
    sourceSubLength INT in  )
  returns (result INT)
result
Numeric field that receives one of the following values (defined as type INT or the equivalent: type BIN with length 9 and no decimal places) returned by the function:
-1
The value based on target is less than the value based on source
0
The value based on target is equal to the value based on source
1
The value based on target is greater than the value based on source
target
Value from which a target value is derived. Can be a field or a literal.
targetSubIndex
Identifies the starting byte of a value in target, given that the first byte in target has the index value 1. This index can be an integer literal. Alternatively, this index can be a field defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
targetSubLength
Identifies the number of bytes in the value that is derived from target. The length can be an integer literal. Alternatively, the field can be defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
source
Field or literal from which a source value is derived.
sourceSubIndex
Identifies the starting byte of the value in source, given that the first byte in source has the index value of 1. This index can be an integer literal. Alternatively, this index can be a field defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
sourceSubLength
Identifies the number of bytes in the value that is derived from source. The length can be an integer literal. Alternatively, this index can be a field defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.

A byte-to-byte comparison of the values is performed. If the values are not the same length, the shorter value is padded with blanks even that value is numeric.

Definition considerations

The following values are returned in sysVar.errorCode:
8
Index less than 1 or greater than value length.
12
Length less than 1.
20
Invalid double-byte index. Index for a DBCHAR or UNICODE string points to middle of double-byte character
24
Invalid double-byte length. Length in bytes for a DBCHAR or UNICODE string is odd (double-byte lengths must always be even).

Example

  target = "123456";
  source = "34";
  result = 
    StrLib.compareBytes(target,3,2,source,1,2);
  // result = 0

Related reference
compareStr()
EGL library VGLib

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.