The Code Review component supports built-in code review
rules for COBOL.
These rules are built into the Code Review
for COBOL component and do not require parameters. You can select
these rules from the Enterprise
COBOL, Naming Conventions, Performance, and Program Structures
categories in the software analysis configuration window.
For more information about using this window, see Creating a software analysis configuration.
- Enterprise COBOL:
- Avoid language elements that are obsolete in Enterprise COBOL
5.1
- Use this rule to flag any language element that is obsolete in IBM® Enterprise COBOL for z/OS®. The following elements are
flagged:
- Obsolete compiler options:
- DATEPROC
- LIB
- NOLIB
- NOCMPR2
- NOOPTIMIZE or NOOPT
- NUMPROC, suboption MIG
- OPTIMIZE or OPT, suboptions FULL, STD, and none
- SIZE, suboption MAX
- TEST, suboptions HOOK, NOHOOK, SEPARATE, NOSEPARATE
- XMLPARSE
- YEARWINDOW
- Avoid language elements that are not supported in Enterprise COBOL
5.1
- Use this rule to flag any language element that is not supported
in IBM Enterprise COBOL for z/OS. The following elements are
flagged:
- Unsupported compiler options:
- EVENTS
- FDUMP
- FLAGSAA
- PFDSIGN
- RES
- TEST, suboptions ALL, BLOCK, PATH, STMT, NONE, SYM, NOSYM
- Data description entry, DATEFORMAT clause
- Unsupported intrinsic functions:
- DATEVAL
- UNDATE
- YEARWINDOW
- Unsupported label declaratives:
- GO TO MORE-LABELS
- USE...AFTER...LABEL PROCEDURE...
- Naming conventions:
- Use a program name that matches the source file
name
- Use this rule to flag any PROGRAM-ID division
whose program name is different from its source file name. The file
extension, if any, of the source file is excluded from the comparison.
- Performance:
- Avoid INITIALIZE statements. Use elementary MOVE statements or
VALUE clauses.
- Use this rule to flag INITIALIZE statements.
- Avoid OCCURS DEPENDING ON phrases
- Use this rule to flag OCCURS DEPENDING ON phrases.
- Avoid using subscripts to access a table. Use indexes.
- Use this rule to flag any data item that has the following characteristics:
- It is used as a subscript to access a table element
- It is not specified in an INDEXED BY phrase in
the OCCURS clause that defines the table.
This rule does not flag subscripts that are literals.
- EXEC SQL: Avoid SELECT *
- Use this rule to flag EXEC SQL statements that
contain a SELECT * statement
- EXEC SQL: Use an ORDER BY clause when declaring a cursor
- Use this rule to flag EXEC SQL statements that
declare a cursor without specifying an ORDER BY clause
in the contained SELECT statement.
- Specify 0 RECORDS for BLOCK CONTAINS clauses in file description
entries
- Use this rule to flag BLOCK CONTAINS clauses
that do not specify 0 RECORDS.
- Use an EVALUATE statement rather than a nested IF statement
- Use this rule to flag nested IF statements.
If the nesting is more than one level deep, then the rule flags only
the outermost nested IF statement.
Compare the
template Avoid nesting IF statements deeper than a specified
number of levels.
- Use an odd number of digits in a COMP-3 or PACKED-DECIMAL data
definition
- Use this rule to flag any data definition that is declared as
type COMP-3 or PACKED-DECIMAL and
does not contain an odd number of digits.
- Use binary subscripts
- Use this rule to flag any data item that has the following characteristics:
- It is used as a subscript to access a table element.
- It is not declared with a usage of COMP, COMPUTATIONAL,
or BINARY.
This rule does not flag subscripts that are literals.
- Program Structures:
- Avoid ACCEPT statements
- Use this rule to flag all ACCEPT statements.
Compare
the rule Avoid ACCEPT statements containing FROM CONSOLE
or FROM SYSIN.
- Avoid ACCEPT statements containing FROM CONSOLE or FROM SYSIN
- Use this rule to flag ACCEPT statements that
contain the phrase FROM CONSOLE or FROM SYSIN.
To
flag all ACCEPT statements without exception, use
the rule AVOID ACCEPT statements.
- Avoid ALTER statements
- Use this rule to flag ALTER statements.
- Avoid CALL statements with a literal program
name.
- Use this rule to flag CALL statements that specify
the program name as a literal.
- Avoid CANCEL statements
- Use this rule to flag CANCEL statements.
- Avoid COPY SUPPRESS statements
- Use this rule to flag COPY statements that contain
the SUPPRESS phrase.
- Avoid CORRESPONDING phrases
- Use this rule to flag ADD, SUBTRACT,
and MOVE statements that contain a CORRESPONDING phrase.
- Avoid DISPLAY statements containing UPON CONSOLE
- Use this rule to flag DISPLAY statements that
contain UPON CONSOLE.
- Avoid ENTRY statements
- Use this rule to flag ENTRY statements.
- Avoid EXIT PROGRAM statements
- Use this rule to flag EXIT PROGRAM statements.
- Avoid GO TO statements
- Use this rule to flag all GO TO statements.
Compare
the rule Avoid GO TO statements, except those that reference
an exit paragraph.
- Avoid GO TO statements, except those that reference an exit paragraph
- Use this rule to flag all GO TO statements, except
the statements that transfer control to an exit paragraph. An exit
paragraph is a paragraph that contains only an EXIT statement.
To
flag all GO TO statements without exception, use
the rule Avoid GO TO statements.
- Avoid IF without ELSE
- Use this rule to flag IF statements that do not
contain an ELSE clause.
- Avoid NEXT SENTENCE phrases
- Use this rule to flag all NEXT SENTENCE phrases.
Compare
the rule Use CONTINUE rather than NEXT SENTENCE inside
a scoped range.
- Avoid PERFORM, except PERFORM section
- Use this rule to flag all PERFORM statements,
except the statements that contain sections only.
Note: This rule
flags all PERFORM statements except PERFORM section-name or PERFORM section-name-1 THRU section-name-2.
Inline PERFORM statements and PERFORM statements
that reference paragraphs are flagged.
- Avoid RESERVE clauses in FILE-CONTROL paragraphs
- Use this rule to flag RESERVE clauses in FILE-CONTROL paragraphs.
- Avoid STOP RUN and STOP literal statements
- Use this rule to flag STOP RUN and STOP literal
statements.
- Avoid THRU phrases in PERFORM statements
- Use this rule to flag PERFORM statements that
include a THRU phrase.
- Avoid using level-88 entries in data descriptions
- Use this rule to flag data descriptions that use level-88 entries.
Each level-88 entry is flagged.
- Avoid using more than one EXIT statement per section
- Use this rule to flag sections that contain more than one EXIT statement.
- Avoid using SECTION in the procedure division
- Use this rule to flag any SECTION declarations
in the procedure division.
- Avoid XML PARSE statements
- Use this rule to flag XML PARSE statements.
- EXEC CICS: Check EIBRESP after NOHANDLE
- Use this rule to flag any EXEC CICS statement
that specifies the NOHANDLE option and is not followed
by an IF statement or an EVALUATE statement
that checks the value of EIBRESP.
The EXEC
CICS statement is flagged if it is not
followed
by either of the following statements:
- An IF or EVALUATE statement
that references EIBRESP
- A PERFORM statement that leads to a block of
code whose first statement is an IF or EVALUATE statement
that references EIBRESP
- EXEC CICS: Use DFHRESP to check the return value
- This rule applies to data items that are used as the RESP or RESP2 parameter
of an EXEC CICS command.
Use this rule to flag
a comparison between such a data item and anything other than the
return value of a
DFHRESP function call, in the following
contexts:
- In any relation condition
- In any WHEN unit of a SELECT statement
in which the data item is the selection subject
This rule examines all EXEC CICS blocks
for exception handling by RESP() or RESP2() and
the COBOL definition of the variable that is used is recorded. All relation conditions, such as conditions in IF, ELSE,
and EVALUATE WHEN statements, are searched for this
variable. If matches are found and if an equality check is made against
anything other than the DFHRESP macro, then the 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.
- EXEC CICS: Use the RESP option
- Use this rule to flag EXEC CICS commands
that do not include the RESP option.
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.
- EXEC SQL: Check the value of SQLCODE after an EXEC SQL statement
- Use this rule to flag any EXEC SQL statement
that is not followed by an IF statement or an EVALUATE statement
that checks the value of SQLCODE.
The EXEC
SQL statement is flagged if it is not
followed
by either of the following statements:
- An IF or EVALUATE statement
that references SQLCODE
- A PERFORM statement that leads to a block of
code whose first statement is an IF or EVALUATE statement
that references SQLCODE
- Use an EXIT paragraph in each section
- Use this rule to flag sections that do not contain
an exit paragraph. An exit paragraph is a paragraph that contains
only an EXIT statement.
- Use a WHEN OTHER phrase with an EVALUATE statement
- Use this rule to flag EVALUATE statements that
do not include a WHEN OTHER phrase.
- Use CONTINUE rather than NEXT SENTENCE inside a scoped range
- Use this rule to flag NEXT SENTENCE statements
that lie within the scope of any statement that has an explicit scope
terminator. For example, a NEXT SENTENCE statement
is flagged if it lies between an IF statement and
its corresponding END-IF phrase.
Statements that
have an explicit scope terminator include ADD, CALL, COMPUTE,
DELETE, DIVIDE, EVALUATE, IF, INVOKE, MULTIPLY, PERFORM, READ, RETURN,
REWRITE, SEARCH, START, STRING, SUBTRACT, UNSTRING, WRITE,
and XML.
To flag all NEXT SENTENCE statements
without exception, use the rule AVOID NEXT SENTENCE phrases.
- Use CURRENT-DATE rather than ACCEPT DATE or ACCEPT TIME
- Use this rule to flag ACCEPT DATE and ACCEPT
TIME statements.
- Use level numbers in the sequence 01, 05, 10, 15, ...
- Use this rule to flag data structure definitions that contain
level numbers with the following characteristics:
- They are not in ascending sequence.
- They do not have a value of either 1 or a multiple of 5.
- Use SEARCH ALL rather than SEARCH to search a table
- Use this rule to flag table searches that use SEARCH rather
than SEARCH ALL.
- Use THRU phrases in PERFORM statements
- Use this rule to flag PERFORM statements that
do not include a THRU phrase.