Pointer Expression (<source>) Source Parts

<source> FOR <arithmetic expression>

A source part of this form is processed as follows:

  1. The pointer expression in the source is evaluated and assigned to the stack-source-pointer.

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

  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. If both the source and the destination are specified by noncharacter array rows or array elements, the character size of both the stack-source-pointer and the stack-destination-pointer is eight bits.

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

Example of a <source> FOR <arithmetic expression> Form

In the following example, the 20 EBCDIC characters pointed to by Q are copied to the location pointed to by P.

REPLACE P BY Q FOR 20

<source> FOR <arithmetic expression> WORDS

A source part of this form is processed as follows:

  1. The pointer expression in the source is evaluated and assigned to the stack-source-pointer.

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

  3. The stack-source-pointer and the stack-destination-pointer are moved forward, if necessary, to the nearest word boundary.

  4. The number of 48-bit words specified by the stack-integer-counter are copied from the location specified by the stack-source-pointer to the destination specified by the stack-destination-pointer.

The character sizes of the source and destination pointer expressions are irrelevant.

Example of <source> FOR <arithmetic expression> WORDS

Both P and Q are advanced to the nearest word boundary, if necessary, and 20 words are copied from the location pointed to by Q to the location pointed to by P.

REPLACE P BY Q FOR 20 WORDS

<source> FOR <arithmetic expression> WITH <translate table>

This construct retrieves characters from a source location, translates each character (through the use of the specified translate table) into a possibly different character with a possibly different character size, and stores each resulting character in the location indicated by the stack-destination-pointer.

The value of the pointer expression in the source points to the first character to be translated. The stack-source-pointer is initialized to this value. The stack-destination-pointer and the stack-source-pointer need not have the same character size. Instead, the stack-source-pointer must have a character size equal to that of the characters being translated, and the stack-destination-pointer must have a character size equal to that of the resulting translated characters; otherwise a Memory Protect fault or undefined results occur.

The value of the arithmetic expression indicates the number of characters to be translated and written to the destination. This value is integerized, if necessary, and assigned to the stack-integer-counter. The stack-auxiliary-pointer is initialized to point to the first character of the first word of the translate table, and its character size is absent. Normally, when a pointer is used and its character size is absent, a default value of six or eight is used, depending on the default character type. However, the character size of the pointer used to initialize the stack-auxiliary-pointer is irrelevant. The translate table is not examined sequentially (one character at a time); instead, the data in the table is accessed by special indexing techniques implemented in the hardware, as described in the following text.

<intrinsic translate table>

If the translate table is of this form, the stack-auxiliary-pointer is initialized to point to the appropriate intrinsic translate table. The function of each translate table can be deduced from its name. For example, the HEXTOEBCDIC table is used to translate characters from hexadecimal to EBCDIC.

<translate table identifier>

If the translate table is of this form, a translate table must have been declared in a TRANSLATETABLE declaration. For a detailed discussion regarding the construction of a translate table, refer to TRANSLATETABLE Declaration.

<subscripted variable>

If the translate table is of this form, the programmer is responsible for creating a properly structured translate table that does not cross array row or page boundary and begins with the word in the array row indicated by the subscripted variable. From the subscripted variable to the end of the array row or page, there must be enough words for the entire translate table: 4 or 64 words, depending on whether the character type is 4-bit, 7- or 8-bit, respectively. If there are not enough words for the translate table, an invalid index error can result at run time. For more information on translate table indexing, refer to TRANSLATETABLE Declaration.

Examples of the <source> FOR <arithmetic expression> WITH <translate table> Form

REPLACE POINTER(B,4) BY POINTER(A,8) FOR 30 WITH EBCDICTOHEX
    A = 8"0123456789ABCDEFGHIJabcdefghij"
    B = 4"0123456789ABCDEFFFFFABCDEFFFFF"
REPLACE POINTER(B,7) BY POINTER(A,8) FOR 14 WITH EBCDICTOASCII
    A = 4"F0F1F2F3F4F5F6F7F8F9C1C2C3C4"
    B = 4"3031323334353637383941424344"
REPLACE POINTER(B,8) BY POINTER(A,4) FOR 12 WITH HEXTOEBCDIC
    A = 8"012345" = 4"F0F1F2F3F4F5"
    B = 8"F0F1F2F3F4F5"

<source> WITH <picture identifier>

The character data specified by the source (which must be a pointer) is processed under control of the picture specified by the picture identifier. The source and destination pointers must be 4-bit, 8-bit, or word-oriented. If the source is a word-oriented pointer, it is changed to a 4-bit pointer if the destination is a 4-bit pointer; otherwise, it is changed to an 8-bit pointer. If the destination is a word-oriented pointer, it is changed to a 4-bit pointer if the source is a 4-bit pointer; otherwise, it is changed to an 8-bit pointer. If neither the source nor the destination pointer is a word-oriented pointer, the source and destination pointers must either both be 4-bit pointers or both be 8-bit pointers. Details regarding the formation and action of pictures are described under PICTURE Declaration.

When using a <picture identifier> that provides for character insertion, note the possibility of receiving an undefined result. This is described earlier in the explanation of the REPLACE statement, where both the source and destination are the same.