https://gcc.gnu.org/g:9b9b0ccffaf6185f5f44734755ebb7ae085ed745

commit r15-9180-g9b9b0ccffaf6185f5f44734755ebb7ae085ed745
Author: Bob Dubner <rdub...@symas.com>
Date:   Wed Apr 2 18:01:08 2025 -0400

    cobol: New testcases for INSPECT statement.
    
    gcc/testsuite
    
            * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.cob: New 
testcase.
            * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.cob: Likewise.
            * cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.cob: Likewise.
            * cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.cob: Likewise.
            * cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.cob: Likewise.
            * cobol.dg/group2/INSPECT_CONVERTING_NULL.cob: Likewise.
            * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constant.cob: 
Likewise.
            * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob: 
Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_1.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_2.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_3.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_4.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_5.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_5-f.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_5-r.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_6.cob: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_7.cob: Likewise.
            * cobol.dg/group2/INSPECT_No_repeat_conversion_check.cob: Likewise.
            * cobol.dg/group2/INSPECT_REPLACING_figurative_constant.cob: 
Likewise.
            * cobol.dg/group2/INSPECT_REPLACING_LEADING_ZEROS_BY_SPACES.cob: 
Likewise.
            * cobol.dg/group2/INSPECT_TALLYING_AFTER.cob: Likewise.
            * cobol.dg/group2/INSPECT_TALLYING_BEFORE.cob: Likewise.
            * cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.cob: 
Likewise.
            * cobol.dg/group2/INSPECT_TRAILING.cob: Likewise.
            * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.out: New 
known-good result.
            * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.out: Likewise.
            * cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.out: Likewise.
            * cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.out: Likewise.
            * cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.out: Likewise.
            * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out: 
Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_1.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_2.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_3.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_4.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_5-f.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_5.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_5-r.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_6.out: Likewise.
            * cobol.dg/group2/INSPECT_ISO_Example_7.out: Likewise.
            * cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.out: 
Likewise.
            * cobol.dg/group2/INSPECT_TRAILING.out: Likewise.

Diff:
---
 .../group2/INSPECT_BACKWARD_REPLACING_LEADING.cob  |  43 +++++++
 .../group2/INSPECT_BACKWARD_REPLACING_LEADING.out  |  10 ++
 .../group2/INSPECT_BACKWARD_REPLACING_TRAILING.cob |  44 +++++++
 .../group2/INSPECT_BACKWARD_REPLACING_TRAILING.out |  10 ++
 .../group2/INSPECT_BACKWARD_simple_CONVERTING.cob  | 105 +++++++++++++++
 .../group2/INSPECT_BACKWARD_simple_CONVERTING.out  |  15 +++
 .../group2/INSPECT_BACKWARD_simple_REPLACING.cob   |  29 +++++
 .../group2/INSPECT_BACKWARD_simple_REPLACING.out   |   7 +
 .../group2/INSPECT_BACKWARD_simple_TALLYING.cob    |  78 +++++++++++
 .../group2/INSPECT_BACKWARD_simple_TALLYING.out    |  14 ++
 .../cobol.dg/group2/INSPECT_CONVERTING_NULL.cob    |  15 +++
 .../INSPECT_CONVERTING_TO_figurative_constant.cob  |  15 +++
 .../INSPECT_CONVERTING_TO_figurative_constants.cob |  27 ++++
 .../INSPECT_CONVERTING_TO_figurative_constants.out |   6 +
 .../cobol.dg/group2/INSPECT_ISO_Example_1.cob      |  83 ++++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_1.out      |   9 ++
 .../cobol.dg/group2/INSPECT_ISO_Example_2.cob      |  75 +++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_2.out      |   7 +
 .../cobol.dg/group2/INSPECT_ISO_Example_3.cob      |  68 ++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_3.out      |  13 ++
 .../cobol.dg/group2/INSPECT_ISO_Example_4.cob      |  71 +++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_4.out      |   5 +
 .../cobol.dg/group2/INSPECT_ISO_Example_5-f.cob    |  81 ++++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_5-f.out    |   9 ++
 .../cobol.dg/group2/INSPECT_ISO_Example_5-r.cob    |  77 +++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_5-r.out    |   9 ++
 .../cobol.dg/group2/INSPECT_ISO_Example_5.cob      |  90 +++++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_5.out      |   7 +
 .../cobol.dg/group2/INSPECT_ISO_Example_6.cob      |  58 +++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_6.out      |   5 +
 .../cobol.dg/group2/INSPECT_ISO_Example_7.cob      |  65 ++++++++++
 .../cobol.dg/group2/INSPECT_ISO_Example_7.out      |   9 ++
 .../group2/INSPECT_No_repeat_conversion_check.cob  |  17 +++
 .../INSPECT_REPLACING_LEADING_ZEROS_BY_SPACES.cob  |  13 ++
 .../INSPECT_REPLACING_figurative_constant.cob      |  15 +++
 .../cobol.dg/group2/INSPECT_TALLYING_AFTER.cob     |  26 ++++
 .../cobol.dg/group2/INSPECT_TALLYING_BEFORE.cob    |  26 ++++
 .../INSPECT_TALLYING_REPLACING_ISO_Example.cob     | 142 +++++++++++++++++++++
 .../INSPECT_TALLYING_REPLACING_ISO_Example.out     |  13 ++
 gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.cob |  58 +++++++++
 gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.out |   6 +
 41 files changed, 1475 insertions(+)

diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.cob
new file mode 100644
index 000000000000..bfe4b6744d8b
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.cob
@@ -0,0 +1,43 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_BACKWARD_REPLACING_LEADING.out" }
+        identification  division.
+        program-id.     caller.
+        data            division.
+        working-storage section.
+        77 str          pic x(19) value "AAAAsomeABthingBBBB".
+        procedure division.
+        display "Starting with                                    " """" str 
"""" "..."
+        
+        initialize str all value.
+        inspect str replacing all "A" by "X"
+        display "After inspect          replacing     ALL A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect str replacing leading "A" by "X"
+        display "After inspect          replacing LEADING A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing all "A" by "X"
+        display "After inspect backward replacing     ALL A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing leading "A" by "X"
+        display "After inspect backward replacing LEADING A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect str replacing all "B" by "X"
+        display "After inspect          replacing     ALL B by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect str replacing leading "B" by "X"
+        display "After inspect          replacing LEADING B by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing all "B" by "X"
+        display "After inspect backward replacing     ALL B by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing leading "B" by "X"
+        display "After inspect backward replacing LEADING B by X: " """" str 
"""" 
+        goback.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.out
new file mode 100644
index 000000000000..3e9c3c379d8e
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.out
@@ -0,0 +1,10 @@
+Starting with                                    "AAAAsomeABthingBBBB"...
+After inspect          replacing     ALL A by X: "XXXXsomeXBthingBBBB"
+After inspect          replacing LEADING A by X: "XXXXsomeABthingBBBB"
+After inspect backward replacing     ALL A by X: "XXXXsomeXBthingBBBB"
+After inspect backward replacing LEADING A by X: "AAAAsomeABthingBBBB"
+After inspect          replacing     ALL B by X: "AAAAsomeAXthingXXXX"
+After inspect          replacing LEADING B by X: "AAAAsomeABthingBBBB"
+After inspect backward replacing     ALL B by X: "AAAAsomeAXthingXXXX"
+After inspect backward replacing LEADING B by X: "AAAAsomeABthingXXXX"
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.cob
new file mode 100644
index 000000000000..c2e6a096cc28
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.cob
@@ -0,0 +1,44 @@
+       *> { dg-do run }
+       *> { dg-options "-dialect mf" }
+       *> { dg-output-file "group2/INSPECT_BACKWARD_REPLACING_TRAILING.out" }
+        identification  division.
+        program-id.     caller.
+        data            division.
+        working-storage section.
+        77 str          pic x(19) value "AAAAsomeABthingBBBB".
+        procedure division.
+        display "Starting with                                     " """" str 
"""" "..."
+        
+        initialize str all value.
+        inspect str replacing all "A" by "X"
+        display "After inspect          replacing      ALL A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect str replacing trailing "A" by "X"
+        display "After inspect          replacing TRAILING A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing all "A" by "X"
+        display "After inspect backward replacing      ALL A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing trailing "A" by "X"
+        display "After inspect backward replacing TRAILING A by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect str replacing all "B" by "X"
+        display "After inspect          replacing      ALL B by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect str replacing trailing "B" by "X"
+        display "After inspect          replacing TRAILING B by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing all "B" by "X"
+        display "After inspect backward replacing      ALL B by X: " """" str 
"""" 
+
+        initialize str all value.
+        inspect backward str replacing trailing "B" by "X"
+        display "After inspect backward replacing TRAILING B by X: " """" str 
"""" 
+        goback.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.out
new file mode 100644
index 000000000000..c8f492d7c184
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.out
@@ -0,0 +1,10 @@
+Starting with                                     "AAAAsomeABthingBBBB"...
+After inspect          replacing      ALL A by X: "XXXXsomeXBthingBBBB"
+After inspect          replacing TRAILING A by X: "AAAAsomeABthingBBBB"
+After inspect backward replacing      ALL A by X: "XXXXsomeXBthingBBBB"
+After inspect backward replacing TRAILING A by X: "XXXXsomeABthingBBBB"
+After inspect          replacing      ALL B by X: "AAAAsomeAXthingXXXX"
+After inspect          replacing TRAILING B by X: "AAAAsomeABthingXXXX"
+After inspect backward replacing      ALL B by X: "AAAAsomeAXthingXXXX"
+After inspect backward replacing TRAILING B by X: "AAAAsomeABthingBBBB"
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.cob
new file mode 100644
index 000000000000..fbf9e09dba26
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.cob
@@ -0,0 +1,105 @@
+       *> { dg-do run }
+       *> { dg-options "-dialect mf" }
+       *> { dg-output-file "group2/INSPECT_BACKWARD_simple_CONVERTING.out" }
+
+        program-id.         prog.
+        data                division.
+        working-storage     section.
+        01 item             pic x(64).
+        01 should-be        pic x(64).
+        procedure division.
+        display "Forward:"
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+        move "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" before "jumps"
+        move "THE QUICK BROWN FOX jumps over the lazy dog" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" before "nothing"
+        move "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" after "fox"
+        move "the quick brown fox JUMPS OVER THE LAZY DOG" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" after "fox" before "over"
+        move "the quick brown fox JUMPS over the lazy dog" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" after "fox" before "xyzzy"
+        move "the quick brown fox JUMPS OVER THE LAZY DOG" to should-be
+        perform reportt
+
+        display "Reverse:"
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect backward item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+        move "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect backward item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" before "jumps"
+        move "the quick brown fox jumps OVER THE LAZY DOG" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect backward item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" before "nothing"
+        move "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect backward item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" after "fox"
+        move "THE QUICK BROWN fox jumps over the lazy dog" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect backward item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" before "fox" after "over"
+        move "the quick brown fox JUMPS over the lazy dog" to should-be
+        perform reportt
+
+        move "the quick brown fox jumps over the lazy dog" to item
+        inspect backward item converting 
+                "abcdefghijklmnopqrstuvwxyz"
+            TO  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" before "xyzzy" after "over"
+        move "THE QUICK BROWN FOX JUMPS over the lazy dog" to should-be
+        perform reportt
+
+        goback.
+        reportt.
+            display "                 " function trim(item)
+        if item not equal to should-be
+            display "should have been " function trim(should-be)
+        end-if.
+        end program prog.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.out
new file mode 100644
index 000000000000..0675c63cbb52
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.out
@@ -0,0 +1,15 @@
+Forward:
+                 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
+                 THE QUICK BROWN FOX jumps over the lazy dog
+                 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
+                 the quick brown fox JUMPS OVER THE LAZY DOG
+                 the quick brown fox JUMPS over the lazy dog
+                 the quick brown fox JUMPS OVER THE LAZY DOG
+Reverse:
+                 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
+                 the quick brown fox jumps OVER THE LAZY DOG
+                 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
+                 THE QUICK BROWN fox jumps over the lazy dog
+                 the quick brown fox JUMPS over the lazy dog
+                 THE QUICK BROWN FOX JUMPS over the lazy dog
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.cob
new file mode 100644
index 000000000000..4714e5eb5941
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.cob
@@ -0,0 +1,29 @@
+       *> { dg-do run }
+       *> { dg-options "-dialect mf" }
+       *> { dg-output-file "group2/INSPECT_BACKWARD_simple_REPLACING.out" }
+
+        program-id.         prog.
+        data                division.
+        working-storage     section.
+        01 item pic x(64).
+        procedure division.
+
+        move "AbcAbcXAbcAbcAbcYAbcAbcAbcAbcZAbcAbcAbcAbcAbc" to item
+        display function trim(item)
+        inspect backward item replacing all "Abc" by "Qrs"
+        display function trim(item)
+
+        move "AbcAbcXAbcAbcAbcYAbcAbcAbcAbcZAbcAbcAbcAbcAbc" to item
+        display function trim(item)
+        inspect backward item replacing trailing "Abc" by "Qrs"
+        display function trim(item)
+
+        move "AbcAbcXAbcAbcAbcYAbcAbcAbcAbcZAbcAbcAbcAbcAbc" to item
+        display function trim(item)
+        inspect backward item replacing all "Abc" by "Qrs"
+                after "Z" before "Y"
+        display function trim(item)
+
+        goback.
+        end program prog.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.out
new file mode 100644
index 000000000000..230ab91b107f
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.out
@@ -0,0 +1,7 @@
+AbcAbcXAbcAbcAbcYAbcAbcAbcAbcZAbcAbcAbcAbcAbc
+QrsQrsXQrsQrsQrsYQrsQrsQrsQrsZQrsQrsQrsQrsQrs
+AbcAbcXAbcAbcAbcYAbcAbcAbcAbcZAbcAbcAbcAbcAbc
+QrsQrsXAbcAbcAbcYAbcAbcAbcAbcZAbcAbcAbcAbcAbc
+AbcAbcXAbcAbcAbcYAbcAbcAbcAbcZAbcAbcAbcAbcAbc
+AbcAbcXAbcAbcAbcYQrsQrsQrsQrsZAbcAbcAbcAbcAbc
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.cob
new file mode 100644
index 000000000000..7cd284f57068
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.cob
@@ -0,0 +1,78 @@
+       *> { dg-do run }
+       *> { dg-options "-dialect mf" }
+       *> { dg-output-file "group2/INSPECT_BACKWARD_simple_TALLYING.out" }
+
+        program-id.         prog.
+        data                division.
+        working-storage     section.
+        01 item pic x(64).
+        01 counter pic 999.
+        procedure division.
+
+        move "AAXAAAYAAAAZAAAAA" to item
+        display function trim(item)
+        display "Forward:"
+
+        move zero to counter
+        inspect item tallying 
+            counter for all "A" 
+        display  "FOR ALL A                  " counter
+
+        move zero to counter
+        move "AAXAAAYAAAAZAAAAA" to item
+        inspect item tallying 
+            counter for all "A" after "X"
+        display  "FOR ALL A after X          " counter
+        
+        move zero to counter
+        move "AAXAAAYAAAAZAAAAA" to item
+        inspect item tallying 
+            counter for all "A" before "Z"
+        display  "FOR ALL A before Z         " counter
+
+        move zero to counter
+        move "AAXAAAYAAAAZAAAAA" to item
+        inspect item tallying 
+            counter for all "A" after "X" before "Z"
+        display  "FOR ALL A after X before Z " counter
+
+        move zero to counter
+        move 
"AAXAAAYAAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" to item
+        inspect item tallying 
+            counter for trailing "A"
+        display  "FOR TRAILING A             " counter
+
+
+        display "Backward:"
+        move zero to counter
+        inspect backward item tallying 
+            counter for all "A" 
+        display  "FOR ALL A                  " counter
+
+        move zero to counter
+        move "AAXAAAYAAAAZAAAAA" to item
+        inspect backward item tallying 
+            counter for all "A" after "X"
+        display  "FOR ALL A after X          " counter
+        
+        move zero to counter
+        move "AAXAAAYAAAAZAAAAA" to item
+        inspect backward item tallying 
+            counter for all "A" before "Z"
+        display  "FOR ALL A before Z         " counter
+
+        move zero to counter
+        move "AAXAAAYAAAAZAAAAA" to item
+        inspect backward item tallying 
+            counter for all "A" after "Z" before "X"
+        display  "FOR ALL A after Z before X " counter
+
+        move zero to counter
+        move "AAXAAAYAAAAZAAAAA" to item
+        inspect backward item tallying 
+            counter for trailing "A"
+        display  "FOR TRAILING A             " counter
+
+        goback.
+        end program prog.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.out
new file mode 100644
index 000000000000..73d900626380
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.out
@@ -0,0 +1,14 @@
+AAXAAAYAAAAZAAAAA
+Forward:
+FOR ALL A                  014
+FOR ALL A after X          012
+FOR ALL A before Z         009
+FOR ALL A after X before Z 007
+FOR TRAILING A             052
+Backward:
+FOR ALL A                  061
+FOR ALL A after X          002
+FOR ALL A before Z         005
+FOR ALL A after Z before X 007
+FOR TRAILING A             002
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_NULL.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_NULL.cob
new file mode 100644
index 000000000000..26a760c1cf6a
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_NULL.cob
@@ -0,0 +1,15 @@
+       *> { dg-do run }
+
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 X             PIC X(3) VALUE LOW-VALUES.
+       PROCEDURE        DIVISION.
+           INSPECT X CONVERTING NULL TO "A".
+           IF X NOT = "AAA"
+              DISPLAY X NO ADVANCING
+              END-DISPLAY
+           END-IF.
+           STOP RUN.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constant.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constant.cob
new file mode 100644
index 000000000000..fe1605e91f9c
--- /dev/null
+++ 
b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constant.cob
@@ -0,0 +1,15 @@
+       *> { dg-do run }
+
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 X             PIC X(3) VALUE "BCA".
+       PROCEDURE        DIVISION.
+           INSPECT X CONVERTING "ABC" TO SPACES.
+           IF X NOT = SPACES
+              DISPLAY X NO ADVANCING
+              END-DISPLAY
+           END-IF.
+           STOP RUN.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob
new file mode 100644
index 000000000000..2983cce07bfc
--- /dev/null
+++ 
b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob
@@ -0,0 +1,27 @@
+       *> { dg-do run }
+       *> { dg-output-file 
"group2/INSPECT_CONVERTING_TO_figurative_constants.out" }
+
+        identification division.
+        program-id. clouseau.
+        data division.
+        working-storage section.
+        01 item pic x(12).
+        procedure division.
+        move all "abcd" to item
+        inspect item converting "abcd" to low-values
+        display "low-values " space """" item """"
+        move all "abcd" to item
+        inspect item converting "abcd" to spaces
+        display "spaces     " space """" item """"
+        move all "abcd" to item
+        inspect item converting "abcd" to zeros
+        display "zeros      " space """" item """"
+        move all "abcd" to item
+        inspect item converting "abcd" to quotes
+        display "quotes     " space """" item """"
+        move all "abcd" to item
+        inspect item converting "abcd" to high-values
+        display "high-values" space """" item """"
+        goback.
+        end program clouseau.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out
new file mode 100644
index 000000000000..7de6e4810209
--- /dev/null
+++ 
b/gcc/testsuite/cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out
@@ -0,0 +1,6 @@
+low-values  ""
+spaces      "            "
+zeros       "000000000000"
+quotes      """"""""""""""
+high-values "ÿÿÿÿÿÿÿÿÿÿÿÿ"
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_1.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_1.cob
new file mode 100644
index 000000000000..1bbdea447524
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_1.cob
@@ -0,0 +1,83 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_1.out" }
+        Identification Division.
+        Program-Id. Clouseau.
+        Data Division.
+        Working-Storage Section.
+        01 rows   pic 99 value 3.
+        01 counts pic 99 value 5.
+
+        01 rowlim pic 99.
+        01 ncount pic 99.
+
+        01 inputs.
+           05 row occurs  6 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 count PIC 99 occurs 5 times.
+              10 output PIC X(20).
+        77 len PIC 9(8).
+        Procedure Division.
+        *> Odd-numbered rows are "read only" and contain the inputs and 
expected
+        *> outputs.
+        *> Even-numbered rows are modified by the INSPECT statements and 
contain
+        *> the observed outputs
+        Move ' EFABDBCGABEFGG      0301010005TUXYXVWRXYZZPZ' to row(1).
+        Move ' BABABC              0200000101SXYXYZ'         to row(3).
+        Move ' BBBC                0001000200SSVW'           to row(5).
+`
+        compute rowlim = 2*rows - 1
+
+        Display '  INPUT                C0 C1 C2 C3 C4 OUTPUT'
+        Display '  -------------------- -- -- -- -- -- ----------------'
+        Perform Example-1 with test after
+            varying counter from 1 by 2 until counter >= rowlim.
+
+        Goback.
+
+        Inspection Section.
+        Example-1.
+        Move row(counter) to row(counter + 1)
+
+        perform varying ncount from 1 by 1 until ncount > counts
+            Move Zero to count(counter + 1 ncount)
+            end-perform
+
+        Move function length( function trim(input(counter)) ) to len.
+        MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
+        INSPECT INPUT(COUNTER)(1:len) TALLYING
+            COUNT(counter + 1 1) FOR ALL "AB", ALL "D"
+            COUNT(counter + 1 2) FOR ALL "BC"
+            COUNT(counter + 1 3) FOR LEADING "EF"
+            COUNT(counter + 1 4) FOR LEADING "B"
+            COUNT(counter + 1 5) FOR CHARACTERS
+        INSPECT OUTPUT(COUNTER + 1)(1:len) 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"
+
+        If row(counter) = row(counter + 1) then
+            Move '*' to star(counter + 1)
+        Else
+            Move '!' to star(counter + 1).
+
+        Display star(counter)     ' '
+                input(counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(counter ncount) ' ' with no advancing
+            end-perform
+        display function trim (output(counter))
+
+        Display  star(1 + counter)    ' '
+                input(1 + counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(1 + counter ncount) ' ' with no advancing
+            end-perform
+        display function trim (output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_1.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_1.out
new file mode 100644
index 000000000000..b3b354ce26ec
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_1.out
@@ -0,0 +1,9 @@
+  INPUT                C0 C1 C2 C3 C4 OUTPUT
+  -------------------- -- -- -- -- -- ----------------
+  EFABDBCGABEFGG       03 01 01 00 05 TUXYXVWRXYZZPZ
+* EFABDBCGABEFGG       03 01 01 00 05 TUXYXVWRXYZZPZ
+  BABABC               02 00 00 01 01 SXYXYZ
+* BABABC               02 00 00 01 01 SXYXYZ
+  BBBC                 00 01 00 02 00 SSVW
+* BBBC                 00 01 00 02 00 SSVW
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_2.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_2.cob
new file mode 100644
index 000000000000..a464101ae16d
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_2.cob
@@ -0,0 +1,75 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_2.out" }
+
+        Identification Division.
+        Program-Id. Clouseau.
+        Data Division.
+        Working-Storage Section.
+        01 rows   pic 99 value 2.
+        01 counts pic 99 value 2.
+
+        01 rowlim pic 99.
+        01 ncount pic 99.
+
+        01 inputs.
+           05 row occurs  4 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 count PIC 99 occurs 2 times.
+              10 output PIC X(20).
+        77 len PIC 9(8).
+        Procedure Division.
+        *> Odd-numbered rows are "read only" and contain the inputs and 
expected
+        *> outputs.
+        *> Even-numbered rows are modified by the INSPECT statements and 
contain
+        *> the observed outputs
+        Move ' BBB                 0300ZZZ' to row(1).
+        Move ' ABA                 0300ZZZ' to row(3).
+`
+        compute rowlim = 2*rows - 1
+
+        Display '  INPUT                C0 C1 OUTPUT'
+        Display '  -------------------- -- -- ----------------'
+        Perform Example-1 with test after
+            varying counter from 1 by 2 until counter >= rowlim.
+
+        Goback.
+
+        Inspection Section.
+        Example-1.
+        Move row(counter) to row(counter + 1)
+
+        perform varying ncount from 1 by 1 until ncount > counts
+            Move Zero to count(counter + 1 ncount)
+            end-perform
+
+        Move function length( function trim(input(counter)) ) to len.
+        MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
+        INSPECT INPUT(COUNTER)(1:len) TALLYING
+            COUNT(counter + 1 1) FOR CHARACTERS
+            COUNT(counter + 1 2) FOR ALL "A";
+        INSPECT OUTPUT(COUNTER + 1)(1:len) REPLACING
+            CHARACTERS BY "Z"
+            ALL "A" BY "X"
+
+        If row(counter) = row(counter + 1) then
+            Move '*' to star(counter + 1)
+        Else
+            Move '!' to star(counter + 1).
+
+        Display star(counter)     ' '
+                input(counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(counter))
+
+        Display  star(1 + counter)    ' '
+                input(1 + counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(1 + counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_2.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_2.out
new file mode 100644
index 000000000000..65eb71c36f79
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_2.out
@@ -0,0 +1,7 @@
+  INPUT                C0 C1 OUTPUT
+  -------------------- -- -- ----------------
+  BBB                  03 00 ZZZ
+* BBB                  03 00 ZZZ
+  ABA                  03 00 ZZZ
+* ABA                  03 00 ZZZ
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_3.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_3.cob
new file mode 100644
index 000000000000..7111e9c10715
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_3.cob
@@ -0,0 +1,68 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_3.out" }
+
+        Identification Division.
+        Program-Id. Clouseau.
+        Data Division.
+        Working-Storage Section.
+        01 inputs.
+           05 row occurs 10 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 count PIC 99 occurs 3 times.
+              10 output PIC X(20).
+        77 len PIC 9(8).
+
+        Procedure Division.
+        Move ' BBEABDABABBCABE     030002BBEXYZXYXYZCABV' to row(1).
+        Move ' ADDDDC              000004AZZZZC'  to row(3).
+        Move ' ADDDDA              000005AZZZZZ'  to row(5).
+        Move ' CDDDDC              000000CDDDDC'  to row(7).
+        Move ' BDBBBDB             000300BDWWWDB' to row(9).
+`
+        Display '  INPUT                C0 C1 C2 OUTPUT'
+        Display '  -------------------- -- -- -- --------------------'
+        Perform Example-3 with test after
+            varying counter from 1 by 2 until counter = 9.
+
+        Goback.
+
+        Inspection Section.
+        Example-3.
+        Move row(counter) to row(counter + 1)
+        Move input(counter) to output(counter)
+        Move Zero to count(counter 1)
+        Move Zero to count(counter 2)
+        Move Zero to count(counter 3)
+
+        Move function length( function trim(input(counter)) ) to len.
+        INSPECT OUTPUT(COUNTER)(1:len) TALLYING
+             COUNT(counter 1) FOR ALL "AB" BEFORE "BC"
+             COUNT(counter 2) FOR LEADING "B" AFTER "D"
+             COUNT(counter 3) FOR CHARACTERS AFTER "A" BEFORE "C";
+        INSPECT OUTPUT(COUNTER)(1:len) REPLACING
+             ALL "AB" BY "XY" BEFORE "BC"
+             LEADING "B" BY "W" AFTER "D"
+             FIRST "E" BY "V" AFTER "D"
+             CHARACTERS BY "Z" AFTER "A" BEFORE "C"
+
+       If row(counter) = row(counter + 1) then
+          Move '*' to star(counter + 1)
+       Else
+          Move '!' to star(counter + 1).
+
+       Display star(counter)   ' '
+                input(counter)   ' '
+                count(counter 1) ' '
+                count(counter 2) ' '
+                count(counter 3) ' '
+               function trim(output(counter))
+        Display star(1 + counter)   ' '
+                input(1 + counter)   ' '
+                count(1 + counter 1) ' '
+                count(1 + counter 2) ' '
+                count(1 + counter 3) ' '
+               function trim(output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_3.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_3.out
new file mode 100644
index 000000000000..268fa3e5173e
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_3.out
@@ -0,0 +1,13 @@
+  INPUT                C0 C1 C2 OUTPUT
+  -------------------- -- -- -- --------------------
+  BBEABDABABBCABE      03 00 02 BBEXYZXYXYZCABV
+* BBEABDABABBCABE      03 00 02 BBEXYZXYXYZCABV
+  ADDDDC               00 00 04 AZZZZC
+* ADDDDC               00 00 04 AZZZZC
+  ADDDDA               00 00 05 AZZZZZ
+* ADDDDA               00 00 05 AZZZZZ
+  CDDDDC               00 00 00 CDDDDC
+* CDDDDC               00 00 00 CDDDDC
+  BDBBBDB              00 03 00 BDWWWDB
+* BDBBBDB              00 03 00 BDWWWDB
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_4.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_4.cob
new file mode 100644
index 000000000000..192e1a83a304
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_4.cob
@@ -0,0 +1,71 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_4.out" }
+
+        Identification Division.
+        Program-Id. Clouseau.
+        Data Division.
+        Working-Storage Section.
+        01 rows   pic 99 value 1.
+        01 counts pic 99 value 1.
+
+        01 rowlim pic 99.
+        01 ncount pic 99.
+
+        01 inputs.
+           05 row occurs  2 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 count PIC 99 occurs 1 times.
+              10 output PIC X(20).
+        77 len PIC 9(8).
+        Procedure Division.
+        *> Odd-numbered rows are "read only" and contain the inputs and 
expected
+        *> outputs.
+        *> Even-numbered rows are modified by the INSPECT statements and 
contain
+        *> the observed outputs
+        Move ' ABABABABC           01ABABXYABC' to row(1).
+`
+        compute rowlim = 2*rows - 1
+
+        Display '  INPUT                C0 C1 OUTPUT'
+        Display '  -------------------- -- -- ----------------'
+        Perform Example-1 with test after
+            varying counter from 1 by 2 until counter >= rowlim.
+
+        Goback.
+
+        Inspection Section.
+        Example-1.
+        Move row(counter) to row(counter + 1)
+
+        perform varying ncount from 1 by 1 until ncount > counts
+            Move Zero to count(counter + 1 ncount)
+            end-perform
+
+        Move function length( function trim(input(counter)) ) to len.
+        MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
+        INSPECT INPUT(COUNTER)(1:len) TALLYING
+            COUNT(counter + 1 1) FOR ALL "AB" AFTER "BA" BEFORE "BC";
+        INSPECT OUTPUT(COUNTER + 1)(1:len) REPLACING
+            ALL "AB" BY "XY" AFTER "BA" BEFORE "BC"
+        If row(counter) = row(counter + 1) then
+            Move '*' to star(counter + 1)
+        Else
+            Move '!' to star(counter + 1).
+
+        Display star(counter)     ' '
+                input(counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(counter))
+
+        Display  star(1 + counter)    ' '
+                input(1 + counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(1 + counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_4.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_4.out
new file mode 100644
index 000000000000..a2ae6e5109b3
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_4.out
@@ -0,0 +1,5 @@
+  INPUT                C0 C1 OUTPUT
+  -------------------- -- -- ----------------
+  ABABABABC            01 ABABXYABC
+* ABABABABC            01 ABABXYABC
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-f.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-f.cob
new file mode 100644
index 000000000000..09237203c129
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-f.cob
@@ -0,0 +1,81 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_5-f.out" }
+
+        Identification Division.
+        Program-Id. Clouseau.
+        *> Note:  Although modeled on Example-5 in Appendix D of the ISO 2023
+        *> specification, all three of the samples are incorrect.  This code
+        *> modifies the problem to make it somewhat more interesting, and, of
+        *> course, changes the answers so that they are correct for the 
problem.
+        Data Division.
+        Working-Storage Section.
+        01 rows   pic 99 value 3.
+        01 counts pic 99 value 3.
+
+        01 rowlim pic 99.
+        01 ncount pic 99.
+
+        01 inputs.
+           05 row occurs  6 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 count PIC 99 occurs 3 times.
+              10 output PIC X(20).
+        77 len PIC 9(8).
+        Procedure Division.
+        *> Odd-numbered rows are "read only" and contain the inputs and 
expected
+        *> outputs.
+        *> Even-numbered rows are modified by the INSPECT statements and 
contain
+        *> the observed outputs
+        Move ' ABABBCAB            000106ABABBCXY' to row(1).
+        Move ' ABDBABC             000001AVDBABC'  to row(3).
+        Move ' BCABCABD            010000BCABCAVD' to row(5).
+`
+        compute rowlim = 2*rows - 1
+
+        Display '  INPUT                C0 C1 C2 OUTPUT'
+        Display '  -------------------- -- -- -- ----------------'
+        Perform Example-1 with test after
+            varying counter from 1 by 2 until counter >= rowlim.
+
+        Goback.
+
+        Inspection Section.
+        Example-1.
+        Move row(counter) to row(counter + 1)
+        
+        perform varying ncount from 1 by 1 until ncount > counts
+            Move Zero to count(counter + 1 ncount)
+            end-perform
+
+        Move function length( function trim(input(counter)) ) to len.
+        MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
+        INSPECT BACKWARD INPUT(COUNTER)(1:len) TALLYING
+            COUNT(counter + 1 1) FOR ALL "AB" BEFORE "BC"
+            COUNT(counter + 1 2) FOR LEADING "B"
+            COUNT(counter + 1 3) FOR CHARACTERS AFTER "A" BEFORE "D"
+        INSPECT BACKWARD OUTPUT(COUNTER + 1)(1:len) REPLACING
+            ALL "AB" BY "XY" BEFORE "BC"
+            LEADING "B" BY "V" AFTER "D"
+
+        If row(counter) = row(counter + 1) then
+            Move '*' to star(counter + 1)
+        Else
+            Move '!' to star(counter + 1).
+
+        Display star(counter)     ' '
+                input(counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(counter))
+
+        Display  star(1 + counter)    ' '
+                input(1 + counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(1 + counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-f.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-f.out
new file mode 100644
index 000000000000..dbfef1011558
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-f.out
@@ -0,0 +1,9 @@
+  INPUT                C0 C1 C2 OUTPUT
+  -------------------- -- -- -- ----------------
+  ABABBCAB             00 01 06 ABABBCXY
+* ABABBCAB             00 01 06 ABABBCXY
+  ABDBABC              00 00 01 AVDBABC
+* ABDBABC              00 00 01 AVDBABC
+  BCABCABD             01 00 00 BCABCAVD
+* BCABCABD             01 00 00 BCABCAVD
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-r.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-r.cob
new file mode 100644
index 000000000000..bf9299a1d037
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-r.cob
@@ -0,0 +1,77 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_5-r.out" }
+
+        Identification Division.
+        Program-Id. Clouseau.
+        Data Division.
+        Working-Storage Section.
+        01 rows   pic 99 value 3.
+        01 counts pic 99 value 3.
+
+        01 rowlim pic 99.
+        01 ncount pic 99.
+
+        01 inputs.
+           05 row occurs  6 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 count PIC 99 occurs 3 times.
+              10 output PIC X(20).
+        77 len PIC 9(8).
+        Procedure Division.
+        *> Odd-numbered rows are "read only" and contain the inputs and 
expected
+        *> outputs.
+        *> Even-numbered rows are modified by the INSPECT statements and 
contain
+        *> the observed outputs
+        Move ' BACBBABA            000004BACBBXYA' to row(1).
+        Move ' CBABDBA             000005CBAVDBA'  to row(3).
+        Move ' DBACBACB            000100DBACBACB' to row(5).
+
+        compute rowlim = 2*rows - 1
+
+        Display '  INPUT                C0 C1 C2 C3 C4 OUTPUT'
+        Display '  -------------------- -- -- -- -- -- ----------------'
+        Perform Example-1 with test after
+            varying counter from 1 by 2 until counter >= rowlim.
+
+        Goback.
+
+        Inspection Section.
+        Example-1.
+        Move row(counter) to row(counter + 1)
+        
+        perform varying ncount from 1 by 1 until ncount > counts
+            Move Zero to count(counter + 1 ncount)
+            end-perform
+
+        Move function length( function trim(input(counter)) ) to len.
+        MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
+        INSPECT BACKWARD INPUT(COUNTER)(1:len) TALLYING
+            COUNT(counter + 1 1) FOR ALL "AB" BEFORE "BC"
+            COUNT(counter + 1 2) FOR LEADING "B"
+            COUNT(counter + 1 3) FOR CHARACTERS AFTER "A" BEFORE "C"
+        INSPECT BACKWARD OUTPUT(COUNTER + 1)(1:len) REPLACING
+            ALL "AB" BY "XY" BEFORE "BC"
+            LEADING "B" BY "V" AFTER "D"
+
+        If row(counter) = row(counter + 1) then
+            Move '*' to star(counter + 1)
+        Else
+            Move '!' to star(counter + 1).
+
+        Display star(counter)     ' '
+                input(counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(counter))
+
+        Display  star(1 + counter)    ' '
+                input(1 + counter)   ' ' with no advancing
+        perform varying ncount from 1 by 1 until ncount > counts
+            Display count(1 + counter ncount) ' ' with no advancing
+            end-perform
+        display function trim(output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-r.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-r.out
new file mode 100644
index 000000000000..02e8d673e09d
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-r.out
@@ -0,0 +1,9 @@
+  INPUT                C0 C1 C2 C3 C4 OUTPUT
+  -------------------- -- -- -- -- -- ----------------
+  BACBBABA             00 00 04 BACBBXYA
+* BACBBABA             00 00 04 BACBBXYA
+  CBABDBA              00 00 05 CBAVDBA
+* CBABDBA              00 00 05 CBAVDBA
+  DBACBACB             00 01 00 DBACBACB
+* DBACBACB             00 01 00 DBACBACB
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5.cob
new file mode 100644
index 000000000000..016777bb446e
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5.cob
@@ -0,0 +1,90 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_5.out" }
+        Identification Division.
+        Program-Id. Clouseau.
+        *> Note:  Although modeled on Example-5 in Appendix D of the ISO 2023
+        *> specification, all six of the samples are incorrect.
+        *> This code executes the examples as written, and the test suite 
checks
+        *> For the answers believed to be correct
+        Data Division.
+        Working-Storage Section.
+        01 item-1 pic x(8) value "ABABBCAB".
+        01 item-2 pic x(7) value "ABDBABC".
+        01 item-3 pic x(8) value "BCABCABD".
+        01 count-0 pic 9 value zero.
+        01 count-1 pic 9 value zero.
+        01 count-2 pic 9 value zero.
+        Procedure Division.
+
+        initialize item-1 item-2 item-3 count-0 count-1 count-2 all value
+        display item-1 "   " with no advancing
+        INSPECT BACKWARD ITEM-1 TALLYING
+            COUNT-0 FOR ALL "AB" BEFORE "BC"
+            COUNT-1 FOR LEADING "B"
+            COUNT-2 FOR CHARACTERS AFTER "A" BEFORE "C"
+        INSPECT BACKWARD ITEM-1 REPLACING
+            ALL "AB" BY "XY" BEFORE "BC"
+            LEADING "B" BY "V" AFTER "D"
+        display count-0 space count-1 space count-2 space item-1
+
+        initialize item-1 item-2 item-3 count-0 count-1 count-2 all value
+        display item-2 "    " with no advancing
+        INSPECT BACKWARD ITEM-2 TALLYING
+            COUNT-0 FOR ALL "AB" BEFORE "BC"
+            COUNT-1 FOR LEADING "B"
+            COUNT-2 FOR CHARACTERS AFTER "A" BEFORE "C"
+        INSPECT BACKWARD ITEM-2 REPLACING
+            ALL "AB" BY "XY" BEFORE "BC"
+            LEADING "B" BY "V" AFTER "D"
+        display count-0 space count-1 space count-2 space item-2
+
+        initialize item-1 item-2 item-3 count-0 count-1 count-2 all value
+        display item-3 "   " with no advancing
+        INSPECT BACKWARD ITEM-3 TALLYING
+            COUNT-0 FOR ALL "AB" BEFORE "BC"
+            COUNT-1 FOR LEADING "B"
+            COUNT-2 FOR CHARACTERS AFTER "A" BEFORE "C"
+        INSPECT BACKWARD ITEM-3 REPLACING
+            ALL "AB" BY "XY" BEFORE "BC"
+            LEADING "B" BY "V" AFTER "D"
+        display count-0 space count-1 space count-2 space item-3
+
+        initialize item-1 item-2 item-3 count-0 count-1 count-2 all value
+        MOVE FUNCTION REVERSE (ITEM-1) TO ITEM-1
+        display item-1 "   " with no advancing
+        INSPECT ITEM-1 TALLYING
+        COUNT-0 FOR ALL "AB" BEFORE "BC"
+        COUNT-1 FOR LEADING "B"
+        COUNT-2 FOR CHARACTERS AFTER "A" BEFORE "C"
+        INSPECT BACKWARD ITEM-1 REPLACING
+        ALL "AB" BY "XY" BEFORE "BC"
+        LEADING "B" BY "V" AFTER "D"
+        display count-0 space count-1 space count-2 space item-1
+
+        initialize item-1 item-2 item-3 count-0 count-1 count-2 all value
+        MOVE FUNCTION REVERSE (ITEM-2) TO ITEM-2
+        display item-2 "    " with no advancing
+        INSPECT ITEM-2 TALLYING
+        COUNT-0 FOR ALL "AB" BEFORE "BC"
+        COUNT-1 FOR LEADING "B"
+        COUNT-2 FOR CHARACTERS AFTER "A" BEFORE "C"
+        INSPECT BACKWARD ITEM-2 REPLACING
+        ALL "AB" BY "XY" BEFORE "BC"
+        LEADING "B" BY "V" AFTER "D"
+        display count-0 space count-1 space count-2 space item-2
+
+        initialize item-1 item-2 item-3 count-0 count-1 count-2 all value
+        MOVE FUNCTION REVERSE (ITEM-3) TO ITEM-3
+        display item-3 "   " with no advancing
+        INSPECT ITEM-3 TALLYING
+        COUNT-0 FOR ALL "AB" BEFORE "BC"
+        COUNT-1 FOR LEADING "B"
+        COUNT-2 FOR CHARACTERS AFTER "A" BEFORE "C"
+        INSPECT BACKWARD ITEM-3 REPLACING
+        ALL "AB" BY "XY" BEFORE "BC"
+        LEADING "B" BY "V" AFTER "D"
+        display count-0 space count-1 space count-2 space item-3
+
+        goback.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5.out
new file mode 100644
index 000000000000..afcfb7239454
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5.out
@@ -0,0 +1,7 @@
+ABABBCAB   0 1 0 ABABBCXY
+ABDBABC    0 0 0 AVDBABC
+BCABCABD   1 0 0 BCABCAVD
+BACBBABA   1 1 0 BACBBXYA
+CBABDBA    1 0 0 CBAVDBA
+DBACBACB   0 0 0 DBACBACB
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_6.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_6.cob
new file mode 100644
index 000000000000..75917a2d78c4
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_6.cob
@@ -0,0 +1,58 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_6.out" }
+
+        Identification Division.
+        Program-Id. Clouseau.
+        Data Division.
+        Working-Storage Section.
+        01 rows   pic 99 value 1.
+
+        01 rowlim pic 99.
+        01 ncount pic 99.
+
+        01 inputs.
+           05 row occurs  6 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 output PIC X(20).
+        77 len PIC 9(8).
+        Procedure Division.
+        *> Odd-numbered rows are "read only" and contain the inputs and 
expected
+        *> outputs.
+        *> Even-numbered rows are modified by the INSPECT statements and 
contain
+        *> the observed outputs
+        Move ' AC"AEBDFBCD#AB"D    AC"XEYXFYZX#AB"D' to row(1).
+`
+        compute rowlim = 2*rows - 1
+
+        Display '  INPUT                OUTPUT'
+        Display '  -------------------- ----------------'
+        Perform Example-1 with test after
+            varying counter from 1 by 2 until counter >= rowlim.
+
+        Goback.
+
+        Inspection Section.
+        Example-1.
+        Move row(counter) to row(counter + 1)
+
+        Move function length( function trim(input(counter)) ) to len.
+        MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
+        INSPECT OUTPUT(COUNTER + 1)(1:len) CONVERTING
+            "ABCD" TO "XYZX" AFTER QUOTE BEFORE "#".
+
+        If row(counter) = row(counter + 1) then
+            Move '*' to star(counter + 1)
+        Else
+            Move '!' to star(counter + 1).
+
+        Display star(counter)     ' '
+                input(counter)   ' ' with no advancing
+        display function trim(output(counter))
+
+        Display  star(1 + counter)    ' '
+                input(1 + counter)   ' ' with no advancing
+        display function trim(output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_6.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_6.out
new file mode 100644
index 000000000000..dfe5f4b08896
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_6.out
@@ -0,0 +1,5 @@
+  INPUT                OUTPUT
+  -------------------- ----------------
+  AC"AEBDFBCD#AB"D     AC"XEYXFYZX#AB"D
+* AC"AEBDFBCD#AB"D     AC"XEYXFYZX#AB"D
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_7.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_7.cob
new file mode 100644
index 000000000000..ca2ae71ed0bd
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_7.cob
@@ -0,0 +1,65 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_ISO_Example_7.out" }
+        Identification Division.
+        Program-Id. Clouseau.
+        Data Division.
+        Working-Storage Section.
+        01 rows   pic 99 value 3.
+
+        01 rowlim pic 99.
+        01 ncount pic 99.
+
+        01 inputs.
+           05 row occurs  6 times indexed by counter.
+              10 star  PIC X.
+              10 input PIC X(20).
+              10 output PIC X(20).
+        77 len PIC 9(8).
+        
+        Linkage Section.
+        77 result PIC 9(8) Value 0.
+        
+        Procedure Division returning result.
+        *> Odd-numbered rows are "read only" and contain the inputs and 
expected
+        *> outputs.
+        *> Even-numbered rows are modified by the INSPECT statements and 
contain
+        *> the observed outputs
+        Move ' 415-245-1212        415-245-1212' to row(1).
+        Move ' 415-CH5-1212        415-??5-1212' to row(3).
+        Move ' 20%Numeric          20%???????' to row(5).
+`
+        compute rowlim = 2*rows - 1
+
+        Display '  INPUT                OUTPUT'
+        Display '  -------------------- ----------------'
+        Perform Example-1 with test after
+            varying counter from 1 by 2 until counter >= rowlim.
+
+        Goback.
+
+        Inspection Section.
+        Example-1.
+        Move row(counter) to row(counter + 1)
+        
+        Move function length( function trim(input(counter)) ) to len.
+        MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
+        INSPECT OUTPUT(COUNTER + 1)(1:len) CONVERTING
+            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+             TO ALL "?"
+
+        If row(counter) = row(counter + 1) then
+            Move '*' to star(counter + 1)
+        Else
+            Move 1 to result
+            Move '!' to star(counter + 1).
+
+        Display star(counter)     ' '
+                input(counter)   ' ' with no advancing
+        display function trim(output(counter))
+
+        Display  star(1 + counter)    ' '
+                input(1 + counter)   ' ' with no advancing
+        display function trim(output(1 + counter))
+        continue.
+        end program Clouseau.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_7.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_7.out
new file mode 100644
index 000000000000..2418c366b916
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_7.out
@@ -0,0 +1,9 @@
+  INPUT                OUTPUT
+  -------------------- ----------------
+  415-245-1212         415-245-1212
+* 415-245-1212         415-245-1212
+  415-CH5-1212         415-??5-1212
+* 415-CH5-1212         415-??5-1212
+  20%Numeric           20%???????
+* 20%Numeric           20%???????
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_No_repeat_conversion_check.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_No_repeat_conversion_check.cob
new file mode 100644
index 000000000000..358a1da8919e
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_No_repeat_conversion_check.cob
@@ -0,0 +1,17 @@
+       *> { dg-do run }
+
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 X             PIC X(3) VALUE "BCA".
+       01 Y             PIC X(6) VALUE "   BCA".
+       PROCEDURE        DIVISION.
+           INSPECT X CONVERTING "ABC" TO "BCD".
+           IF X NOT = "CDB"
+              DISPLAY "X: " X.
+           INSPECT Y CONVERTING "ABC" TO "BCD".
+           IF Y NOT = "   CDB"
+              DISPLAY "Y: " Y.
+           STOP RUN.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_REPLACING_LEADING_ZEROS_BY_SPACES.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_REPLACING_LEADING_ZEROS_BY_SPACES.cob
new file mode 100644
index 000000000000..d710292338ac
--- /dev/null
+++ 
b/gcc/testsuite/cobol.dg/group2/INSPECT_REPLACING_LEADING_ZEROS_BY_SPACES.cob
@@ -0,0 +1,13 @@
+       *> { dg-do run }
+
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 X             PIC X(4) VALUE "0001".
+       PROCEDURE        DIVISION.
+           INSPECT X REPLACING LEADING ZEROS BY SPACES.
+           IF X NOT = "   1"
+              DISPLAY "Should be '   1' but is '" X "'".
+           STOP RUN.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_REPLACING_figurative_constant.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_REPLACING_figurative_constant.cob
new file mode 100644
index 000000000000..5d706ebf46d0
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_REPLACING_figurative_constant.cob
@@ -0,0 +1,15 @@
+       *> { dg-do run }
+
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 X             PIC X(3) VALUE "BCA".
+       PROCEDURE        DIVISION.
+           INSPECT X REPLACING ALL "BC" BY SPACE.
+           IF X NOT = "  A"
+              DISPLAY X NO ADVANCING
+              END-DISPLAY
+           END-IF.
+           STOP RUN.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_AFTER.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_AFTER.cob
new file mode 100644
index 000000000000..c8cd95e2f003
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_AFTER.cob
@@ -0,0 +1,26 @@
+       *> { dg-do run }
+
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 X             PIC X(4) VALUE "ABC ".
+       01 TAL           PIC 999 VALUE 0.
+       PROCEDURE        DIVISION.
+           MOVE 0 TO TAL.
+           INSPECT X TALLYING TAL FOR CHARACTERS
+                     AFTER INITIAL " ".
+           IF TAL NOT = 0
+              DISPLAY TAL NO ADVANCING
+              END-DISPLAY
+           END-IF.
+           MOVE 0 TO TAL.
+           MOVE " ABC" TO X.
+           INSPECT X TALLYING TAL FOR CHARACTERS
+                     AFTER INITIAL " ".
+           IF TAL NOT = 3
+              DISPLAY TAL NO ADVANCING
+              END-DISPLAY
+           END-IF.
+           STOP RUN.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_BEFORE.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_BEFORE.cob
new file mode 100644
index 000000000000..5640ff5c992e
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_BEFORE.cob
@@ -0,0 +1,26 @@
+       *> { dg-do run }
+
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 X             PIC X(4) VALUE "ABC ".
+       01 TAL           PIC 999 VALUE 0.
+       PROCEDURE        DIVISION.
+           MOVE 0 TO TAL.
+           INSPECT X TALLYING TAL FOR CHARACTERS
+                     BEFORE INITIAL " ".
+           IF TAL NOT = 3
+              DISPLAY TAL NO ADVANCING
+              END-DISPLAY
+           END-IF.
+           MOVE 0 TO TAL.
+           MOVE " ABC" TO X.
+           INSPECT X TALLYING TAL FOR CHARACTERS
+                     BEFORE INITIAL " ".
+           IF TAL NOT = 0
+              DISPLAY TAL NO ADVANCING
+              END-DISPLAY
+           END-IF.
+           STOP RUN.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.cob
new file mode 100644
index 000000000000..ab1a4118074f
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.cob
@@ -0,0 +1,142 @@
+       *> { dg-do run }
+       *> { dg-output-file "group2/INSPECT_TALLYING_REPLACING_ISO_Example.out" 
}
+
+      *> Example from ISO/IEC 2023 page 1151
+        IDENTIFICATION DIVISION.
+        PROGRAM-ID. tests.
+        PROCEDURE DIVISION.
+        CALL "test1"
+        CALL "test2"
+        CALL "test3"
+        goback.
+        end program tests.
+
+        IDENTIFICATION DIVISION.
+        PROGRAM-ID. test1.
+        DATA DIVISION.
+        WORKING-STORAGE SECTION.
+        01 ITEM PIC X(14) VALUE "EFABDBCGABEFGG".
+        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:  "
+                "03" SPACE 
+                "01" SPACE
+                "01" SPACE
+                "00" SPACE
+                "05"
+        DISPLAY "Result is " """" ITEM """"
+        MOVE "TUXYXVWRXYZZPZ" TO  ITEM
+        DISPLAY "Should be " """" ITEM """"
+        GOBACK.
+        END PROGRAM test1.
+
+        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.
+
+        IDENTIFICATION DIVISION.
+        PROGRAM-ID. test3.
+        DATA DIVISION.
+        WORKING-STORAGE SECTION.
+        01 ITEM PIC X(4) VALUE "BBBC".
+        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:  "
+                "00" SPACE 
+                "01" SPACE
+                "00" SPACE
+                "02" SPACE
+                "00"
+        DISPLAY "Result is " """" ITEM """"
+        MOVE "SSVW" TO  ITEM
+        DISPLAY "Should be " """" ITEM """"
+        GOBACK.
+        END PROGRAM test3.
+
diff --git 
a/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.out
new file mode 100644
index 000000000000..58f40fedf800
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.out
@@ -0,0 +1,13 @@
+Counts are: 03 01 01 00 05
+Should be:  03 01 01 00 05
+Result is "TUXYXVWRXYZZPZ"
+Should be "TUXYXVWRXYZZPZ"
+Counts are: 02 00 00 01 01
+Should be:  02 00 00 01 01
+Result is "SXYXYZ"
+Should be "SXYXYZ"
+Counts are: 00 01 00 02 00
+Should be:  00 01 00 02 00
+Result is "SSVW"
+Should be "SSVW"
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.cob 
b/gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.cob
new file mode 100644
index 000000000000..231913c74369
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.cob
@@ -0,0 +1,58 @@
+       *> { dg-do run }
+       *> { dg-options "-dialect mf" }
+       *> { dg-output-file "group2/INSPECT_TRAILING.out" }
+
+        identification      division.
+        program-id.         prog.
+        data                division.
+        working-storage     section.
+        01 the-text         pic x(30) value "    middle".
+        01 counter          pic 9999.
+        01 expected         pic 9999.
+        01 should-be        pic zzz9.
+        01 but-is           pic zzz9.
+        01 msg              pic x(100).
+        procedure           division.
+        
+        move "inspect for leading spaces" to msg
+        move zero to counter
+        inspect the-text tallying counter for leading spaces
+        move 4 to expected
+        perform result.
+        
+        move "inspect for trailing spaces with reverse" to msg
+        move zero to counter
+        inspect function reverse(the-text) tallying counter for leading spaces
+        move 20 to expected
+        perform result.
+
+        move "inspect for trailing spaces with reversed variable" to msg
+        move function reverse(the-text) to the-text
+        move zero to counter
+        inspect the-text tallying counter for leading spaces
+        move 20 to expected
+        perform result.
+
+        move "inspect for trailing spaces with INSPECT TRAILING extension" to 
msg
+        move function reverse(the-text) to the-text
+        move zero to counter
+        inspect the-text tallying counter for trailing spaces
+        move 20 to expected
+        perform result.
+
+        inspect the-text replacing trailing space by "X"
+        display the-text
+
+        stop run.
+
+        result.
+        display function trim(msg) ": " with no advancing
+        move expected to should-be
+        if counter equal to expected
+            display function trim(should-be)
+        else
+            move counter  to but-is
+            display "should be " function trim(should-be) 
+                    " but is " function trim(but-is)
+        end-if.
+
diff --git a/gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.out 
b/gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.out
new file mode 100644
index 000000000000..e55c3e99edaf
--- /dev/null
+++ b/gcc/testsuite/cobol.dg/group2/INSPECT_TRAILING.out
@@ -0,0 +1,6 @@
+inspect for leading spaces: 4
+inspect for trailing spaces with reverse: 20
+inspect for trailing spaces with reversed variable: 20
+inspect for trailing spaces with INSPECT TRAILING extension: 20
+    middleXXXXXXXXXXXXXXXXXXXX
+

Reply via email to