CRITICAL
Rule Definition
Using indexes to address a table is more efficient than using subscripts since the index already contains the
displacement from the start of the table and does not have to be calculated at run time. Subscripts, on the
other hand, contain an occurrence number that must be converted to a displacement value at run time
before it can be used. When using subscripts to address a table, use a binary (COMP) signed data item with
eight or fewer digits (for example, using PICTURE S9(8) COMP for the data item). This will allow fullword
arithmetic to be used during the calculations. Additionally, in some cases, using four or fewer digits for the
data item may also offer some added reduction in CPU time since halfword arithmetic can be used.
Remediation
Prefer to use index rather than subscript. Add an INDEXED clause in table definition and use this index.
Violation Code Sample
01 DIRECT-TAX-RATE.
02 TAX-RATE PIC 99 OCCURS 5 TIMES.
01 TX-INDEX PIC X(10).
...
SET TX-INDEX TO 4.
MOVE TAX-RATE(TX-INDEX) TO SEC-RATE.
Fixed Code Sample
01 DIRECT-TAX-RATE.
02 TAX-RATE PIC 99 OCCURS 5 TIMES INDEXED BY TX-INDEX.
...
SET TX-INDEX TO 4.
MOVE TAX-RATE(TX-INDEX) TO SEC-RATE.
Reference
IBM Cobol - Best Practices and Recommendations
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.