3.3 Character Assignment Statement

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
v
Is a character scalar memory reference.
e
Is a character expression.

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.


Note
When the run-time system assigns a value to a scalar memory reference and the memory reference is shorter than the value being assigned, the assigned value may be truncated and significant characters lost. This truncation can occur without warning, and can cause the run-time system to pass incorrect information back to the program.

Examples

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.) 


Previous Page Next Page Table of Contents