Comparison rules

The comparison operation that determines text replacement starts with the leftmost source text word that follows the REPLACE statement, and with the first word of pseudo-text-1 or partial-word-1.

  • pseudo-text-1 is compared to an equivalent number of contiguous source text words. pseudo-text-1 matches the source text only if the ordered sequence of text words that forms pseudo-text-1 is equal, character for character, to the ordered sequence of source text words. For national characters, the sequence of national characters must be equal, national character for national character, to the ordered sequence of library words.
  • When the LEADING phrase is specified, partial-word-1 matches the source text only if the contiguous sequence of characters that forms partial-word-1 is equal, character for character, to an equal number of contiguous characters that start with the leftmost character position of a source text word.

    When the TRAILING phrase is specified, partial-word-1 matches the source text only if the contiguous sequence of characters that forms partial-word-1 is equal, character for character, to an equal number of contiguous characters that end with the rightmost character position of a source text word.

  • For matching purposes, each occurrence of a separator comma, a separator semicolon, or a sequence of one or more separator spaces is considered to be a single space.

    However, when pseudo-text-1 or partial-word-1 consists solely of a separator comma or separator semicolon, the comma or semicolon participates in the match as a text word. In this case, the space that follows the comma or semicolon separator can be omitted.

    When the source text contains a closing quotation mark that is not immediately followed by a separator space, a separator comma, a separator semicolon, or a separator period, the closing quotation mark is considered a separator quotation mark.

  • If no match occurs, the comparison is repeated with each successive occurrence of pseudo-text-1 or partial-word-1 if specified, until either a match is found or no further REPLACING operands exist.
  • When all occurrences of pseudo-text-1 or partial-word-1 are compared and no match occurs, the next successive source text word is then considered to be the leftmost source text word, and the comparison cycle starts again, beginning with the first occurrence of pseudo-text-1 or partial-word-1.
  • Whenever a match occurs between pseudo-text-1 and the source text, the corresponding pseudo-text-2 replaces the matched text in the source text. Whenever a match occurs between partial-word-1 and the source text word, the matched characters of that source text word are either replaced by partial-word-2 or deleted if partial-word-2 consists of zero text words.The source text word that immediately follows the rightmost text word that participated in the match is then considered as the leftmost source text word. The comparison cycle starts again, beginning with the first occurrence of pseudo-text-1 or partial-word-1.
  • The comparison operation continues until the rightmost text word in the source text that is within the scope of the REPLACE statement has either participated in a match, or been considered as a leftmost source text word and participated in a complete comparison cycle.