Analyzing ABAP Complexity

The complexity value of an object’s ABAP source code returned by the Analyze ABAP Quality action is based on the notion of cyclomatic complexity, developed by Thomas J. McCabe, Sr. In a directed graph that represents the control flow of a program, the program’s cyclomatic complexity (M) is calculated as:

M = E - N + P

  • E is the number of edges in the graph. In this definition, the entry and exit points for the graph are assumed to be connected.
  • N is the number of nodes in the graph.
  • P is the number of connected components. For object-oriented programs, each method of a class is regarded as a separate connected component.

For ABAP source code:

  • IF and ELSEIF statements are counted as decision points. However, any AND, OR or other logical operands within these statements are not counted.
  • Within a CASE statement, all WHEN statements are counted as decision points.
  • LOOP, DO, WHILE and CHECK statements are counted as decision points.
  • FORM, METHOD and FUNCTION statements are counted as connected components in the formula for cyclomatic complexity. These are separate sections of code with distinct entry and exit points.
  • Within SQL statements, WHERE clauses are counted as decision points in SELECT, MODIFY, UPDATE and DELETE statements. However, these statements are not counted if they do not have a WHERE clause.
  • KEY clauses in READ statements are counted as decision points. However READ statements are not counted if they do not have a KEY clause.

Keywords and Count Words

If the Complexity category is selected, the Analyze ABAP Quality action uses a set of keywords and count words to determine the complexity of each object’s ABAP source code. Keywords define the types of statement that will be considered in determining the source code’s complexity value. The following keywords are specified in the default quality rules file used by the Analyze ABAP Quality action:

CATCH

DELETE

DO

ELSEIF

FORM

FUNCTION

IF

INCLUDE

LOOP

METHOD

MODIFY

READ

SELECT

UPDATE

WHEN

WHILE

Count words define the tokens that will be used in determining the complexity of each object’s ABAP source code. The following count words are specified in the default quality rules file used by the Analyze ABAP Quality action:

CATCH

CHECK

DO

ELSEIF

FORM

FUNCTION

IF

KEY

LOOP

METHOD

WHEN

WHERE

WHILE

 

Complexity Rankings

If the Complexity category is selected, the Analyze ABAP Quality action assigns a ranking to each object based upon its complexity value. The following rankings are specified in the default quality rules file used by the Analyze ABAP Quality action. These values may be overridden using the Analyze ABAP Quality action’s Complexity Rank Overrides property.

Complexity Value Ranking
0 to 10 Good
11 to 15 Bad
16 or above Ugly

Analyze ABAP Quality Actions