The code:
IDENTIFICATION DIVISION.
PROGRAM-ID. test2.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ITEM PIC X(6) VALUE "BABABC".
01 COUNT-0 PIC 99 VALUE 0.
01 COUNT-1 PIC 99 VALUE 0.
01 COUNT-2 PIC 99 VALUE 0.
01 COUNT-3 PIC 99 VALUE 0.
01 COUNT-4 PIC 99 VALUE 0.
PROCEDURE DIVISION.
INSPECT ITEM TALLYING
COUNT-0 FOR ALL "AB", ALL "D"
COUNT-1 FOR ALL "BC"
COUNT-2 FOR LEADING "EF"
COUNT-3 FOR LEADING "B"
COUNT-4 FOR CHARACTERS;
INSPECT ITEM REPLACING
ALL "AB" BY "XY", "D" BY "X"
ALL "BC" BY "VW"
LEADING "EF" BY "TU"
LEADING "B" BY "S"
FIRST "G" BY "R"
FIRST "G" BY "P"
CHARACTERS BY "Z"
DISPLAY "Counts are: "
COUNT-0 SPACE
COUNT-1 SPACE
COUNT-2 SPACE
COUNT-3 SPACE
COUNT-4
DISPLAY "Should be: "
"02" SPACE
"00" SPACE
"00" SPACE
"01" SPACE
"01"
DISPLAY "Result is " """" ITEM """"
MOVE "SXYXYZ" TO ITEM
DISPLAY "Should be " """" ITEM """"
GOBACK.
END PROGRAM test2.
The result after compiling with GC 3.2.1:
Counts are: 02 00 00 01 06
Should be: 02 00 00 01 01
Result is "�XYXY"
Should be "SXYXYZ"
After going through the ISO rules and adding all examples but the not-yet implemented
BACKWARDSphrase (hm, should add them as skipped...), I totally see the bug here.both the counting and replacing have the same underlying issue - the internal "already done" is reset within the statement, fixing this showed a missing "+ 1" for marking the length - I'll check those fixes in along with the testsuite adjustments, soon.
Corroboration: I compiled your program with GCOBOL. The results: