rspec/rules/S3595/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

101 lines
2.1 KiB
Plaintext

== Why is this an issue?
The binary algorithm used by ``++SEARCH ALL++`` is far more efficient for large tables than the one used by ``++SEARCH++``. While it's not always possible to use ``++SEARCH ALL++``, it should be the preferred algorithm.
This rule raises an issue when tables with more than the specified number of possible entries are searched using ``++SEARCH++``.
=== Noncompliant code example
Using the default threshold of 500:
[source,cobol]
----
01 MY-TABLE.
05 MY-TAB-ELEM OCCURS 300000
INDEXED BY MY-TAB-IND.
10 MY-ATTR1 PIC X(07).
10 MY-ATTR2 PIC X(07).
10 MY-ATTR3 PIC X(07).
01 MY-TAB2.
05 MY-TAB2-ELEM OCCURS 300000
ASCENDING MY-ATTR1 *> Key is defined. Why not use it?
INDEXED BY MY-TAB-IND.
10 MY-ATTR1 PIC X(07).
10 MY-ATTR2 PIC X(07).
10 MY-ATTR3 PIC X(07).
01 MY-TAB-IND PIC 9(08).
SEARCH MY-TAB-ELEM. *> Noncompliant; define a key & use binary search
AT END...
SEARCH MY-TAB2-ELEM. *> Noncompliant
AT END...
----
=== Compliant solution
[source,cobol]
----
01 MY-TABLE.
05 MY-TAB-ELEM OCCURS 300000
ASCENDING MY-ATTR1
INDEXED BY MY-TAB-IND.
10 MY-ATTR1 PIC X(07).
10 MY-ATTR2 PIC X(07).
10 MY-ATTR3 PIC X(07).
01 MY-TAB2.
05 MY-TAB2-ELEM OCCURS 300000
ASCENDING MY-ATTR1
INDEXED BY MY-TAB-IND.
10 MY-ATTR1 PIC X(07).
10 MY-ATTR2 PIC X(07).
10 MY-ATTR3 PIC X(07).
01 MY-TAB-IND PIC 9(08).
SEARCH ALL MY-TAB-ELEM.
AT END...
SEARCH ALL MY-TAB2-ELEM.
AT END...
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
\[Sort this table and] [u|U]se "SEARCH ALL" instead of "SEARCH".
=== Parameters
.threshold
****
----
500
----
Minimum table size to require the use of binary searches
****
=== Highlighting
``++SEARCH tablename++``
endif::env-github,rspecator-view[]