COBOL

COBOL Metrics

Arithmetic Operators

  • Mnemonic AROP

  • Description Number of arithmetic operators

Blank Lines

  • Mnemonic BLAN

  • Description Number of blank lines of code in the source file(s).

CALL Statements

  • Mnemonic CALL

  • Description Number of CALL statements

Cyclomatic Complexity

  • Mnemonic CCN

  • Description Number of linearly independent paths in the function control graph.

Control Flow Token

  • Mnemonic CFT

  • Description Number of tokens in the control flow of functions

Call Graph Depth

  • Mnemonic CGDM

  • Description Maximum depth of the call graph.

Comment Lines

  • Mnemonic CLOC

  • Description Number of lines of comments in the source file(s).

Comment lines with code

  • Mnemonic CLOC_CODE

  • Description Number of lines of comments in the source file(s) whose first word is a keyword.

Comment lines without alphabetic characters

  • Mnemonic CLOC_NULL

  • Description Number of lines of comments in the source file(s) without alphabetic character.

Real comment lines with alphabetic characters

  • Mnemonic CLOC_REAL

  • Description Number of real lines of comments in the source file(s) with alphabetic characters.

Conditions

  • Mnemonic COND

  • Description Number of conditions

Commented Statements

  • Mnemonic CSTAT

  • Description Number of Commented Statements.

Minimum Number of Cycles

  • Mnemonic CYCL

  • Description Minimum number of call graph cycles in which the function is involved (including recursivity).

Debug lines

  • Mnemonic DBUG

  • Description Number of lines of debug in the source file(s).

DISPLAY statements

  • Mnemonic DISPLAY

  • Description Number of DISPLAY statements

Distinct Operands

  • Mnemonic DOPD

  • Description Number of distinct operands: variables and constants ([Halstead,76]: n2)

Distinct Operands in Data Div.

  • Mnemonic DOPD_DD

  • Description Number of distinct operands in Data Division: variables and constants ([Halstead,76]: n2)

Distinct Operands in Procedure Div.

  • Mnemonic DOPD_PD

  • Description Number of distinct operands in Procedure Division: variables and constants ([Halstead,76]: n2)

Distinct Operators

  • Mnemonic DOPT

  • Description Number of distinct operators: language keywords ([Halstead,76]: n1)

Distinct Operators in Data Div.

  • Mnemonic DOPT_DD

  • Description Number of distinct operators in Data Division: language keywords ([Halstead,76]: n1)

Distinct Operators in Procedure Div.

  • Mnemonic DOPT_PD

  • Description Number of distinct operators in Procedure Division: language keywords ([Halstead,76]: n1)

Else Statements

  • Mnemonic ELSE

  • Description Number of 'else' statements

EVALUATE Statements

  • Mnemonic EVAL

  • Description Number of EVALUATE statements

Call to exit

  • Mnemonic EXIT

  • Description Number of calls to the exit function

File Declarations

  • Mnemonic FD

  • Description Number of file declarations

Files Used

  • Mnemonic FDUS

  • Description Number of references to files

Goto Statements

  • Mnemonic GOTO

  • Description Number of 'goto' statements

Cloned Code

  • Mnemonic ICC

  • Description Duplicated code in this artefact

Cloned Control Flow Tokens

  • Mnemonic ICFTC

  • Description Number of duplicated tokens in control flow of functions

Is IDMS active

  • Mnemonic IDMS_ACTIVE

  • Description Is IDMS active in program

IDMS instructions called

  • Mnemonic IDMS_CALLBD

  • Description Number of IDMS instructions called

IDMS records called

  • Mnemonic IDMS_CALLREC

  • Description Number of IDMS records called

IDMS calls for modification

  • Mnemonic IDMS_MOD

  • Description Number of calls for modification

IDMS calls for reading/searching

  • Mnemonic IDMS_READ

  • Description Number of calls for reading/searching

IDMS subschema definition

  • Mnemonic IDMS_SSCH

  • Description Number of IDMS subschema definition

If Statements

  • Mnemonic IF

  • Description Number of 'if' statements

Line Count

  • Mnemonic LC

  • Description Number of lines.

Maximum Nested Structures

  • Mnemonic NEST

  • Description Maximum number of nested structures

Number of paragraphs

  • Mnemonic PARA

  • Description Number of paragraphs.

PERFORM Statements

  • Mnemonic PERF

  • Description Number of PERFORM statements

Repeated Code Blocks

  • Mnemonic RS

  • Description Duplicated blocks in the function

Data Declarations

  • Mnemonic SD

  • Description Number of data declarations

Data Used

  • Mnemonic SDUS

  • Description Number of used data

