CRITICAL
Rule Definition
The PERFORM statement allows calling paragraphs with several call levels. However, Cobol is not a recursive language and can not manage paragraph recursive calls correctly. When a paragraph is called via a PERFORM statement, then the calling statement is saved into a stack and the control flow jumps to the beginning of the called paragraph. At the end of this paragraph, then the control flow returns to the calling statement. A recursive call can alter the calling statement stack and the control flow may be unpredictable.
Furthermore, all data are global to the program. Then, if a paragraph called at level 'n' modifies a data, then this data is modified for all the call levels.
For all these reasons, it is better to replace paragraph recursive calls by loops.
Remediation
Try to remove recursive algorithms in the program and replace them by iterative algorithms.
Violation Code Sample
PROCEDURE DIVISION.
PROCESS.
MOVE 0 TO A.
PERFORM PROC-01.
GOBACK.
PROC-01.
ADD 1 TO A.
* If condition is true then there is a recursive call
IF A < 13 THEN
PERFORM PROC-01
END-IF
Fixed Code Sample
PROCEDURE DIVISION.
PROCESS.
MOVE 0 TO A.
PERFORM PROC-01 UNTIL A = 13.
GOBACK.
PROC-01.
ADD 1 TO A.
Reference
IBM Enterprise Cobol for z/OS - Language Reference
Related Technologies
Cobol
Technical Criterion
Complexity - Algorithmic and Control Structure Complexity
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.