rspec/rules/S3632/cobol/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

121 lines
3.5 KiB
Plaintext

== Why is this an issue?
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.
=== Noncompliant code example
[source,cobol]
----
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
[source,cobol]
----
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.
----
or
[source,cobol]
----
01 INVENTORY-RECORD.
05 Field-A PIC X OCCURS 10000 TIMES INDEXED BY IDX1.
...
PERFORM VARYING IDX1 FROM 1 BY 1 UNTIL IDX1 > 10000
MOVE ITEM1 TO Field-A (IDX1)
END-PERFORM.
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make "xxx" a binary type or use a different variable.
=== Highlighting
The table subscript, i.e. ``++(SUBS)++`` in
----
MOVE F337-CODE2-SPE (SUBS) TO ...
----
'''
== Comments And Links
(visible only on this page)
=== 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
MOVE ITEM1 TO Field-A (IDX1)
END-PERFORM.
----
=== on 21 Nov 2016, 16:16:55 Ann Campbell wrote:
Updated [~pierre-yves.nicolas]
endif::env-github,rspecator-view[]