The REPLACE statement causes character data from one or more sources to be stored in a designated portion of an array row.
<replace statement>
── REPLACE ──<destination>── BY ──<source part list>───────────────────┤
<destination>
──┬──────────────────┬─<pointer expression>────────────────────────────┤ └─<update pointer>─┘
<update pointer>
──<pointer variable>── : ──────────────────────────────────────────────┤
The REPLACE statement stores character data from one or more data sources into a designated portion of an array row. The array row and the starting character position within the array row are both determined by the pointer expression part of the destination syntax. The value of this pointer expression initializes the stack-destination-pointer. As each character is moved into the destination array row, the stack-destination-pointer is correspondingly incremented one character position.
If either the source or destination of the REPLACE statement is an 8-bit character-based pointer, and the array pointed to is a direct array larger than 65535 words, an attempt to index into and beyond word 65536 produces an undefined result or the program fails. Refer to POINTER Function for the description of an 8-bit (EBCDIC) character-based pointer.
When the last character has been stored in the destination array row, the corresponding final value of the stack-destination-pointer is stored in the pointer variable of the update pointer, if specified; otherwise, it is discarded. If the update pointer option for the <source> part is present, the pointer variable specified by the update pointer is assigned the final value of the stack-source-pointer for this <source> part. In either case, a bounds error can arise when the number of characters to be transferred is zero (or negative) and the final offset of the update pointer is beyond the last valid array row element + 1.

