General Rules

  1. The number of characters in Format 1 that obey certain conditions are counted by a special register named TALLY. Its PICTURE is 9(5) and USAGE is COMP-N. Its default value is zero.
  2. The characters to be counted and replaced are determined by the key words following TALLYING or REPLACING. Counting is done only in Format 1, and replacement is done only in Format 2 and when specified in Format 1.
    Key Words Characters To Be Counted And Replaced
    ALL Count and/or replace all instances of literal-1 with literal-2.
    FIRST Replace the first (left-most) instance of literal-1 with literal-2.
    LEADING Count and/or replace all instances of literal-1 that appear before (to the left of) any other character in the data item.
    UNTIL FIRST Count and/or replace all characters to the left of the first (left-most) instance of literal-1 with literal-2. If literal-1 does not appear in the data item, count and replace all characters in the data item.
  3. Literal-1 is the character to be counted. Literal-2 is the character that will replace literal-1. Note that the substitution of literal-2 for characters other than literal-1 occurs only when UNTIL FIRST is specified.
  4. The contents of the TALLY register are unchanged in Format 2. In Format 1, its contents are replaced by the appropriate character count, regardless of the previous contents.