Creating a Variable Length Character Expression

In this section:

As an alphanumeric type, an AnV field can be used in arithmetic and logical expressions in the same way that the An type is used.

Note: Because AnV fields have two bytes of overhead and there is additional processing required to strip them, AnV format is not recommended for use in non-relational data sources.

Using Concatenation With AnV Fields

If either of the operands in a concatenation between two fields is an AnV field, variable length alphanumeric rules are used to perform the concatenation:

Using the EDIT Function With AnV Fields

The following expression results in an AnV format only when x has AnV format.

EDIT(x,mask)

The actual length of the result is the number of characters in mask other than '$'.

Note that an actual length of zero may result.

EDIT(x) can be used to convert an AnV field to an integer value when x has AnV format.

Using CONTAINS and OMITS With AnV Fields

The only difference in evaluation of the CONTAINS and OMITS operators with AnV fields occurs when one of the operands has an actual length of zero.

In the following examples, the field Z has an actual length of zero, but X and Y do not:

Expression

Result

Z CONTAINS Y

FALSE

X CONTAINS Z

TRUE

Z CONTAINS Z

TRUE

Z OMITS Y

TRUE

X OMITS Z

FALSE

Z OMITS Z

FALSE

Using LIKE With AnV Fields

The only difference in evaluation of the following expression occurs when x has an actual length of zero:

x LIKE mask ...

In the following example, the field instance Z has an actual length of zero:

Z LIKE mask ...

This expression evaluates to TRUE only when the mask consists exclusively of percent ('%') signs.

Note that no other mask can evaluate to an empty string. Even the mask in the following expression has a length of one, and therefore the expression evaluates as FALSE:

Z LIKE ''

Using the EQ, NE, LT, GT, LE, and GE Operators With AnV Fields

As with An type fields, operations are evaluated on the assumption that the shorter operand is padded with blanks.

Therefore, even an empty AnV field, Z, is compared as a field consisting of all blanks.

In the following examples, Z is an empty AnV field instance and X is an AnV field instance that is not empty and contains non-blank characters:

Expression

Result

Z EQ Z
Z GE Z
Z LE Z

TRUE

Z NE Z
Z LT Z
Z GT Z

FALSE

Z EQ X

FALSE

Z NE X

TRUE

Z LT X

TRUE

Z GT X

FALSE

Z LE X

TRUE

Z GE X

FALSE

X EQ Z

FALSE

X NE Z

TRUE

X LT Z

FALSE

X GT Z

TRUE

X LE Z

FALSE

X GE Z

TRUE

Using the DECODE Function With AnV Fields

DECODE alphafield (value 'result'...

The use of either an An or AnV field with DECODE causes a result of type An as long as the result part of the value-result pairs is provided as a constant. (Constants are type An.)

Using the Assignment Operator With AnV Fields

There are three situations to consider when using the assignment operator with the AnV format: AnV data type on the right hand side only, AnV data type on both sides, and AnV data type on the left side only.

fld/An = AnV_type_expression;