The character assignment statement assigns the value of the character expression on the right of the equal sign to the character scalar memory reference on the left of the equal sign. It takes the following form:
v = e
If the length of e is greater than the length of v, the character expression is truncated on the right.
If the length of e is less than the length of v, the character expression is filled on the right with space characters.
The expression e must have a character data type. You cannot assign a numeric value to a character scalar memory reference.
By assigning a value to a character substring, you do not affect character positions in the character scalar memory reference 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 show valid and invalid character assignment statements and explain why the invalid ones are not valid. (In the examples, all memory references have a character data type.)
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 on right must have a character data type. |
STRING = 5HBEGIN |
Expression on right must have a character data type. (Hollerith constants are numeric, not character.) |