VARLEN (Variable-Length Field) keyword for physical and logical files

You can use this field-level keyword to define this field as a variable-length field.

Variable-length fields are useful for improving storage when the data for the field typically fits within a certain length, but can occasionally be longer. Specify the maximum length of the field in positions 30 to 34. You can specify the allocated length (or typical length) in the parameter.

The format of the keyword is:
VARLEN[(allocated-length)]

The allocated-length parameter is optional. Use it to specify the number of bytes (two byte characters in the case of graphic fields) allocated for the field in the fixed portion of the file. If you do not specify the allocated-length parameter, the data for this field is stored in the variable length portion of the file.

Valid values for the allocated-length parameter are 1 to the maximum length of the field specified in positions 30 to 34.

The VARLEN keyword has no parameters for a logical file.

The VARLEN keyword is valid only on character fields and graphic fields.

When you specify the VARLEN keyword, the maximum length you can specify in positions 30 to 34 is 32 740 (32 739 if the field allows the null value). If the field is a graphic field, the maximum length you can specify is 16 370.

If you specify the DFT keyword for a variable-length field, the length of the default value must be less than or equal to the allocated length for the field. If the default value is longer than the allocated length, an error message is issued when the file is created.

If you specify a hexadecimal value as the default value for a variable-length field, the number of hexadecimal characters must be equal to two times the allocated length for the field.

The DFT keyword is not allowed on the same field as a VARLEN keyword unless you specify a value for the allocated-length parameter.

Do not specify the VARLEN keyword on a date, time, or timestamp field (L, T, or Z in position 35).

Example

The following example shows how to specify the VARLEN keyword for a physical file.

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00010A          R RECORD1
00020A            FIELD1       100A         VARLEN(30)
00030A            FIELD2       200A         VARLEN
     A

FIELD1 is defined as a variable-length field with a maximum length of 100 and an allocated length of 30. FIELD2 is defined as a variable-length field with a maximum length of 200 and no allocated length.