REPLACING Phrase (Formats 2 and 3)

identifier-3 or literal-1
The subject field.
identifier-5 or literal-3
The substitution field.
The subject field and the substitution field must have the same length. The following replacement rules apply:
  • If the subject field is a figurative constant, it is considered to be a 1-character nonnumeric literal. Each character in the inspected item equivalent to the figurative constant is replaced by the single-character substitution field, which must be 1 character in length.
  • If the substitution field is a figurative constant, the substitution field is considered to be the same length as the subject field. Each non-overlapping occurrence of the subject field in the inspected item is replaced by the substitution field.
  • When the subject and substitution fields are character-strings, each non-overlapping occurrence of the subject field in the inspected item is replaced by the character-string specified in the substitution field.
  • Once replacement has occurred in a given character position in the inspected item, no further replacement for that character position is made in this execution of the INSPECT statement.

When the CHARACTERS phrase is used, literal-3 or identifier-5 must be 1 character in length, and literal-2 or identifier-4 must be 1 character in length.

When neither the BEFORE nor AFTER phrase is specified, the following actions take place when the INSPECT REPLACING statement is executed:
  • If CHARACTERS is specified, the substitution field must be 1 character in length. Each character in the inspected field is replaced by the substitution field, beginning at the leftmost character and continuing to the rightmost.
  • If ALL is specified, each non-overlapping occurrence of the subject field in the inspected item is replaced by the substitution field, beginning at the leftmost character and continuing to the rightmost.
  • If LEADING is specified, each contiguous non-overlapping occurrence of the subject field in the inspected item is replaced by the substitution field, provided that the leftmost such occurrence is at the point where comparison began in the first comparison cycle for which this substitution field is eligible to participate.
  • If FIRST is specified, the leftmost occurrence of the subject field in the inspected item is replaced by the substitution field.