You would like to have your application complete the previous generation of the application generated only. This Knowledge Document explains how to complete the previous generation and no others.
This is how it would be coded:
IF ESP_APPL_GEN THEN DO
IF NOT COMPLETED THEN -
ESPNOMSG AJ ALL APPL(%ESPAPPL..0) TERMINATE
To explain the above from the bottom up:
- ESPNOMSG AJ ALL APPL(%ESPAPPL..0) TERMINATE
This will issue the AJ command to terminate (complete) all the jobs in the application %ESPAPPL for generation 0 (this is the current application).
- IF NOT COMPLETED THEN - the "NOT COMPLETED" will check to see if the current generation or the current application is not completed.
- IF ESP_APPL_GEN THEN DO
This will ensure that the application completion will only run when the application is being generated. If this code is not added the "complete the application" routine will run 2 times. Once when the application is generated (generation phase) and again when it runs(process phase). The result would be that the "complete the application" would run at generation phase and complete the previous generation. Then the "complete the application" will run again in the process phase and complete the new created generation. So then no job could ever be run.