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-IDdivision 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
INITIALIZEstatements. - Avoid OCCURS DEPENDING ON phrases
- Use this rule to flag
OCCURS DEPENDING ONphrases. - 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 BYphrase in theOCCURSclause that defines the table.
This rule does not flag subscripts that are literals.
- EXEC SQL: Avoid SELECT *
- Use this rule to flag
EXEC SQLstatements that contain aSELECT *statement - EXEC SQL: Use an ORDER BY clause when declaring a cursor
- Use this rule to flag
EXEC SQLstatements that declare a cursor without specifying anORDER BYclause in the containedSELECTstatement. - Specify 0 RECORDS for BLOCK CONTAINS clauses in file description entries
- Use this rule to flag
BLOCK CONTAINSclauses that do not specify0 RECORDS. - Use an EVALUATE statement rather than a nested IF statement
- Use this rule to flag nested
IFstatements. If the nesting is more than one level deep, then the rule flags only the outermost nestedIFstatement.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-3orPACKED-DECIMALand 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
ACCEPTstatements.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
ACCEPTstatements that contain the phraseFROM CONSOLEorFROM SYSIN.To flag all
ACCEPTstatements without exception, use the rule AVOID ACCEPT statements. - Avoid ALTER statements
- Use this rule to flag
ALTERstatements. - Avoid CALL statements with a literal program name.
- Use this rule to flag
CALLstatements that specify the program name as a literal. - Avoid CANCEL statements
- Use this rule to flag
CANCELstatements. - Avoid COPY SUPPRESS statements
- Use this rule to flag
COPYstatements that contain theSUPPRESSphrase. - Avoid CORRESPONDING phrases
- Use this rule to flag
ADD,SUBTRACT, andMOVEstatements that contain aCORRESPONDINGphrase. - Avoid DISPLAY statements containing UPON CONSOLE
- Use this rule to flag
DISPLAYstatements that containUPON CONSOLE. - Avoid ENTRY statements
- Use this rule to flag
ENTRYstatements. - Avoid EXIT PROGRAM statements
- Use this rule to flag
EXIT PROGRAMstatements. - Avoid GO TO statements
- Use this rule to flag all
GO TOstatements.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 TOstatements, except the statements that transfer control to an exit paragraph. An exit paragraph is a paragraph that contains only anEXITstatement.To flag all
GO TOstatements without exception, use the rule Avoid GO TO statements. - Avoid IF without ELSE
- Use this rule to flag
IFstatements that do not contain anELSEclause. - Avoid NEXT SENTENCE phrases
- Use this rule to flag all
NEXT SENTENCEphrases.Compare the rule Use CONTINUE rather than NEXT SENTENCE inside a scoped range.
- Avoid PERFORM, except PERFORM section
- Use this rule to flag all
PERFORMstatements, except the statements that contain sections only.Note: This rule flags allPERFORMstatements exceptPERFORM section-nameorPERFORM section-name-1 THRU section-name-2. InlinePERFORMstatements andPERFORMstatements that reference paragraphs are flagged. - Avoid RESERVE clauses in FILE-CONTROL paragraphs
- Use this rule to flag
RESERVEclauses inFILE-CONTROLparagraphs. - Avoid STOP RUN and STOP literal statements
- Use this rule to flag
STOP RUNandSTOPliteral statements. - Avoid THRU phrases in PERFORM statements
- Use this rule to flag
PERFORMstatements that include aTHRUphrase. - 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
EXITstatement. - Avoid using SECTION in the procedure division
- Use this rule to flag any
SECTIONdeclarations 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 CICSstatement that specifies theNOHANDLEoption and is not followed by anIFstatement or anEVALUATEstatement that checks the value of EIBRESP.TheEXEC CICSstatement is flagged if it is not followed by either of the following statements:- An
IForEVALUATEstatement that references EIBRESP - A
PERFORMstatement that leads to a block of code whose first statement is anIForEVALUATEstatement 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 CICScommand.Use this rule to flag a comparison between such a data item and anything other than the return value of aDFHRESPfunction call, in the following contexts:- In any relation condition
- In any
WHENunit of aSELECTstatement in which the data item is the selection subject
This rule examines all
EXEC CICSblocks 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 WHENstatements, are searched for this variable. If matches are found and if an equality check is made against anything other than theDFHRESPmacro, then the relation condition is recorded as a rule violation. In addition, anyEVALUATEstatement that uses the response variable as itsWHATcondition then has itsWHENclauses examined. If they contain anything other than references to theDFHRESPmacro, theWHENclauses are flagged as rule violations. EXEC CICS: Use the RESP option- Use this rule to flag
EXEC CICScommands that do not include the RESP option.This rule examines all
EXEC CICSblocks 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 SQLstatement that is not followed by anIFstatement or anEVALUATEstatement that checks the value of SQLCODE.TheEXEC SQLstatement is flagged if it is not followed by either of the following statements:- An
IForEVALUATEstatement that references SQLCODE - A
PERFORMstatement that leads to a block of code whose first statement is anIForEVALUATEstatement 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
EXITstatement. - Use a WHEN OTHER phrase with an EVALUATE statement
- Use this rule to flag
EVALUATEstatements that do not include aWHEN OTHERphrase. - Use CONTINUE rather than NEXT SENTENCE inside a scoped range
- Use this rule to flag
NEXT SENTENCEstatements that lie within the scope of any statement that has an explicit scope terminator. For example, aNEXT SENTENCEstatement is flagged if it lies between anIFstatement and its correspondingEND-IFphrase.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 SENTENCEstatements 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 DATEandACCEPT TIMEstatements. - 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
SEARCHrather thanSEARCH ALL. - Use THRU phrases in PERFORM statements
- Use this rule to flag
PERFORMstatements that do not include aTHRUphrase.