The source string is assigned to the target string from left to right. If the source string is longer than the target, excess characters, bits, graphics or widechars on the right are ignored, and the STRINGSIZE condition is raised. For fixed-length targets, if the target is longer than the source, the target is padded on the right. If STRINGSIZE is disabled, and the length of the source and/or the target is determined at run time, and the target is too short to contain the source, unpredictable results can occur.
Character strings are padded with blanks, bit strings with '0'B, graphic strings with DBCS blanks, and widechar strings with widechar blanks.
declare Subject char(10); Subject = 'Transformations';
'Transformations' has 15 characters, therefore, when PL/I assigns the string to Subject, it truncates five characters from the right end of the string. This is equivalent to executing the following:
Subject = 'Transforma';
The first two of the following statements assign equivalent values to Subject and the last two assign equivalent values to Code:
Subject = 'Physics'; Subject = 'Physics '; declare Code bit(10); Code = '110011'B; Code = '1100110000'B;
The following statements do not assign equivalent values to Subject:
Subject = '110011'B; Subject = '1100110000'B;
When the first statement is executed, the bit constant on the right is first converted to a character string and is then extended on the right with blank characters rather than zero characters. This statement is equivalent to:
Subject = '110011bbbb';
The second of the two statements requires only a conversion from bit to character type and is equivalent to:
Subject = '1100110000';
A string value is not extended with blank characters or zero bits when it is assigned to a string variable that has the VARYING attribute. Instead, the length of the target string variable is set to the length of the assigned string. However, truncation will occur if the length of the assigned string exceeds the maximum length declared for the varying-length string variable.