MainframeSupports
tip week 51/2014:

It is extremely easy to terminate an executing program in COBOL. You just execute a GOBACK. Unfortunately it is much more complicated in PL/I. Maybe you have tracked down EXIT and STOP, tried them and found out that strange things happen especially to the return code. In the manual it is stated that EXIT and STOP leads to "abnormal termination" and therefore they cannot be used for simulation of GOBACK.

Fortunately there is a way to simulate GOBACK which I have used for many years. Just in front of the END statement that terminates the MAIN procedure you define a label. I call it endOfProgram. Now you can simulate the GOBACK functionality like this:

myPgm: PROC OPTIONS(MAIN);
...
CALL goback;
...
goback: PROC;
  GO TO endOfProgram;
END goback;
...
endOfProgram:
END myPgm;

The above example is of course very simplified. You can add more code, like error processing and setting of the return code. The good part is that the program terminates normally and you can even use the trick described in week 43/2014 by setting a breakpoint on the GO TO statement and skip it when the breakpoint is reached. You can execute the CALL GOBACK anywhere you like, even in a procedure called seventeen levels down or more. It will still work correctly.

Previous tip in english        Forrige danske tip        Tip list