Number of Sections

  • Mnemonic SECT

  • Description Number of sections.

Source Lines Of Code

  • Mnemonic SLOC

  • Description Number of lines of source code in the source file(s).

Executable Statements

  • Mnemonic STAT

  • Description Total number of executable statements.

STOP Statements

  • Mnemonic STOP

  • Description Number of STOP statements

TIMES Clauses

  • Mnemonic TIME

  • Description Number of TIMES clauses in PERFORM statements

Operand Occurrences

  • Mnemonic TOPD

  • Description Number of occurrences of operands: variables and constants ([Halstead,76]: N2)

Operand Occurrences in Data Div.

  • Mnemonic TOPD_DD

  • Description Number of occurrences of operands in Data Division: variables and constants ([Halstead,76]: N2)

Operand Occurrences in Procedure Div.

  • Mnemonic TOPD_PD

  • Description Number of occurrences of operands in Procedure Division: variables and constants ([Halstead,76]: N2)

Operator Occurrences

  • Mnemonic TOPT

  • Description Number of occurrences of operators: language keywords ([Halstead,76]: N1)

Operator Occurrences in Data Div.

  • Mnemonic TOPT_DD

  • Description Number of occurrences of operators in Data Division: language keywords ([Halstead,76]: N1)

Operator Occurrences in Procedure Div.

  • Mnemonic TOPT_PD

  • Description Number of occurrences of operators in Procedure Division: language keywords ([Halstead,76]: N1)

Lines Added

  • Mnemonic LADD

  • Description Number of lines added since the previous version.

Lines Modified

  • Mnemonic LMOD

  • Description Number of lines modified since the previous version.

Lines Removed

  • Mnemonic LREM

  • Description Number of lines removed since the previous version.

UNTIL Clauses

  • Mnemonic UNTL

  • Description Number of UNTIL clauses in PERFORM statements

VARYING Clauses

  • Mnemonic VARY

  • Description Number of VARYING clauses in PERFORM statements

WHEN Clauses

  • Mnemonic WHEN

  • Description Number of WHEN and WHENOTHER clauses in EVALUATE Statements

COBOL Ruleset

BLOCK Clause

  • Mnemonic BLOCKSIZE

  • Description In the FILE-DESCRIPTION section, each file description shall always use the BLOCK CONTAINS 0 RECORDS clause. The system will assign the BLOCK-SIZE automatically when allocating the file.

Column 7 for * and D Only

  • Mnemonic COLUMN7

  • Description Only * and D shall be used in column 7.

Comment Division

  • Mnemonic COMMENT_DIVISION

  • Description A comment is recommended before each division.

Comment FD

  • Mnemonic COMMENT_FD

  • Description A comment is recommended before each file description.

Comment First Level

  • Mnemonic COMMENT_FIRST_LEVEL

  • Description A comment is recommended before each first level of IF or PERFORM.

Comment Variable 01 and 77

  • Mnemonic COMMENT_FIRST_VARIABLE

  • Description A comment is recommended before each variable 01 and 77.

Empty lines around DIVISION

  • Mnemonic CPRS_DIVISION

  • Description An empty line shall precede and follow a DIVISION.

Empty line after EXIT

  • Mnemonic CPRS_EXIT

  • Description An empty line shall follow an EXIT statement.

Bad statement indentation

  • Mnemonic CPRS_INDENT

  • Description The nested statements shall be indented.

Bad indentation of scope terminator

  • Mnemonic CPRS_SCOPE_TERMINATOR

  • Description Scope terminators must be on the same column as the beginning of the block to facilitate program readability.

Empty line after SECTION

  • Mnemonic CPRS_SECTION

  • Description An empty line shall follow a SECTION.

Variable declaration format

  • Mnemonic DCLWS

  • Description A variable shall be declared in the WORKING STORAGE using the format ^W

Paragraphs having exact same name

  • Mnemonic R_DUPPARA

  • Description Paragraphs having exact same name in the same PROGRAM-ID is forbidden.

Missing END-EVALUATE

  • Mnemonic EVALWITHENDEVAL

  • Description An EVALUATE statement shall be closed by END-EVALUATE

Close file once

  • Mnemonic FILECLOSEONCE

  • Description A file shall be closed only once

Close open file

  • Mnemonic FILEOPENCLOSE

  • Description A file shall be opened and closed in the same program

Open file once

  • Mnemonic FILEOPENONCE

  • Description A file shall be opened only once

Use FILE STATUS

  • Mnemonic FILESTATUS

  • Description FILE STATUS shall be used to manage I/O errors.

Single GOBACK

  • Mnemonic GOBACK

  • Description Only a single GOBACK shall be used in a subprgram.

