End Job (ENDJOB)
|Where allowed to run: All environments (*ALL)
The End Job (ENDJOB) command ends the specified job and any associated inline data files. The job can be on a job queue, it can be active, or it can have already completed running.
You can specify that the application program is given time to control end-of-job processing. If no time is given or if cleanup cannot be performed within the given time, the system performs minimal end-of-job processing, which can include:
- Closing the database files.
- Spooling the job log to an output queue.
- Cleaning up internal objects in the operating system.
- Showing the end-of-job display (for interactive jobs).
- Completing commitment control processing
Before ending the job, you should verify that no logical unit of work is in an in doubt state due to a two-phase commit operation that is in progress. If it is, then the value of the Action if ENDJOB commitment option can greatly impact the ENDJOB processing. For example, if the Action if ENDJOB commitment option is the default value of WAIT, this job will be held up and will not complete its end of job processing until the commitment control operation is completed. This ensures database integrity on all related systems. For specific instructions on how to determine these conditions, and for a description of all the impacts of ending this job under these conditions, see the Backup and Recovery book.
Restrictions: The issuer of the command must be running under a user profile which is the same as the job user identity of the job being ended, or the issuer of the command must be running under a user profile which has job control (*JOBCTL) special authority. This restriction is enforced even when ending the current job.
The job user identity is the name of the user profile by which a job is known to other jobs. It is described in more detail in the Work Management book.
|JOB||Job name||Single values: *
Other values: Qualified job name
|Required, Positional 1|
|Qualifier 1: Job name||Name|
|Qualifier 2: User||Name|
|Qualifier 3: Number||000000-999999|
|OPTION||How to end||*CNTRLD, *IMMED||Optional, Positional 2|
|DELAY||Controlled end delay time||1-999999, 30||Optional, Positional 3|
|SPLFILE||Delete spooled files||*NO, *YES||Optional, Positional 4|
|LOGLMT||Maximum log entries||Integer, *SAME, *NOMAX||Optional|
|ADLINTJOBS||Additional interactive jobs||*NONE, *GRPJOB, *ALL||Optional|
|DUPJOBOPT||Duplicate job option||*SELECT, *MSG||Optional|
Job name (JOB)
Specifies the qualified job name of the job to be ended.
This is a required parameter.
- The job from which this command is run is ended. Specifying this value is the only way to end the current job.
Qualifier 1: Job name
- Specify the name of the job.
Qualifier 2: User
- Specify the user name that identifies the user profile under which the job is run.
Qualifier 3: Number
- Specify the system-assigned job number.
Note: If no user name or job number is specified, all jobs currently in the system are searched for the job name. If more than one occurrence of the specified name is found, a qualified job name must be provided either explicitly or through the selection display. Refer to the Duplicate job option (DUPJOBOPT) parameter for more information.
How to end (OPTION)
Specifies whether the job ends immediately or in a controlled manner that lets the application program perform end-of-job processing. In either case, the system performs certain job cleanup processing.
- The job ends in a controlled manner. This allows the program running to perform cleanup (end-of-job processing). When a job being ended has a signal handling procedure for the asynchronous signal SIGTERM, the SIGTERM signal is generated for that job. The application has the amount of time specified on the DELAY parameter to complete cleanup before the job is ended.
- The job ends immediately and the system performs end-of-job cleanup. System cleanup can take from a brief amount of time to several minutes. When a job being ended has a signal handling procedure for the asynchronous signal SIGTERM, the SIGTERM signal is generated for that job and the QENDJOBLMT system value specifies the time limit. Other than by handling the SIGTERM signal, the program that is running is not allowed to perform any cleanup.
Note: The *IMMED value might cause undesirable results if data has been partially updated. This value should be used only after a controlled end has been attempted unsuccessfully.
Note: When a SIGTERM signal handler is running during the immediate ending of a job, an ENDJOB command with OPTION(*IMMED) can be used to end the SIGTERM signal handler. This is only allowed if the SIGTERM signal handler has already had at least two minutes to run.
Controlled end delay time (DELAY)
Specifies the amount of time (in seconds) allowed for the job to complete its cleanup processing during a controlled end. If the cleanup is not completed before the end of the delay time, the job is ended immediately. (Only system cleanup is performed.)
The delay time does not start until the job becomes active if the job is suspended because of one of the following conditions:
- The system request option 1 is selected.
- The job is held by the Hold Job (HLDJOB) command.
- The job is transferred by the Transfer Secondary Job (TFRSECJOB) command.
- The job is transferred by the Transfer to Group Job (TFRGRPJOB) command.
Note: This parameter is valid only when OPTION(*CNTRLD) is specified.
- A maximum delay time of 30 seconds is allowed for cleanup before the job ends.
- Specify the maximum amount of delay time (in seconds) before the job ends.
Delete spooled files (SPLFILE)
Specifies whether spooled output files created by this job are kept for normal processing or deleted. Regardless of whether the spooled files are deleted, the job logs are kept.
- The spooled output files created by the job being ended are kept for normal processing by a writer. When the job ends, the spooled file action (SPLFACN) job attribute determines whether spooled files are detached from the job or kept with the job.
- The spooled output files created by the job being ended and which are on output queues in the library name space of the thread issuing this command are deleted. The job log is not deleted. If the job has already ended and the spooled file action for the job is to detach the spooled files, the End Job (ENDJOB) command will not find the job and the spooled files will not be deleted.
Maximum log entries (LOGLMT)
Specifies the maximum number of entries in the message queue of the job being ended that are written to the job log. This parameter can be used to limit the number of messages written to the job log printer file, QPJOBLOG, for a job that ends.
The value specified on this parameter can change the logging limit of the job even if the job is already ending or the job has already ended. The following are examples of how the logging limit can be changed:
- If the value specified is greater than the number of messages written at the time the command is issued, messages continue to be written until the new limit is reached.
- If the value specified is less than the number of messages already written to the spooled file, a message indicating that the limit has been reached is immediately put in the spooled file as the last entry. The remaining messages on the queue are ignored.
- If 0 (zero) is specified before any messages are written to the spooled file, no job log is produced for the job that is ending. If the job has already ended and the job log has not yet been produced, the job log is removed regardless of the value of the job log output (LOGOUTPUT) job attribute. For more information on removing pending job logs, refer to the Remove Pending Job Log (QWTRMVJL) API.
- The message logging limit does not change. If the logging limit does not change for this job on a previous command, *NOMAX is the value used by the system.
- There is no limit to the number of messages logged; all messages on the job message queue are written to the job log.
- Specify the maximum number of messages that can be written to the job log.
Additional interactive jobs (ADLINTJOBS)
Specifies whether the additional interactive jobs associated with the job specified in the Job name (JOB) parameter are ended.
- Only the job specified in the JOB parameter is ended.
- If the job specified in the JOB parameter is a group job, all group jobs associated with the group are ended. If the job is not a group job, the job specified in the JOB parameter is ended.
- All interactive jobs running on the workstation associated with the job specified in the JOB parameter are ended. This includes group jobs and secondary jobs.
Duplicate job option (DUPJOBOPT)
Specifies the action taken when duplicate jobs are found by this command.
- The selection display is shown when duplicate jobs are found during an interactive session. Otherwise, a message is issued.
- A message is issued when duplicate jobs are found.
Example 1: Ending a Job Immediately
ENDJOB JOB(JOB1) OPTION(*IMMED) SPLFILE(*YES)
This command ends a job named JOB1 immediately. Spooled output produced by the job is deleted; the job log is saved.
Example 2: Saving Spooled Output
ENDJOB JOB(001234/XYZ/JOB2) OPTION(*CNTRLD) DELAY(50) SPLFILE(*NO)
This command ends a job named 001234/XYZ/JOB2. Spooled output is saved for normal processing by the spooling writer. The job has 50 seconds to perform any cleanup routines, after which it is ended immediately.
Example 3: Removing a Pending Job Log
ENDJOB JOB(543210/ABCDE/JOB3) LOGLMT(0)
This command removes the pending job log for a completed job named 543210/ABCDE/JOB3. This has the same effect as the Remove Pending Job Log (QWTRMVJL) API.
Example 4: Ending the Current Job
ENDJOB JOB(*) OPTION(*IMMED)
This command ends the job in which the command is issued. To exit from a SIGTERM signal handling procedure after the required cleanup has been performed, immediately end the current job. Control may be returned to the command issuer, even though the immediate option has been used. To handle this situation, the program which issued this command should return.
- No response from subsystem for job &3/&2/&1.
- Job &1 user &2 job number &3 not found.
- End of duplicate job names.
- Job control function not performed.
- Reader or writer &3/&2/&1 not allowed as job name.
- Current job not allowed as job name on this command.
- Job &3/&2/&1 not valid job type for function.
- Not authorized to control job &3/&2/&1.
- Function check occurred in subsystem for job &3/&2/&1.
- Function not done. &3/&2/&1 in transition condition.
- ENDJOB OPTION(*IMMED) not allowed at this time.
- &3/&2/&1 already ending because of ENDJOBABN.
- Job &3/&2/&1 already ending with *IMMED option.
- Job &3/&2/&1 has completed.
- Job &3/&2/&1 is already ending *CNTRLD.
- Spool control block for job &10/&9/&8 damaged.