Created On: 16 October 2012
Problem:
One of our programs drops thru an Exit Program to the next paragraph. We are testing a new Cobol program and it is not honoring the Exit Program verb.
Sample code follows:
Identification Division.
Program-Id. LORINCE.
Data Division.
Working-Storage Section.
1 A Pic 9.
Procedure Division.
P1.
Move 0 to A
Display ' A = ' A
If A < 3
Perform Varying A From 1 by 1 Until A > 3
Display ' A < 3, A = ' A
End-Perform
End-If
If A < 5
Perform Varying A From 1 by 2 Until A > 3
Display ' A < 5, A = ' A
End-Perform
End-If
Exit Program.
P2.
Display 'Saved For Future Calculations'.
We get this output:
A = 0
A < 3, A = 1
A < 3, A = 2
A < 3, A = 3
A < 5, A = 1
A < 5, A = 3
Saved For Future Calculations
Why does this continue on after the end of paragraph P1?
Sample code follows:
Identification Division.
Program-Id. LORINCE.
Data Division.
Working-Storage Section.
1 A Pic 9.
Procedure Division.
P1.
Move 0 to A
Display ' A = ' A
If A < 3
Perform Varying A From 1 by 1 Until A > 3
Display ' A < 3, A = ' A
End-Perform
End-If
If A < 5
Perform Varying A From 1 by 2 Until A > 3
Display ' A < 5, A = ' A
End-Perform
End-If
Exit Program.
P2.
Display 'Saved For Future Calculations'.
We get this output:
A = 0
A < 3, A = 1
A < 3, A = 2
A < 3, A = 3
A < 5, A = 1
A < 5, A = 3
Saved For Future Calculations
Why does this continue on after the end of paragraph P1?
Resolution:
The problem here was that the program being tested was not CALLed by a driver program. The Language Reference states that for a Format 4 EXIT statement:
If the EXIT PROGRAM statement is executed in a program
which is not under the control of a calling runtime element,
the EXIT PROGRAM statement causes execution of the program
to continue with the next executable statement.
The answer is to code this at the end of the first paragraph:
Exit Program
Goback.
If the EXIT PROGRAM statement is executed in a program
which is not under the control of a calling runtime element,
the EXIT PROGRAM statement causes execution of the program
to continue with the next executable statement.
The answer is to code this at the end of the first paragraph:
Exit Program
Goback.
Incident #2570631