IDMS FIND CURRENT

  • Mnemonic IDMSFINDCURRENT

  • Description IDMS FIND CURRENT is forbidden

IDMS One modify by PERFORM

  • Mnemonic IDMSONEMODFORPERF

  • Description Each IDMS modify statement (MODIFY/ERASE/STORE) should be in a specific perform

IDMS One same call

  • Mnemonic IDMSONESAMECALL

  • Description Avoid duplicated IDMS call.

IDMS Ready Protected Update

  • Mnemonic IDMSREADYPRTUPD

  • Description Each IDMS Ready Update statement should be defined in PROTECTED mode.

IDMS Return Code

  • Mnemonic IDMSRETURNCODE

  • Description After each IDMS statement, return code should be checked.

Missing END-IF

  • Mnemonic IFWITHENDIF

  • Description An IF statement shall be closed by an END-IF

Avoid using inline PERFORM with too many lines of code

  • Mnemonic INLINE_PERFORM_SIZE

  • Description Avoid Cobol programs containing PERFORM - END-PERFORM loops with more than 80 lines.

Standard Label

  • Mnemonic LABELSTD

  • Description In the FILE-DESCRIPTION section, each file description shall always use the LABEL RECORD STANDARD clause. Only the standard labels are checked by the system.

Missing END-ADD

  • Mnemonic MISSING_END_ADD

  • Description An ADD statement shall be closed by an END-ADD.

Missing END-CALL

  • Mnemonic MISSING_END_CALL

  • Description An CALL statement shall be closed by an END-CALL.

Missing END-COMPUTE

  • Mnemonic MISSING_END_COMPUTE

  • Description An COMPUTE statement shall be closed by an END-COMPUTE.

Missing END-DELETE

  • Mnemonic MISSING_END_DELETE

  • Description An DELETE statement shall be closed by an END-DELETE.

Missing END-DIVIDE

  • Mnemonic MISSING_END_DIVIDE

  • Description An DIVIDE statement shall be closed by an END-DIVIDE.

Missing END-MULTIPLY

  • Mnemonic MISSING_END_MULTIPLY

  • Description An MULTIPLY statement shall be closed by an END-MULTIPLY.

Missing END-READ

  • Mnemonic MISSING_END_READ

  • Description An READ statement shall be closed by an END-READ.

Missing END-RETURN

  • Mnemonic MISSING_END_RETURN

  • Description An RETURN statement shall be closed by an END-RETURN.

Missing END-REWRITE

  • Mnemonic MISSING_END_REWRITE

  • Description An REWRITE statement shall be closed by an END-REWRITE.

Missing END-SEARCH

  • Mnemonic MISSING_END_SEARCH

  • Description An SEARCH statement shall be closed by an END-SEARCH.

Missing END-START

  • Mnemonic MISSING_END_START

  • Description An START statement shall be closed by an END-START.

Missing END-STRING

  • Mnemonic MISSING_END_STRING

  • Description An STRING statement shall be closed by an END-STRING.

Missing END-SUBTRACT

  • Mnemonic MISSING_END_SUBTRACT

  • Description An SUBTRACT statement shall be closed by an END-SUBTRACT.

Missing END-UNSTRING

  • Mnemonic MISSING_END_UNSTRING

  • Description An UNSTRING statement shall be closed by an END-UNSTRING.

Missing END-WRITE

  • Mnemonic MISSING_END_WRITE

  • Description An WRITE statement shall be closed by an END-WRITE.

Missing FILLER

  • Mnemonic MISSING_FILLER

  • Description Even the 'FILLER' word is optional since Cobol85, it is recommanded to write it.

No more than 3 nested IF

  • Mnemonic NESTEDIF

  • Description There shall be no more than 3 nexted IF statements

Nested Program

  • Mnemonic NESTED_PROGRAM

  • Description Nested program is not recommanded

ALTER shall not be used

  • Mnemonic NOALTER

  • Description The ALTER statement shall not be used. Labels are decided only at execution time.

Factorizable Classes

  • Mnemonic CAC_CL

  • Description Consider classes refactorization

Factorizable Files

  • Mnemonic CAC_FI

  • Description Consider files refactorization

Factorizable Functions

  • Mnemonic CAC_FN

  • Description Consider functions refactorization

Factorizable Packages

  • Mnemonic CAC_PKG

  • Description Consider packages refactorization

Cloned Classes

  • Mnemonic CC_CL

  • Description There shall be no duplicated classes

Cloned Files

  • Mnemonic CC_FI

  • Description There shall be no duplicated files

Cloned Functions

  • Mnemonic CC_FN

  • Description There shall be no duplicated functions

