For character assignment statements, the variable and expression must be of character type and have the same kind parameter.
The variable and expression can have different lengths. If the length of the expression is greater than the length of the variable, the character expression is truncated on the right. If the length of the expression is less than the length of the variable, the character expression is filled on the right with blank characters.
If you assign a value to a character substring, you do not affect character positions in any part of the character scalar variable not included in the substring. If a character position outside of the substring has a value previously assigned, it remains unchanged. If the character position is undefined, it remains undefined.
The following examples demonstrate valid and invalid character assignment statements. (In the valid examples, all variables are of type character.)
Valid | |
FILE = 'PROG2' | |
REVOL(1) = 'MAR'//'CIA'
| |
LOCA(3:8)
= 'PLANT5' | |
TEXT(I,J+1)(2:N-1) = NAME/
/X | |
Invalid | Explanation |
'ABC' =
CHARS | Left element must be a character variable, array element, or substring reference. |
CHARS = 25 | Expression does not have a character data type. |
STRING =
5HBEGIN | Expression does not have a character data type. (Hollerith constants are numeric, not character.) |