How to calculate and measure the ring complexity of ABAP and Java code cyclomatic complexity

Source: Internet
Author: User

The loop complexity of the code (cyclomatic complexity, where it translates into cyclomatic complexity) is a measure of code complexity, presented by Thomas J. McCabe, Sr., in 1976.

In the concept of software testing, cyclomatic complexity is used to measure the complexity of a module to determine the structure, the number of which is represented by the number of independent linear path, that is, reasonable prevention of errors required to test the minimum number of paths. Large Cyclomatic complexity indicates that the program code may be of low quality and difficult to test and maintain.

Calculation formula

Ring complexity = E? N + 2

E = number of edges in the program control flow graph

N = number of midpoint in the program control flow graph

Look at a concrete example. The ring complexity of the ABAP code below is calculated as 3 according to the formula.

DATA: lv_value TYPE i VALUE 1. IF lv_value = 1.     WRITE: / ‘always happend‘. ELSEIF lv_value = 2.     WRITE: / ‘not possible‘. ELSE.     WRITE: / ‘even not possible‘. ENDIF.

Let's start by drawing out the program flow of the code:

Use the Code Inspector tool in ABAP to measure the loop complexity of the codes:

Refer to my ABAP blog for specific steps:

    • A Small tip To get all transparent tables used in ABAP code

    • Useful tips regarding ABAP code inspector that is not know

Java can measure the ring complexity with a tool called Sourcemonitor:

Refer to my blog for details using Sourcemonitor to monitor your Java code complexity


To get more original Jerry's technical articles, please follow the public number "Wang Zixi" or scan the QR code below:

How to calculate and measure the ring complexity of ABAP and Java code cyclomatic complexity

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.