Use the COBOL custom rule templates to create custom rules
for COBOL code reviews.
- An inline PERFORM statement cannot exceed the specified line number
limit
- Use this template to flag PERFORM statements
that contain more than a specified number of lines. Enter the number
of lines as a parameter to this template.
The template counts the
nonblank lines that follow PERFORM statements and
precede END PERFORM statements.
- Avoid calling the specified routine
- Use this template to flag CALL statements that
call a specified routine. Enter the name of the routine as a parameter
to this template.
This template is enforced only when the CALL statement
uses the literal name of the routine.
- Avoid including the specified copybook
- Use this template to flag COPY statements that
refer to a specified copybook. Enter the name of the copybook as a
parameter to this template.
- Avoid nesting IF statements deeper than the specified number of
levels
- Use this template to flag IF statements that
are nested deeper than a specified number of levels. Enter the number
of levels of nesting as a parameter to this template.
If the nesting
is more than one level deeper than the specified maximum, then the
template flags only the outermost nested IF statement.
Compare
the rule Use EVALUATE statement rather than nested IF statement.
- Avoid static calls except for the specified program name
- Use this template to flag CALL statements that
have the following characteristics:
- A Java™ static method or
a COBOL factory method is called.
- The method name does not match the specified program name. Enter
the program name as a parameter to the template.
- Avoid using the selected compiler directives
- Use this template to flag the selected compiler directives. Select
the compiler directives to flag: BASIS, CBL (PROCESS), COPY,
EJECT, REPLACE, SERVICE LABEL, SERVICE RELOAD, SKIP, and TITLE.
- EXEC SQL: Use a WHERE clause in selected statements
- Use this template to flag any EXEC SQL statement
that contains a SELECT, DELETE,
or UPDATE statement that does not include a WHERE clause.
Select the types of statement to flag: SELECT, DELETE,
and UPDATE.
- Follow the specified naming convention for COBOL file names
- Use this template to flag program file names that do not match
a specified regular expression. Enter the regular expression as a
parameter to this template. The comparison ignores the file extension
of the program name, if any.
Examples:
- To flag file names that do not begin with "prefix" use: ^prefix.*$
- To flag file names that do not begin with "prefix" and end with
an integer use: ^prefix.[0-9]$
The regular expression must have one match only for its
target file names, starting with the first character of the file name
and ending with the last. For example, to match files that begin with
AARV,
such as
AARVLIST.cbl,
AARVUPDT.cbl,
or
AARVEDIT.cbl.
- Correct example: ^aa.*$
- Incorrect example: a
The first example is correct because it matches the names AARVLIST,
AARVUPDT, and AARVEDIT only one time, and it matches them from the
first character to the last. The second example is incorrect because
it matches the names AARVLIST, AARVUPDT, and AARVEDIT more than one
time (at index 0 and at index 1) and it does not match them from the
first character to the last.
- Procedure division statements cannot exceed the specified line
number limit
- Use this template to flag PROCEDURE divisions
that contain more than a specified number of lines. Enter the number
of lines as a parameter to this template.
During processing, the
template counts all the nonblank lines in the PROCEDURE division
after the procedure division header.
- Use a scope terminator phrase with the specified COBOL statement
type
- Use this template to flag the specified type of COBOL statement
if it does not contain a scope terminator phrase. Select the type
of COBOL statement as a parameter for the template.
The statement
types are CALL, IF, EVALUATE, READ, SEARCH, or STRING.
- Use comments to describe all paragraphs
- Use this template to flag paragraph declarations that are not
immediately preceded or followed by a comment. Select whether the
comment precedes or follows the paragraph declaration.
A paragraph
declaration is a paragraph name or paragraph header that begins a
paragraph.
- Use comments to describe all sections
- Use this template to flag section headers that are not immediately
preceded or followed by a comment. Select whether the comment precedes
or follows the section header.
- Use the specified prefix with condition names
- Use this template to flag data descriptions that do not begin
with the specified prefix. Enter the prefix as a parameter to the
template.