VARCHAR(length {:2 | 4})

The VARCHAR keyword is used in a free-form definition to indicate that the item is variable-length character.

It must be the first keyword.

The parameter specifies the length in bytes. It can be between 1 and 16,773,102.

Each parameter can be a literal or a named constant. If it is a named constant, the constant must be defined prior to the definition statement.

The second parameter is optional. It specifies the number of bytes used to store the current length of the variable-length item. See Size of the Length-Prefix for a Varying Length Item.

Each parameter can be a literal or a named constant. If it is a named constant, the constant must be defined prior to the definition statement.

In the following example
  • field cust_name is defined as a variable-length character field with a maximum length of 50 characters
  • field message is defined as a variable-length character field with a maximum length of 500 characters and a prefix size of 4 bytes.

  DCL-S cust_name VARCHAR(50);
  DCL-S message VARCHAR(500 : 4);

For information on defining a fixed-length character item, see CHAR(length).