We are trying to analyse Cobol sources.
When there is a copymember with the content of a SELECT statement in a source, the analyzer generates a code-smell warning saying that the SELECT should be taken out of the copymember.
Although we generally consider it good practice to not put structural program elements in a copymember,
we think this warning is wrong:
A SELECT is NOT a structural part of the program.
There may be more than one of them in one program, and the same SELECT can appear in many different programs.
Below there is a sample program that shows how we have set up our file I/O, with a bunch of copymembers for each file.
Having a warning for every use of a SELECT copymember does not fit into that strategy.
Versions used:
Cobol: AcuCobol version 10.2.1, fixed format
SonarQube: Enterprise Edition Version 9.6.1 (build 59531)
Source code:
IDENTIFICATION DIVISION.
PROGRAM-ID. PP0039.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
COPY "C/SEL/ORDER".
DATA DIVISION.
FILE SECTION.
COPY "C/FD/ORDER".
WORKING-STORAGE SECTION.
01 FILE-STATUS PIC X(02).
PROCEDURE DIVISION.
MAIN SECTION.
GOBACK
.
SELECT copymember (“C/SEL/ORDER”):
SELECT ORDER-FILE ASSIGN TO RANDOM ORDER-FILE-NAME
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS ORDER-ID IN ORDER-REC
FILE STATUS IS FILE-STATUS.
REC copymember (“C/REC/ORDER”):
01 ORDER-REC.
03 ORDER-KEY.
05 ORDER-ID PIC 9(10).
03 ORDER-DATA.
05 ORDER-FIELD-ONE PIC X(05).
05 ORDER-FIELD-TWO PIC X(05).
FD copymember (“C/FD/ORDER” ):
FD ORDER-FILE.
COPY "C/REC/ORDER".
The generated code smell: