== Why is this an issue?

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

[source,cobol]
----
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

[source,cobol]
----
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
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Update the declarations of "XXX" and "YYY" to have the same format.


=== Highlighting

operands and operator


'''
== Comments And Links
(visible only on this page)

=== on 24 Mar 2016, 14:54:25 Ann Campbell wrote:
_Why_ is this inefficient and why does efficiency decrease as the number of formats in an operation increases?


What's the best corrective action? Change all the relevant var declarations? Perform intermediate calculations? Apply casts or conversions?

=== on 3 May 2016, 14:10:33 Pierre-Yves Nicolas wrote:
\[~ann.campbell.2] We should clarify what "different numeric formats" means:

* We should probably compare the USAGE clauses of the definitions of the operands, taking into account the default value and possible synonyms (e.g. COMP is the same as BINARY)
* According to an http://www.ibm.com/support/knowledgecenter/SS6SG3_6.1.0/com.ibm.cobol61.ent.doc/PGandLR/tasks/tpeff05b.html[IBM documentation], we should probably also compare the number of decimal places.
* Should we check that the PICTURE clauses are identical?

The current issue message is "Update the declaration of XXX to make it a YYY". If the 2 operands of a binary expression have different numeric formats, which definition should be updated? It's not always obvious, e.g. when operand 1 is COMP and operand 2 is COMP-3. The message could be changed to avoid this kind of problem.



=== on 3 May 2016, 14:18:48 Pierre-Yves Nicolas wrote:
\[~ann.campbell.2] Should we keep this rule restricted to "comparisons" or should we extend it to cover arithmetic expressions/statements? In the current code sample, a variable is incremented through a specific syntax (PERFORM VARYING...) using different numeric formats.

=== on 24 May 2016, 15:43:00 Ann Campbell wrote:
Per our discussion, I've forwarded these questions to the original requester.

=== on 29 Nov 2016, 09:34:52 Elena Vilchik wrote:
\[~ann.campbell.2] There is wording "the more formats there are in a comparison the less ...", while IMO it's weird to say "the more" if there are just max 2 possible. Do you think you could rephrase it? Thanks!

=== on 5 Dec 2016, 09:43:12 Ann Campbell wrote:
done [~elena.vilchik]

endif::env-github,rspecator-view[]
