Rule Definition
When GOTO are used to jump out of a PERFORM range, program control flow is altered (an executable GO TO pointing on the statement located just after the calling PERFORM is inserted at runtime at the end of the called paragraph only if this code location is empty) and does not return to the calling statement. Moreover, program logic becomes difficult to understand and evolution can be risky.
Remediation
Only use GOTO jumps in a section scope. GOTO jumps out of PERFORM range can be used to exit the program. It is better to use conditional expression to manage control flow.
Violation Code Sample
PROCEDURE DIVISION
0000-MAIN.
PERFORM 1000-PROC.
PERFORM 2000-PROC THRU 2100-PROC.
PERFORM 3000-PROC THRU 3100-PROC.
0100-MAIN.
GOBACK.
*
1000-PROC.
MOVE A TO B.
*** This GO TO jumps out the PERFORM range
GO TO 4000-PROC.
*
2000-PROC.
ADD 1 TO B.
IF B = 5
*** This GO TO does not jump out of the PERFORM range
GO TO 2100-PROC
END-IF
2100-PROC.
EXIT.
*
3000-PROC.
ADD 1 TO B.
IF B = 5
*** This GO TO jumps out of the PERFORM range
GO TO 4000-PROC
END-IF
3100-PROC.
MOVE B TO C.
*
4000-PROC.
ADD 1 TO A.
...
GO TO 0100-MAIN.
Fixed Code Sample
PROCEDURE DIVISION
0000-MAIN.
MOVE 0 TO END-THE-PROG.
PERFORM 1000-PROC.
IF END-THE-PROG = 0
PERFORM 2000-PROC THRU 2100-PROC
END-IF
IF END-THE-PROG = 0
PERFORM 3000-PROC THRU 3100-PROC
END-IF
0100-MAIN.
GOBACK.
*
1000-PROC.
MOVE A TO B.
PERFORM 4000-PROC.
*
...
*
3000-PROC.
ADD 1 TO B.
IF B = 5
PERFORM 4000-PROC
IF END-THE-PROG = 1
*** This GO TO does not jump out of the PERFORM range
GO TO 3100-PROC
END-IF
END-IF
MOVE B TO C.
3100-PROC.
EXIT.
*
4000-PROC.
ADD 1 TO A.
...
MOVE 1 TO END-THE-PROG.
* GO TO 0100-MAIN.
Reference
IBM Enterprise Cobol for z/OS - Programming Guide
Related Technologies
Cobol
Technical Criterion
CWE-1075 - Unconditional Control Flow Transfer outside of Switch Block
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.