This topic describes the COBOL code review rules in detail.
- Naming conventions:
- Use PROGRAM-ID that matches the source member name
- This rule compares the PROGRAM-ID with the source member name,
excluding any file extension. If they are not the same, the PROGRAM-ID
is flagged as a violation.
- Performance:
- Avoid INITIALIZE statements. Use elementary MOVE statements or
VALUE clauses.
- This rule locates all INITIALIZE statements and flags them as
violations.
- Avoid OCCURS DEPENDING ON clauses
- This rule locates all OCCURS DEPENDING ON phrases and flags them
as violations.
- Avoid subscripts in table access. Use indexes
- The rule examines all variables being used as indexes in a program.
Each variable’s declaration is then examined and if the variable is
not declared via INDEXED BY, it is flagged as a violation.
- Use an odd number of digits in a COMP-3 PICTURE clause
- All COMP-3 PICTURE declarations are examined, and if the number
of digits contained in the PICTURE phrase is not odd, the declaration
is flagged as a violation.
- Use binary subscripts
- This rule searches for all incidences of the subscripting of a
variable. If the variable is subscripted with a literal, those instances
are ignored. For each of the non literal subscripts, the definition
of that subscript is searched for in the data division. Each definition
is examined, and if the subscript is not declared as COMP, COMPUTATIONAL
or BINARY, the subscript is flagged as a rule violation.
- Use DFHRESP value to check response code
- This rule examines all EXEC CICS® blocks
for exception handling via RESP() or RESP2() and the COBOL definition
of the variable used is recorded. Consequently all relation conditions
(such as found in IF, ELSE and EVALUATE WHEN) are searched for this
variable, and if found, and an equality check is made against anything
other than the DFHRESP macro, then this relation condition is recorded
as a rule violation. In addition, any EVALUATE statement that uses
the response variable as its WHAT condition then has its WHEN clauses
examined. If they contain anything other than references to the DFHRESP
macro, the WHEN clauses are flagged as rule violations.
- Use EVALUATE statement rather than nested IF statement
- This rule examines all IF statements to see if they are contained
within a nested IF structure, and if so, that the parent IF structure
itself isn’t already recorded as a violation. Any statements matching
these criteria are flagged as rule violations.
- Use RESP option in EXEC command
- This rule examines all EXEC CICS blocks
and checks that a RESP() option is present. If no option is present,
the block is flagged as a violation.
- Program Structures:
- A GO TO statement can reference a paragraph only if it is an exit
paragraph
- This rule examines each GO TO statement in a program. If the GO
TO points to a section name, the statement is flagged as a violation.
If the GO TO points to a paragraph name, the rule locates the given
paragraph and checks to see if it consists solely of an EXIT statement.
If this is not the case, the GO TO is flagged as a rule violation.
- Avoid ACCEPT FROM CONSOLE statements
- This rule searches through all ACCEPT statements and flags any
using the “CONSOLE” or “SYSIN” parameters as violations.
- Avoid ACCEPT statements
- This rule flags all ACCEPT statements as violations.
- Avoid ALTER statements
- This rule flags all ALTER statements as violations.
- Avoid CALL statement with program-name.
- Use dynamic calls. This rule searches for all CALL statements
and flags any with a literal identifier as a violation.
- Avoid COPY SUPPRESS statements
- All COPY statements are examined. Any containing a SUPPRESS phrase
are flagged as violations.
- Avoid CORRESPONDING phrases
- ADD, SUBTRACT and MOVE statements are all examined for a CORRESPONDING
phrase. Any matches are flagged as violations
- Avoid ENTRY statements
- This rule flags all ENTRY statements as violations.
- Avoid EXIT PROGRAM statements
- This rule locates all EXIT PROGRAM statements and flags them as
violations.
- Avoid GO TO statements
- This rule locates all GO TO statements and flags them as violations.
- Avoid NEXT SENTENCE phrases
- This rule locates all NEXT SENTENCE phrases and flags them as
violations.
- Avoid RESERVE clause in FILE-CONTROL paragraphs
- This rule locates all RESERVE clauses in a program and flags them
as violations.
- Avoid STOP RUN and STOP literal statements
- This rule locates all STOP RUN and STOP Literal statements in
a program and flags them as violations.
- Avoid THRU phrase in PERFORM statements
- This rule examines all PERFORM statements and flags those with
a THRU phrase as rule violations.
- Use THRU phrase with PERFORM statement
- This rule examines all PERFORM statements and flags those without
a THRU phrase as rule violations
- Use WHEN OTHER phrase with EVALUATE statement
- This rule examines all EVALUATE statements. Those that do not
contain a WHEN OTHER phrase are flagged as violations.