In general, the clause ``++INDEXED BY++`` should be used whenever possible when handling COBOL tables. If it's not possible, then avoid using a numeric display variable to access the table's elements. Instead, use a ``++BINARY++``/``++COMP++`` variable, which the processor can handle more efficiently.
=== on 8 Nov 2016, 09:43:02 Pierre-Yves Nicolas wrote:
\[~ann.campbell.2], I believe that the compliant solution should include the definition of ``++Row-IDX++`` the same way the non-compliant example includes the definition of ``++SUBS++``. In fact, I think that this is the only thing which should change between the 2 code samples (similarly as the examples for RSPEC-3671).
=== on 8 Nov 2016, 21:36:34 Ann Campbell wrote:
\[~pierre-yves.nicolas] I've added the definition of ``++Row-IDX++`` but not otherwise changed the Compliant Solution; both code samples came directly from the original rule requesters.
Also, I'm wondering if the loop format changes based on what you can do with a ``++PIC 99++`` vs a ``++PIC S9(n) BINARY++``
=== on 21 Nov 2016, 09:48:54 Pierre-Yves Nicolas wrote:
\[~ann.campbell.2] Sorry for replying late. In fact, indexes are usually not declared as data items (see http://www.ibm.com/support/knowledgecenter/SS6SG3_6.1.0/com.ibm.cobol61.ent.doc/PGandLR/tasks/tptbl12.html[some IBM documentation]).
I suggest the following changes:
Noncompliant Code Example
----
01 SUBS PIC 9(5).
01 INVENTORY-RECORD.
05 Field-A PIC X OCCURS 10000 TIMES.
...
PERFORM VARYING SUBS FROM 1 BY 1 UNTIL SUBS > 10000
MOVE ITEM1 TO Field-A (SUBS) *> Noncompliant
END-PERFORM.
----
Compliant Solution without ``++INDEXED BY++``
----
01 SUBS PIC 9(5) COMP.
01 INVENTORY-RECORD.
05 Field-A PIC X OCCURS 10000 TIMES.
...
PERFORM VARYING SUBS FROM 1 BY 1 UNTIL SUBS > 10000
MOVE ITEM1 TO Field-A (SUBS)
END-PERFORM.
----
Compliant Solution with ``++INDEXED BY++``
----
01 INVENTORY-RECORD.
05 Field-A PIC X OCCURS 10000 TIMES INDEXED BY IDX1.
...
PERFORM VARYING IDX1 FROM 1 BY 1 UNTIL IDX1 > 10000