compareBytes()
The vgLib.compareBytes() system function compares the contents of two substrings, byte by byte, without regard for the format of that content.
vgLib.compareBytes() is one of a number of functions maintained for compatibility with code migrated from VisualAge® Generator. New code can use standard EGL operators for these purposes.
EGL performs a byte-to-byte binary comparison of the values. If the values are not the same length, EGL pads the shorter value with blanks, even if that value is numeric.
Syntax
vgLib.compareBytes(
var1 HEX inOut,
var1index INT in,
var1SubstrLength INT in,
var2 HEX inOut,
var2Index INT in,
var2SubstrLength INT in )
returns (result INT)
- var1
- Value from which the first comparison value is derived. Can be any value that is reference compatible with HEX.
- var1SubstrIndex
- Identifies the starting byte of the substring in var1, given that the index value of the first byte is 1. This index can be an integer literal or variable (INT or BIN(9)).
- var1SubstrLength
- Identifies the number of bytes in the substring that is derived from var1. The length can be an integer literal or variable (INT or BIN(9)).
- var2
- Value from which the second comparison substring is derived. Can be any value that is reference compatible with HEX.
- var2SubstrIndex
- Identifies the starting byte of the substring in var2, given that the index value of the first byte is 1. This index can be an integer literal or variable (INT or BIN(9)).
- var2SubstrLength
- Identifies the number of bytes in the substring that is derived from var2. The length can be an integer literal or variable (INT or BIN(9)).
- result
- Integer value (INT or BIN(9)) returned by the function. The function
can return any of the following values:
- -1
- The substring based on var1 is less than the substring based on var2
- 0
- The substring based on var1 is equal to the substring based on var2
- 1
- The substring based on var1 is greater than the substring based on var2
Error considerations
If you use V6 exception compatibility (see Using V6 exception compatibility), the following values are
returned in sysVar.errorCode:
- 8
- Index less than 1 or greater than value length.
- 12
- Length less than 1.
- 20
- Index for a DBCHAR or UNICODE string points to middle of double-byte character
- 24
- Length in bytes for a DBCHAR or UNICODE string is odd (double-byte lengths must always be even).
Example
The following example shows how to use the vgLib.compareBytes() function.
target, source HEX (6); // index must be multiple of 2
result INT;
target = "123456";
source = "34";
result = vgLib.compareBytes(target,2,1,source,1,1); // result = 0