The comparison of numeric values of different formats is inefficient. For instance, comparing a COMP-3
with a COMP-4
causes a performance drag because conversions are required under the covers before the comparison.
This rule raises an issue when variables with different USAGE
clauses, or different numbers of decimal places are compared.
Noncompliant code example
01 SUB1 PIC 9999 BINARY
01 WS-DISPLAY-1 PIC 9(12)
01 WS-PACKED-DEC PIC 9(12)V9(2) COMP-3
01 WS-BIN PIC S9999 COMP-4
01 WS-DISPLAY-2 PIC 9(4)
PERFORM VARYING SUB1 FROM WS-DISPLAY-1
BY WS-PACKED-DEC
UNTIL WS-BIN > WS-DISPLAY-2 *> Noncompliant
* ...
END-PERFORM
Compliant solution
01 SUB1 PIC 9999 BINARY
01 WS-DISPLAY-1 PIC 9(12)
01 WS-PACKED-DEC PIC 9(12)V9(2) COMP-4
01 WS-BIN PIC S9999 COMP-4
01 WS-DISPLAY-2 PIC 9(4)
PERFORM VARYING SUB1 FROM WS-DISPLAY-1
BY WS-PACKED-DEC
UNTIL WS-BIN > WS-DISPLAY-2
* ...
END-PERFORM