Creating a Variable Length Character Expression

Topics:

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:

  • The size of the concatenated string is the sum of the sizes of the operands.
  • For weak concatenation, the actual length of the concatenated string is the sum of the two actual lengths of the input strings.
  • For strong concatenation, the actual length stored in an AnV field of the concatenated string is the sum of the actual length of the first input string minus its number of trailing blanks plus the actual length of the second string.
  • For any An field in the concatenation, the size and length are equal.
  • Two consecutive single quotation marks represent a null value with format A1V and an actual length of 0 (zero), when the field has MISSING ON.

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;
  • The actual length of the evaluated expression is lost on assignment to the An field.
  • The size of the AnV result does not prevent assignment to a shorter An format field:
    • If the result of the expression has an actual length that is shorter than the length of the field on the left side of the assignment operator, the result is padded with blanks.
    • If the result of the expression has an actual length that is longer than the length of the field on the left side of the assignment operator, the result is truncated.
      fld/AnV = AnV_type_expression;
  • The length of the result is assigned as the length of the field on the left of the assignment operator unless it exceeds the field's declared size. In this case, the length assigned is the declared size (n).
  • The size of the AnV evaluation result does not prevent assignment to a shorter AnV field:
    • If the length of the result of the expression is shorter than the size of the field on the left side of the assignment operator, the result is padded with blanks.
    • If the result of the expression has an actual length that is longer than the size of the field on the left side of the assignment operator, the result is truncated.
      fld/AnV = An_type_expression;
  • The length of the field on the left side of the assignment operator is assigned equal to its size (n).
  • The actual length of the result is verified against the size n declared for the AnV field. An error is generated if the result is longer than n.

WebFOCUS

Feedback