CL Programming

Using a Job to Debug Another Job

You may want to use a separate job to debug programs running in another job for one of the following reasons:

Debugging Batch Jobs Submitted to a Job Queue

Using a separate job to debug another batch job submitted to the job queue allows you to put the batch job into debug mode and to set breakpoints and traces before the job starts to process. Use the following steps to debug batch jobs to be submitted to a job queue:

  1. Submit the batch job using the Submit Job (SBMJOB) command or a program that automatically submits the job with HOLD(*YES).
    SBMJOB HOLD(*YES)
    
  2. Determine the qualified job name (number/user/name) that is assigned to the job using the Work with Submitted Jobs (WRKSBMJOB) command or the Work with Job Queues (WRKJOBQ) command. The SBMJOB command also displays the name in a completion message when the command finishes processing.

    The WRKJOBQ (Work With Job Queue) command displays all the jobs waiting to start in a particular job queue. You can show the job name from this display by selecting option 5 for the job.

  3. Enter the Start Service Job (STRSRVJOB) command from the display you plan to use to debug the batch job as follows:
    STRSRVJOB JOB(qualified-job-name)
    
  4. Enter the STRDBG command and provide the names of all programs to be debugged. No other debug commands can be entered while the job is waiting on the job queue.
  5. Use the Release Job Queue (RLSJOBQ) command to release the job queue. A display appears when the job is ready to start, indicating that you may begin debugging the job. Press F10 to show the Command Entry display.
  6. Use the Command Entry display to enter any debug commands, such as the Add Breakpoint (ADDBKP) or Add Trace (ADDTRC) commands.
  7. Press F3 to leave the Command Entry display, and then press Enter to start the batch job.
  8. When the job stops at a breakpoint, you see the normal breakpoint display. When the job finishes, you cannot add breakpoints and traces, or display or change variables. However, you can display any trace data using the Display Trace Data (DSPTRCDTA) command.
  9. If you wish to debug another batch job, first end debugging using the End Debug (ENDDBG) command and then end servicing the job using the End Servicing Job (ENDSRVJOB) command.

Debugging Batch Jobs Not Started from Job Queues

Some jobs started on the system are not submitted to a job queue. These jobs cannot be stopped before they start running but they can usually be debugged. To debug jobs not started from a job queue, do the following:

  1. Rename the program that is called when the job starts. For example, if the job runs program CUST310, you can rename this program to CUST310DBG.
  2. Create a small CL program with the same name as the original program (before the program was renamed). In the small CL program, use the Delay Job (DLYJOB) command to delay for one minute and then use the CALL command to call the renamed program.
  3. Allow the batch job to start to force the CL program to be delayed for one minute.
  4. Use the Work with Active Jobs (WRKACTJOB) command to find the batch job that is running. When the display appears, enter option 5 next to the job to obtain the qualified job name.
  5. Enter the Start Service Job (STRSRVJOB) command as follows:
    STRSRVJOB JOB(qualified-job-name)
    
  6. Enter STRDBG and any other debug commands, such as the Add Breakpoint (ADDBKP) or Add Trace (ADDTRC) command. Proceed with debugging as usual.

Debugging a Running Job

You can debug a job that is already running if you know what statements the job will run. For example, you may want to debug a running program if the job is looping or the job has not yet run a program that is to be debugged. The following steps allow you to debug a running job:

  1. Use the Work with Active Jobs (WRKACTJOB) command to find the job that is running. When the display appears, enter option 5 next to the job to obtain the qualified job name.
  2. Enter the Start Service Job (STRSRVJOB) command as follows:
    STRSRVJOB JOB(qualified-job-name)
    
  3. Enter the Start Debug (STRDBG) command. (Entering the command does not stop the job from running.)
    Note:
    You can use the Display Debug (DSPDBG) command to show the call stack. However, unless the program is stopped for some reason, the stack is correct only for an instant, and the program continues to run.
  4. If you know a statement to be run, enter the Add Breakpoint (ADDBKP) command to stop the job at the statement.

    If you do not know what statements are being run, do the following:

    1. Enter the Add Trace (ADDTRC) command.
    2. After a short time, enter the Remove Trace (RMVTRC) command to stop tracing the program.
    3. Enter the Display Trace Data (DSPTRCDTA) command to show what statements have processed. Use the trace data to determine which data statements to process next (for example, statements inside a program loop).
    4. Enter the Add Breakpoint (ADDBKP) command to stop the job at the statement.
  5. Enter the desired debug commands when the program is stopped at a breakpoint.

Debugging Another Interactive Job

You can debug a job from another display, whether the job is running or waiting at a menu or command entry display. To debug another interactive job, do the following:

  1. Determine the qualified job name of the job to be debugged. To determine the name, either enter the Display Job (DSPJOB) command from the display of the job to be debugged, or use the Work with Active Jobs (WRKACTJOB) command.
  2. Enter the Start Service Job (STRSRVJOB) command using the qualified job name.
  3. Enter the Start Debug (STRDBG) command and any other debug commands desired. If the job is already running, you may need to enter the Display Debug (DSPDBG) command to determine what statement in the program is processing.

When the job being debugged is stopped at a breakpoint, the display station is locked.

Considerations When Debugging One Job from Another Job

Although most jobs can be debugged from another job, you must take the following into consideration:


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]