BYTELENGTH

BYTELENGTH returns a FIXED BINARY(31) value that is the number of bytes used by a UCHAR string.

Read syntax diagramSkip visual syntax diagramBYTELENGTH( x)
x
Expression. x must have UCHAR type.

If x has UCHAR VARYING or UCHAR VARYING4 type, the value returned by BYTELENGTH(x) does not count the number of prefix bytes. If x has UCHAR VARYINGZ type, the value returned by BYTELENGTH(x) does not count the terminating null byte.

The value returned by BYTELENGTH(x) is always greater than the value returned by LENGTH(x), but no greater than four times the value returned by LENGTH(x).

Example 1:

Given DCL X UCHAR(1), then LENGTH(X) = 1 and STG(X) = 4, but after:

	X = ‘A’;
	BYTELENGTH(X) = 1 (since X holds ‘41’ux ) 
	X = ‘Ä’;
	BYTELENGTH(X) = 2 (since X holds  ‘C3_84’ux )
	X = ‘€’;
	BYTELENGTH(x) = 3 (since X holds ‘E2_82_AC’ux )
Example 2:

Given DCL X UCHAR(6), then LENGTH(X) = 6 and STG(X) = 24, but after:

	X = ‘Straße’ ; 
	BYTELENGTH(X) = 7 (since X holds ’53_74_72_C39F_61_65’ux )
Example 3:

Given DCL X UCHAR(8) VARYING, then STG(X) = 34, but after:

	X = ‘Straße’ ; 
	LENGTH(X) = 6
	BYTELENGTH(X) = 7 (since X holds ’53_74_72_C39F_61_65’ux )
	CSTG(X) = 9