Refer to Data types and attributes for general information about strings.
The BIT attribute specifies a bit variable.
The CHARACTER attribute specifies a character variable. Character strings can also be declared using the PICTURE attribute.
The WIDECHAR attribute specifies a widechar variable which will hold UTF-16 data.
The GRAPHIC attribute specifies a graphic variable.
The syntax for the BIT, CHARACTER, GRAPHIC and WIDECHAR attributes is:
| Attribute | Abbreviation |
|---|---|
| CHARACTER | CHAR |
| GRAPHIC | G |
| WIDECHAR | WCHAR |
| NONVARYING | NONVAR |
| VARYING | VAR |
| VARYINGZ | VARZ |
You can specify the length as an expression or as an asterisk. If the length is not specified, the default is 1. For named constants, length is determined from the length of the value expression.
For a parameter, an expression is valid only if it is CONTROLLED. An asterisk specification for a parameter indicates that the length is taken from the argument that is passed.
If the length specification is an expression, it is evaluated and converted to FIXED BINARY(31,0), which must be positive, when storage is allocated for the variable.
For STATIC data, length must be a restricted expression.
For BASED data, length must be a restricted expression, unless the string is a member of a structure or a union and the REFER option is used.
The statement below declares User as a variable that can represent character data with a length of 15:
declare User character (15);
The following example shows the declaration of a bit variable:
declare Symptoms bit (64);