A concatenation operation is specified by combining operands with the concatenation infix operator:
||
Concatenation signifies that the operands are to be joined in such a way that the last character, bit, graphic or widechar of the operand to the left immediately precedes the first character, bit, graphic or widechar of the operand to the right, with nothing intervening.
The concatenation operator can cause conversion to a string type because concatenation can be performed only upon strings--either character, bit, graphic or widechar. The results differ according to the setting of the RULES compiler option:
When you specify RULES(IBM), the concatenation operator behaves as follows:
For example:
dcl B bin(4) initial(4),
C bit(1) initial('1'b);
put skip list (B || C);
/* Produces '01001' not 'bbb41' */
When you specify RULES(ANS), the concatenation operator behaves as follows:
Consider this example:
dcl B bin(4) initial(4),
C bit(1) initial('1'b);
put skip list (B || C);
/* Produces 'bbb41', not '01001' */
The result of a concatenation operation is a string whose length is equal to the sum of the lengths of the two operands, and whose type (that is, character, bit, graphic or widechar) is the same as that of the two operands.
If an operand requires conversion for concatenation, the result depends upon the length of the string to which the operand is converted.
| For these operands and values | This operation | Yields this result |
|---|---|---|
|
A = '010111'B B = '101'B C = 'xy,Z' D = 'aa/BB' |
A || B |
'010111_101'B |
|
A || A || B |
'010111_010111_101'B |
|
|
C || D |
'xy,Zaa/BB' |
|
|
D || C |
'aa/BBxy,Z' |
|
|
B || D |
'101aa/BB' |
In the last example, the bit string '101'B is converted to the character string '101' before the concatenation is performed. The result is a character string.