INSPECT

INSPECT REPLACING ALL on 1 byte operands

Statement: INSPECT REPLACING ALL

Data types: PIC X

Options: Default

Conditions: In all cases

V4 behavior: Uses general translate instruction as in all cases

V6 behavior: Handle short cases with a simple test and move

Source Example:
1 ITEM PIC X(1)

INSPECT ITEM REPLACING ALL ‘ ‘ BY ‘.’.

Performance: V6 is 84% faster than V4

Consecutive INSPECTs on the same data item

Statement: More than one consecutive INSPECT REPLACING ALL on the same data item

Data types: PIC X

Options: OPT(1 | 2)

Conditions: When the compiler can prove, according to the rules of INSPECT, that the optimization will not alter the result.

V4 behavior: Generate separate operations for each INSPECT operation

V6 behavior: Coalesce the separate INSPECTs into a single INSPECT operation

Source Example:
1 ITEM PIC X(15)

INSPECT ITEM REPLACING ALL QUOTE BY SPACE.
INSPECT ITEM REPLACING ALL LOW-VALUE BY SPACE.

Performance: V6 is 57% faster than V4

INSPECT TALLYING ALL / INSPECT REPLACING ALL

Statement: INSPECT TALLYING ALL / INSPECT REPLACING ALL

Data types: PIC X

Options: ARCH(11)

Conditions: No BEFORE, AFTER, FIRST, or LEADING clause. For REPLACING, the replaced value must have length > 1

V4 behavior: Use regular instructions or runtime calls

COBOL 6 behavior: At ARCH(11), COBOL 6 is able to generate code using the vector instructions introduced in z13®. These instructions are able to process up to 16 bytes at a time

Source Example:
01 STR PIC X(255).
01 C PIC 9(5) COMP-5 VALUE 0.

INSPECT STR TALLYING C FOR ALL ' '

Performance: V6 ARCH(11) is 98% faster than V4

Source Example:
01 STR PIC X(255).

INSPECT STR REPLACING ALL 'AB' BY 'CD'

Performance: V6 ARCH(11) is 78% faster than V4