String Literal Source Parts

A string literal of 96 bits or less is a short string literal. A short string literal is evaluated at compilation time and stored, left-justified, in a one-word or two-word operand. Character size information is discarded.

A string literal of more than 96 bits is a long string literal. A long string literal is evaluated at compilation time and stored in a portion of an array called a pool array. The character size and address of the string literal are stored in a pointer called a pool array pointer.

The compiler calculates the number of characters in a string literal in terms of the largest character size specified by the string literal. The following are calculations for various string literals:

String Literal

Number of Characters

4"C1"

2

8"AB"

2

48"01"

1

4"01""A"

2 (if the default character type is EBCDIC)

<string literal>

If the source part is a short string literal, it is processed as follows:

  1. At compilation time, the number of characters in the string is calculated.

  2. At run time, the string literal is stored, left-justified with zero fill, in a one-word or two-word stack-source-operand.

  3. The stack-integer-counter is assigned the value for the string length calculated at compilation time (see step 1).

  4. Characters are copied from the stack-source-operand to the destination specified by the stack-destination-pointer. The stack-integer-counter specifies the number of characters copied, and the stack-destination-pointer specifies the character size. If the destination is specified by a noncharacter array row or array element, the character size is eight bits.

If the source part is a long string literal, it is processed as follows:

  1. At compilation time, the number of characters in the string is calculated.

  2. At run time, the stack-source-pointer is assigned the value of the pool array pointer to the long string literal, which includes the character size and address.

  3. The character sizes of the stack-source-pointer and the stack-destination-pointer are compared. If they are not equal, the program is discontinued with a fault.

  4. The stack-integer-counter is assigned the value for the string length calculated at compilation time (see step 1).

  5. The number of characters specified by the stack-integer-counter are copied from the pool array to the destination specified by the stack-destination-pointer.

Examples of a <string literal>

REPLACE P BY "ABC"

In the following example, the three EBCDIC characters ABC are copied to the destination pointed to by P.

In the following example, the 20-character EBCDIC string is copied to the destination pointed to by P. At the end of the statement, P is left pointing to the first character position after the last character copied.

REPLACE P:P BY "A MUCH LONGER STRING"

In the following example, because the source, a string literal, is only four 4-bit characters long, it is evaluated as a single word; the character size is not retained. Because the destination is an 8-bit pointer, and four characters are to be replaced, four 8-bit characters are copied to the destination. At the end of the statement, the destination contains 4"12340000", which are the leftmost 32 bits of the stack-source-operand 4"123400000000".

REPLACE P BY 4"1234"

<string literal> FOR <arithmetic expression>

If the source part is a short string literal, it is processed as follows:

  • At compilation time, the string literal is stored in a one- or two-word operand. If the string literal is less than or equal to 48 bits long, it is stored, left-justified, and repeated for fill in a one-word operand. If the string literal is more than 48 bits long, it is stored, left-justified with zero fill, in a two-word operand.

  • At run time, this operand is assigned to the stack-source-operand.

  • If the arithmetic expression yields a positive value, this value is rounded to an integer, if necessary, and assigned to the stack-integer-counter; otherwise, zero is assigned to the stack-integer-counter.

  • The number of characters specified by the stack-integer-counter are copied to the destination specified by the stack-destination-pointer. If the stack-source-operand contains fewer than the specified number of characters, it is reused as many times as necessary. The character size is specified by the stack-destination-pointer. If the destination is specified by a noncharacter array row or array element, the character size is eight bits.

In the following examples, the first column shows a source part, and the second column shows the resulting string. A question mark (?) represents a null character.

Source Part

Result

"A" FOR 20

AAAAAAAAAAAAAAAAAAAA

"AB" FOR 20

ABABABABABABABABABAB

"ABC" FOR 20

ABCABCABCABCABCABCAB

"ABCD" FOR 20

ABCDABABCDABABCDABAB

"ABCDEF" FOR 20

ABCDEFABCDEFABCDEFAB

"ABCDEFGH" FOR 20

ABCDEFGH????ABCDEFGH

If the source part is a long string literal, it is processed as follows:

  1. The stack-source-pointer is assigned the value of the pool array pointer to the long string literal, which includes the character size and address.

  2. The character sizes of the stack-source-pointer and the stack-destination-pointer are compared. If they are not equal, the program is discontinued with a fault.

  3. If the arithmetic expression yields a positive value, this value is rounded to an integer, if necessary, and assigned to the stack-integer-counter; otherwise, zero is assigned to the stack-integer-counter.

  4. The number of characters specified by the stack-integer-counter are copied to the destination specified by the stack-destination-pointer.

The <string literal> FOR <arithmetic expression> syntax is undefined for a long string literal if the integerized value of the arithmetic expression is greater than the length of the string literal in characters. For example, the result of the following statement is undefined:

REPLACE POINTER(A) BY "ABCDEFGHIJKLMNO" FOR 30

<string literal> FOR <arithmetic expression> WORDS

If the source part is a short string literal, it is processed as follows:

  1. At compilation time, the string literal is stored in a one- or two-word operand. If the string literal is less than or equal to 48 bits long, is stored, left-justified and repeated for fill, in a one-word operand. If the string literal is more than 48 bits long, it is stored, left-justified with zero fill, in a two-word operand.

  2. At run time, this operand is assigned to the stack-source-operand.

  3. If the arithmetic expression yields a positive value, this value is rounded to an integer, if necessary, and assigned to the stack-integer-counter; otherwise, zero is assigned to the stack-integer-counter.

  4. The stack-destination-pointer is moved forward, if necessary, to the nearest word boundary.

  5. The number of words specified by the stack-integer-counter are copied from the stack-source-operand to the destination specified by the stack-destination-pointer. If the stack-source-operand contains fewer than the specified number of words, it is reused as often as necessary.

In the following examples, the first column shows a source part, and the second column shows the resulting string. A question mark (?) represents a null character.

Source Part

Result

"ABCD" FOR 2 WORDS

ABCDABABCDAB

"ABCDEFGH" FOR 2 WORDS

ABCDEFGH????

"ABCDEFGH" FOR 3 WORDS

ABCDEFGH????ABCDEF

If the source part is a long string literal, it is processed as follows:

  1. The stack-source-pointer is assigned the value of the pool array pointer to the long string literal, which includes the character size and address.

  2. The character sizes of the stack-source-pointer and the stack-destination-pointer are compared. If they are not equal, the program is discontinued with a fault.

  3. If the arithmetic expression yields zero or a positive value, this value is rounded to an integer, if necessary, and assigned to the stack-integer-counter; otherwise, zero is assigned to the stack-integer-counter.

  4. The stack-destination-pointer is moved forward, if necessary, to the nearest word boundary.

  5. The number of words specified by the stack-integer-counter are copied from the stack-source-operand to the destination indicated by the stack-destination-pointer.

The <string literal> FOR <arithmetic expression> WORDS syntax is undefined for a long string literal if the integerized value of the arithmetic expression is greater than the length of the string literal in 48-bit words. For example, the result of the following statement is undefined:

REPLACE POINTER(A) BY "ABCDEFGHIJKLMNO" FOR 6 WORDS