How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

IBM i e-Book

A Developer’s Guide to Mastering IBM i Concepts

Jobs & Logs

Job Log

A job log contains information related to requests entered for a job. Each job has an associated job log that can contain the following information for the job.

  • The commands in the job
  • The commands in CL program, if CL program was created with the LOG(*YES) option or with the LOG(*JOB) option and a change job (CHGJOB) is run with the LOGCLPGM(*YES) option.
  • All messages and message help sent to the requester and not removed from the program message queues.

At the end of the job, the job log can be written to the output file QPJOBLOG so that it can be printed. After the job log is written to the output file, the job log is deleted.

Controlling information written in a job log

To control what information the system writes in the job log, specify the LOG parameter on the Create Job Description (CRTJOBD) command. You can change the levels by using the Change Job (CHGJOB) command or the Change Job Description (CHGJOBD) command.

Three values make up the LOG parameter: message level, message severity, and message text level.

The first value, message level, has the following levels:

Level Description
0 No data is logged.
1 The only information to be logged is all messages sent to the job’s external message queue with a severity greater than or equal to the message severity specified. Messages of this type indicate when the job started, when it ended, and its status at completion.
2 The following information is logged:

  • Level 1 logging information.
  • Any requests that result in high-level messages with a severity greater than or equal to the severity specified. If the request is logged, all its associated messages are also logged.
3 The following information is logged:

  • Logging level 1 and 2 information.
  • All requests.
  • Commands run by a CL program if allowed by the Log CL program commands job attribute and the Log attribute of the CL program.
4 The following information is logged:

  • All requests and all messages with a severity code greater than or equal to the severity specified, including trace messages.
  • Commands run by a CL program if allowed by the Log CL program commands job attribute and the Log attribute of the CL program.

The second value, message severity, specifies the severity level in conjunction with the log level that causes error messages to be logged in the job log. Values 0 through 99 are allowed.

The third value in the LOG parameter, message text level, specifies the level of message text that is written in the job log. The values are:

*SAME
The current value for the message text level does not change.
*MSG
Only message text is written to the job log (message help is not included).
*SECLVL
The message and the message help (cause and recovery) are written to the job log.

Displaying a job log

The way to display a job log depends on the status of the job.

  • The Work with Job Logs (WRKJOBLOG) command can be used to display pending job logs for completed jobs, all job log spooled files, or both. For example, to display the list of pending job logs for all jobs that have ended, enter: WRKJOBLOG JOBLOGSTT(*PENDING)
  • If the job is active or in a job queue, or if the job log is pending, use the Display Job Log (DSPJOBLOG) command. For example, to display the job log of the interactive job for user JSMITH at display station WS1, enter: DSPJOBLOG JOB(nnnnnn/JSMITH/WS1), where nnnnnn is the job number.
  • If the job has ended and the job log is written to an output file but is not yet printed, use the Display Spooled File (DSPSPLF) command, as follows: DSPSPLF FILE(QPJOBLOG) JOB(001293/FRED/WS3). to display the job logs for job number 001293 associated with user FRED at display station WS3.
  • To display the job log of your own interactive job, do one of the following:
    • Enter the command: DSPJOBLOG OR
    • Enter the WRKJOB command and select option 10 (Display job log) from the Work with Job display.
    • Press F10=Include detailed messages from the Command Entry display (this key displays the messages that are shown in the job log).
    • Use the cursor movement keys to get to the end of the job log. To get to the end of the job log quickly, press F18 (Bottom). After pressing F18, you might need to roll down to see the command that is running.
    • Use the cursor movement keys to get to the top of the job log. To get to the top of the job log quickly, press F17 (Top).


  • To display the job log in command WRKACTJOB:
    • Use the WRKACTJOB command.
    • Take option 5 against the job.
    • Type option 10 to see the job log.
    • Press F10=Include detailed messages from the Command Entry display (this key displays the messages that are shown in the job log).
    • Use the cursor movement keys to get to the end of the job log. To get to the end of the job log quickly, press F18 (Bottom). After pressing F18, you might need to roll down to see the command that is running.
    • Use the cursor movement keys to get to the top of the job log. To get to the top of the job log quickly, press F17 (Top).




Preventing the production of job logs

  • To prevent a job log from being produced at the completion of a batch job, you can specify *NOLIST for the message text-level value of the LOG parameter on the Batch Job (BCHJOB), Submit Job (SBMJOB), Change Job (CHGJOB), Create Job Description (CRTJOBD), or Change Job Description (CHGJOBD) command.
  • If you specify *NOLIST for the message level value of the LOG parameter, the job log is not produced at the end of a job unless the job end code is 20 or greater. If the job end is 20 or greater, the job log is produced.
  • For an interactive job, the value specified for the LOG parameter on the SIGNOFF command takes precedence over the LOG parameter value specified for the job.
  • To prevent a job log from being produced when the job is completed, but remain in the system in a pending state, specify *PND for the LOGOUTPUT parameter on the Submit Job (SBMJOB), Change Job (CHGJOB), Create Job Description (CRTJOBD), or Change Job Description (CHGJOBD) command. If you specify *NOLIST for the LOG parameter, no job log will be produced, and there will be no pending job log either. Pending job logs will only be available when a job log would normally be written to an output file or database file when the job ends and the job log output job attribute is *PND. You can use the Work with Job Logs (WRKJOBLOG) command to find both pending and written job logs.

Job log from programming perspective

  • Write to job log, we can send messages from inside a running RPG program. We can do it by using one of IBM’s APIs – Qp0zLprintf

    The procedure prototype is as below.

    Example

  • Using SQL to get information from Job Logs.

    We can get job log information with SQL Select query from table JOBLOG_INFO. It returns one row for each job log message.

    SELECT *
    FROM TABLE(QSYS2.JOBLOG_INFO('*')) A;
    

    The parameter ‘*’ says to retrieve the information from the current job. If we wanted to look at a different job we would change the parameter to the fully qualified jobname such as:

    SELECT *
    FROM TABLE(QSYS2.JOBLOG_INFO('878597/QUSER/QZDASOINIT')) A;
    

    If we wanted to see the job log in reverse order, we can do this with:

    SELECT *
    FROM TABLE(QSYS2.JOBLOG_INFO('*')) A
    ORDER by ordinal_position desc;
    

    to retrieve only the last message in the joblog.

    SELECT message_id, message_text, message_second_level_text
    FROM TABLE(QSYS2.JOBLOG_INFO('*')) A
    ORDER by ordinal_position desc
    fetch first row only;
    
    

How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

share_iconShare
X

Awards and Certifications

company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo