COMPARE Function

Purpose

Compares two buffers.

Syntax

COMPARE(x, y, z)

Parameters

x, y, z are expressions. x and y are the addresses that specify the areas of storage and z is the number of bytes. x and y must have the OFFSET and POINTER type. z is converted to FIXED BINARY(31,0).

Description

The COMPARE built-in function compares two buffers and returns a FIXED BINARY(31,0) value. The returned value is 0 if the number of bytes at the addresses x and y are identical. It is negative if the z bytes at x are less than those in y, and positive if the bytes at x are greater than those at y.

Example

dcl Result fixed bin;
dcl 1 Str1,
2 B fixed bin(31),
2 C pointer,
2 * union,
3 D char(4),
3 E fixed bin(31),
3 *,
4 * char(3),
4 F fixed bin(8) unsigned,
2 * char(0);
dcl 1 Template nonasgn static,
2 * fixed bin(31) init(16), /* ’’X */
2 * pointer init(null()),
2 * char(4) init(’’),
2 * char(0);
call plimove(addr(Str1), addr(Template), stg(Str1));
Result = compare(addr(Str1), addr(Template), stg(Str1)); /* 0 */
D = ’DSA ’;
Result = compare(addr(Str1), addr(Template), stg(Str1)); /* 1 */
B = 15; /* ’00000F00’X */
D = ’DSA ’;
Result = compare(addr(Str1), addr(Template), stg(Str1)); /* -1 */

Restrictions

None.