Error in the reporting of unused files

We are scanning AcuCobol sources.

We see an error in the reporting of unused files:
The error occurs under the following conditions:

  • The ‘SELECT’ of a file is in a separate copymember AND
  • this copymember is added into a program AND
  • The file is NOT used in the program.

When these conditions are met, the file is reported as being unused.
In itself that is correct, however the issue is reported on the copy-member, not on the source in which the copy-member was added.
If we create a copy-member with a SELECT, and we don’t insert it in any program, we get no issue reported on it.

A small reproducer program:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. PP0047.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
          COPY "C/SEL/PP0047".
       DATA DIVISION.
       FILE SECTION.
          COPY "C/FD/PP0047".
       WORKING-STORAGE SECTION.
       01 FILE-STATUS            PIC X(02).
       PROCEDURE DIVISION.
       MAIN SECTION.
           GOBACK
           .

The copy-member that contains the SELECT:

       SELECT PP0047-FILE ASSIGN TO RANDOM PP0047-FILE-NAME
              ORGANIZATION IS INDEXED
              ACCESS MODE IS DYNAMIC
              RECORD KEY IS PP0047-ID IN PP0047-REC
              FILE STATUS IS FILE-STATUS.

And the copy-member that contains the FD:

       FD PP0047-FILE.
       01 PP0047-REC.
          03 PP0047-ID   PIC 9(10).
          03 PP0047-DATA PIC X(90).

Versions used:
Cobol: Acucobol 10.2.1
SonarQube: * 10.4 (build 87286)
SonarScanner 5.0.1.3006

Please fix this error in the reporting.

Hi Jos,

Sorry for replying so late.

If I understand correctly what you describe, I believe that our rule should simply not report any issue on a SELECT that is declared inside a copybook. Your program may have to include the copybook because of other declarations appearing in the copybook without needing all of them.
Ignoring such declarations would be consistent with what we already do when trying to detect unused data items.

Do you agree?

Thanks for your valuable feedback.

Hi Pierre-Yves,

The point is not so much that an issue is reported.
Because (if you look at my reproducer program PP0047) that is correct: The file is not used.
However, SQ report this issue on the copybook; not on the program in which the copybook is used.
So if you have a SELECT in a copybook that is used in 100 programs, and in one program the copybook is included but not used, you get an issue reported on the copybook.
And then you need to check 101 programs to find the one where it is not used.

Hopefully it is possible for you to report this issue on the program in which the copybook is included.

image001.gif

image002.gif

Hi Jos,

There’s definitely a problem to fix.
We will do what I described in my previous message: SONARCOBOL-1702
We will also try to think of a new rule to detect when a program (not a copybook) contains a COPY statement to include a copybook that only contains definitions that are not used in the program.

Thank you.