Cloned Algorithmic

  • Mnemonic CFTC_FN

  • Description There shall be no algorithmic cloning

No Conditional GOTO

  • Mnemonic NOCONDGOTO

  • Description Conditional GO TO shall not be used. Use EVALUATE instead.

No MOVE CORRESPONDING

  • Mnemonic NOCORRESPONDING

  • Description MOVE CORRESPONDING shall not be used.

COMPUTE instead of ADD

  • Mnemonic NOCPXADD

  • Description COMPUTE shall be used to add more than 2 data instead of ADD.

COMPUTE instead of SUBTRACT

  • Mnemonic NOCPXSUBTRACT

  • Description COMPUTE shall be used to add more than 2 data instead of SUBTRACT.

No DEBUG MODE

  • Mnemonic NODEBUG

  • Description DEBUGGING-MODE shall not be used

COMPUTE instead of DIVIDE

  • Mnemonic NODIVIDE

  • Description COMPUTE shall be used instead of DIVIDE.

FIXME shall not be commited in sources code

  • Mnemonic R_NOFIXME

  • Description FIXME shall not be commited in sources code as it brings confusion regarding code reliability.

No INITIALIZE

  • Mnemonic NOINITIALIZE

  • Description INITIALIZE shall not be used. Use MOVE to initialize variable.

COMPUTE instead of MULTIPLY

  • Mnemonic NOMULTIPLY

  • Description COMPUTE shall be used instead of MULTIPLY.

No procedural COPY

  • Mnemonic NOPROCCOPY

  • Description Procedural COPY clauses shall not be used. Use subprograms instead.

No RENAMES

  • Mnemonic NORENAMES

  • Description The RENAMES clause shall not be used.

Avoid Duplicated Blocks in Function

  • Mnemonic RS_FN

  • Description There shall be no duplicated parts in functions

TODO shall not be commited in sources code

  • Mnemonic R_NOTODO

  • Description TODO shall not be commited in sources code as it brings confusion regarding code reliability.

No Variables S9(9)

  • Mnemonic NOVARS9

  • Description The variables shall not be declared in S9(9) COMP. It implies a conversion

Avoid GOTO jumps out of PERFORM range

  • Mnemonic NO_GOTO_OUT_OF_PERFORM_RANGE

  • Description Avoid Cobol Programs containing sections or paragraphs that are called by PERFORM statements and that contain a GO TO statement to another section or paragraph that is not in the scope of the initial PERFORM.

Avoid OPEN/CLOSE inside loops

  • Mnemonic NO_OPEN_CLOSE_INSIDE_LOOP

  • Description Avoid Cobol programs using OPEN or CLOSE in loops. Following loops are taken into account: - PERFORM TIMES / UNTIL / VARYING

Avoid accessing data by using the position and length

  • Mnemonic NO_REFERENCE_ACCESS

  • Description Avoid Cobol programs accessing part of data by using a position and a length.

Use COMP for OCCURS

  • Mnemonic OCCURSCOMP

  • Description For the OCCURS DEPENDING ON clause, the corresponding item shall be declared using COMP or BINARY.

Avoid mixing paragraphs and sections

  • Mnemonic PARA_OR_SECT_ONLY

  • Description A program should not mix paragraphs and sections.

Perform with no THRU

  • Mnemonic PERFORMWITHTHRU

  • Description The call of a paragraph shall be made in the use of PERFORM paragraphName THRU paragraphNameExit.

Bad paragraph position used in PERFORM

  • Mnemonic POSITION_OF_PERFORM_RANGE

  • Description On a PERFORM range: P1 THRU P2, P1 must be declared before P2.

READ-WRITE Instruction

  • Mnemonic READWRITE

  • Description READ A INTO B or WRITE A FROM B forms shall be used for reading/writing a file.

Avoid using READ statement without AT END clause

  • Mnemonic READ_AT_END

  • Description Avoid Cobol programs using READ statements without the AT END clause.

Relaxed violation

  • Mnemonic RELAX

  • Description A rule violation is relaxed and justified.

Statement shall be in uppercase

  • Mnemonic UPPERCASE

  • Description A COBOL statement shall be written in uppercase to keep the program readable.

Use SYNCHRONIZED

  • Mnemonic USESYNCH

  • Description SYNCHRONIZED shall be used for COMP, COMP-1, COMP-2, POINTER and INDEX variables.

Homonymous variable shall not be used

  • Mnemonic VARNAME

  • Description There shall be no homonymous variables.

Use WHEN OTHER

  • Mnemonic WHENOTHER

  • Description EVALUATE shall end by a WHEN OTHER clause.