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

Debug Batch Jobs

A job which does not require user interaction to run is known as a Batch job. In simple terms, batch job is a scheduled program which runs without or minimum user interaction, once batch job is submitted it waits for its turn in job queue, on its turn job starts automatically in the background even if user signs-off.
IBM i system provides facility to schedule batch jobs.

  • Schedule daily, weekly, monthly, start or end of the month and so on.
    Example-A batch job is scheduled to run 10.00 PM daily to take back up of important application files.

Also, batch jobs can be held until a certain time.

Submitting a batch job:


Commonly used command for submitting batch job is Submit Job (SBMJOB) command.
Example:
  • In this example, a job named DELETESPL is submitted in QBATCH job queue. The job runs the command DLTSPLF.
    SBMJOB CMD(DLTSPLF FILE(*SELECT)) JOB(DELETESPL) JOBQ(QBATCH)
  • In this example, Job named DAILYBKUP is submitted in QBATCH job queue.
    The job runs the program named BKUPFILES.
    SBMJOB CMD(CALL PGM(*LIBL/BKUPFILES)) JOB(DAILYBKUP) JOBQ(QBATCH)

Debugging a batch job:


Unlike interactive jobs, batch jobs require specific steps to perform debugging.
Following are the list of steps and recommendation for debugging batch jobs.
  • HOLD the Job: – Debug command should be executed before job starts. Hence, the job we want to debug should be on hold or yet to start. To achieve this-
    • Use the submit job (SBMJOB) command with parameter HOLD(*YES) to prevent job from executing immediately.
      SBMJOB CMD(CALL PGM(*LIBL/BKUPFILES)) JOB(DAILYBKUP) JOBQ(QBATCH) HOLD(*YES)

      The job will be submitted with status "HELD".
    • In real time applications, usually the jobs are submitted from programs with HOLD(*NO). In such cases, when SBMJOB is coded within a program, we can hold the job queue to which the job is being submitted using Hold Job Queue (HLDJOBQ) command. Once job is submitted, we can then hold the specific job with HLDJOB command or option 3 = Hold on WRKUSRJOB screen and release the job queue with Release Job Queue (RLSJOBQ) command.
      NOTE: Job queue must be released ASAP, since holding it for long time will impact execution of other jobs submitted to same job queue.
    • Schedule date/time can be specified in SBMJOB command using parameters SCDDATE and SCDTIME.
  • Find the job attributes: Note down the attributes of the submitted job. This can be done using following method-
    • Run command WRKUSRJOB STATUS(*JOBQ) and Enter option 5.

      Note down the values Job, User, Number displayed at the top of the next screen "Work with Job".
  • Start service job: The service job will allow to interactively debug the batch job.
    Enter command STRSRVJOB with the job attributes noted in last step.
    STRSRVJOB JOB(667098/HIMANSHUGA/DAILYBKUP)

  • Start debug:
    • Enter STRDBG command and enter the program name(s) you want to debug.
      STRDBG PGM(BKUPFILES) UPDPROD(*YES)


      Module source is displayed on debug screen.
    • At this point, debug commands cannot be used. Since job is not active, press F12 to return to command line and release the held job using RLSJOB command or using option 6 = Release on WRKUSRJOB screen.

      Below screen is displayed then..
    • Press F10=Command entry on above screen takes to "Command Entry" screen and type Display Module Source (DSPMODSRC) command and press ENTER; Module source is displayed again on debug screen. Break points can be added at this point.

      ADD break points.
    • Now press F3 or F12 to return to the "Command Entry" screen and press F12 again to return to the "Start Serviced Job" screen.

      Press ENTER to start the job and continue with debugging.
  • End debug and End service job:
    Once debug completes enter the ENDDBG command to end the debug and ENDSRVJOB command to end the service operations of the job that was being serviced.

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