Built-in code review rules for COBOL
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
- Obsolete compiler options:
- 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...
- Unsupported compiler options:
- 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 theOCCURS
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 aSELECT *
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 anORDER BY
clause in the containedSELECT
statement. - Specify 0 RECORDS for BLOCK CONTAINS clauses in file description entries
- Use this rule to flag
BLOCK CONTAINS
clauses that do not specify0 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 nestedIF
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
orPACKED-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
, orBINARY
.
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 phraseFROM CONSOLE
orFROM 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 theSUPPRESS
phrase. - Avoid CORRESPONDING phrases
- Use this rule to flag
ADD
,SUBTRACT
, andMOVE
statements that contain aCORRESPONDING
phrase. - Avoid DISPLAY statements containing UPON CONSOLE
- Use this rule to flag
DISPLAY
statements that containUPON 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 anEXIT
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 anELSE
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 allPERFORM
statements exceptPERFORM section-name
orPERFORM section-name-1 THRU section-name-2
. InlinePERFORM
statements andPERFORM
statements that reference paragraphs are flagged. - Avoid RESERVE clauses in FILE-CONTROL paragraphs
- Use this rule to flag
RESERVE
clauses inFILE-CONTROL
paragraphs. - Avoid STOP RUN and STOP literal statements
- Use this rule to flag
STOP RUN
andSTOP
literal statements. - Avoid THRU phrases in PERFORM statements
- Use this rule to flag
PERFORM
statements that include aTHRU
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 theNOHANDLE
option and is not followed by anIF
statement or anEVALUATE
statement that checks the value of EIBRESP.TheEXEC CICS
statement is flagged if it is not followed by either of the following statements:- An
IF
orEVALUATE
statement that references EIBRESP - A
PERFORM
statement that leads to a block of code whose first statement is anIF
orEVALUATE
statement that references EIBRESP
- An
- 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 aDFHRESP
function call, in the following contexts:- In any relation condition
- In any
WHEN
unit of aSELECT
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 inIF
,ELSE
, andEVALUATE WHEN
statements, are searched for this variable. If matches are found and if an equality check is made against anything other than theDFHRESP
macro, then the relation condition is recorded as a rule violation. In addition, anyEVALUATE
statement that uses the response variable as itsWHAT
condition then has itsWHEN
clauses examined. If they contain anything other than references to theDFHRESP
macro, theWHEN
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 anIF
statement or anEVALUATE
statement that checks the value of SQLCODE.TheEXEC SQL
statement is flagged if it is not followed by either of the following statements:- An
IF
orEVALUATE
statement that references SQLCODE - A
PERFORM
statement that leads to a block of code whose first statement is anIF
orEVALUATE
statement that references SQLCODE
- An
- 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 aWHEN 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, aNEXT SENTENCE
statement is flagged if it lies between anIF
statement and its correspondingEND-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
, andXML
.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
andACCEPT 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 thanSEARCH ALL
. - Use THRU phrases in PERFORM statements
- Use this rule to flag
PERFORM
statements that do not include aTHRU
phrase.