ILE COBOL Language Reference

Replacing Algorithm

For example, assuming three matched pairs of pseudo-text in a REPLACE statement:

  1. The comparison starts with the leftmost source program text word following the REPLACE statement, and with the first pseudo-text-1.
  2. Pseudo-text-1 is compared to an equivalent number of contiguous source program text words according to the following rules:
  3. If no match occurs, the comparison is repeated with each successive occurrence of pseudo-text-1 (in our example, there are three occurrences), until a match is found (go to Step 5)
  4. If no match is found after all, the next source program text word is treated as the leftmost program text word, and the cycle begins again at Step 1
  5. When a match is found, the corresponding pseudo-text-2 replaces the matched text in the source program
  6. The source program text word immediately following the rightmost text word that participated in the match becomes the leftmost source program text word. The cycle starts again (Step 1) with the first occurrence of pseudo-text-1.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]