rspec/rules/S4882/cobol/rule.adoc
2022-02-04 16:28:24 +00:00

40 lines
1.0 KiB
Plaintext

Some COBOL compilers such as IBM one will assume that the minimum value of ``++OCCURS DEPENDING ON++`` is 1 but nothing is enforcing that and this behaviour can change or be different when using another compiler.
Setting the minimum value of ``++OCCURS DEPENDING ON++`` makes the code more readable, and less dependent on compiler.
== Noncompliant Code Example
[source,cobol]
----
01 MY-TABLE-COUNT PIC S9(4) BINARY.
01 MY-TABLE.
03 MY-ITEM OCCURS 500 TIMES *> Noncompliant
DEPENDING ON MY-TABLE-COUNT.
05 MY-FIELD-01 PIC X(08).
05 MY-FIELD-02 PIC 9(05).
----
== Compliant Solution
[source,cobol]
----
01 MY-TABLE-COUNT PIC S9(4) BINARY.
01 MY-TABLE.
03 MY-ITEM OCCURS 1 TO 500 TIMES *> Compliant; minimum value is 1
DEPENDING ON MY-TABLE-COUNT.
05 MY-FIELD-01 PIC X(08).
05 MY-FIELD-02 PIC 9(05).
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]