Batch processing is a powerful feature in Control Language (CL) that allows you to execute a series of commands or programs without manual intervention. This is particularly useful for tasks that need to be performed regularly or require significant computational resources. In this section, we will cover the basics of batch processing, how to create and manage batch jobs, and practical examples to help you understand and implement batch processing in your CL programs.

Key Concepts

  1. Batch Job: A job that is submitted to the system to be processed at a later time or under specific conditions.
  2. Job Queue: A queue where batch jobs are placed before they are executed.
  3. Job Description: A set of attributes that define how a job should be processed.
  4. Job Scheduler: A system component that manages the execution of batch jobs based on predefined criteria.

Creating a Batch Job

To create a batch job, you need to define the job's attributes and submit it to a job queue. Here is a step-by-step guide:

Step 1: Define the Job Description

A job description specifies the attributes of the job, such as the job name, user profile, and job queue. You can create a job description using the CRTJOBD (Create Job Description) command.

CRTJOBD JOBD(MYJOBD) JOBQ(QBATCH) USER(MYUSER) TEXT('My Batch Job Description')

Step 2: Create the CL Program

Write a CL program that contains the commands you want to execute as part of the batch job. Save this program in a source physical file.

PGM
    /* Your batch processing commands go here */
    DCL VAR(&MSG) TYPE(*CHAR) LEN(50)
    CHGVAR VAR(&MSG) VALUE('Batch job started')
    SNDPGMMSG MSG(&MSG)
    /* Add more commands as needed */
ENDPGM

Step 3: Submit the Batch Job

Use the SBMJOB (Submit Job) command to submit the CL program to the job queue.

SBMJOB CMD(CALL PGM(MYLIB/MYCLPGM)) JOB(MYBATCHJOB) JOBD(MYJOBD)

Managing Batch Jobs

Once a batch job is submitted, you can manage it using various CL commands:

  • WRKJOB: Work with a specific job.
  • WRKACTJOB: Work with active jobs.
  • WRKSBMJOB: Work with submitted jobs.
  • ENDJOB: End a job.
  • HLDJOB: Hold a job.
  • RLSJOB: Release a held job.

Example: Monitoring a Batch Job

You can monitor the status of a batch job using the WRKSBMJOB command.

WRKSBMJOB JOB(MYBATCHJOB)

This command displays a list of submitted jobs, allowing you to check their status, hold, release, or end them as needed.

Practical Example

Let's create a practical example where we automate a daily backup process using batch processing.

Step 1: Create the Job Description

CRTJOBD JOBD(BACKUPJOBD) JOBQ(QBATCH) USER(BACKUPUSER) TEXT('Daily Backup Job Description')

Step 2: Write the CL Program

PGM
    DCL VAR(&MSG) TYPE(*CHAR) LEN(50)
    CHGVAR VAR(&MSG) VALUE('Starting daily backup')
    SNDPGMMSG MSG(&MSG)
    
    /* Backup commands */
    SAVLIB LIB(MYLIB) DEV(TAP01) ENDOPT(*LEAVE)
    
    CHGVAR VAR(&MSG) VALUE('Daily backup completed')
    SNDPGMMSG MSG(&MSG)
ENDPGM

Step 3: Submit the Batch Job

SBMJOB CMD(CALL PGM(MYLIB/DAILYBACKUP)) JOB(DAILYBACKUP) JOBD(BACKUPJOBD) SCDDATE(*CURRENT) SCDTIME('230000')

This command schedules the DAILYBACKUP job to run at 11:00 PM every day.

Exercises

Exercise 1: Create and Submit a Batch Job

  1. Create a job description named MYJOBD with the job queue QBATCH and user MYUSER.
  2. Write a CL program that sends a message "Hello, Batch World!".
  3. Submit the CL program as a batch job named HELLOBATCH.

Solution

  1. Create the job description:

    CRTJOBD JOBD(MYJOBD) JOBQ(QBATCH) USER(MYUSER) TEXT('My Job Description')
    
  2. Write the CL program:

    PGM
        DCL VAR(&MSG) TYPE(*CHAR) LEN(50)
        CHGVAR VAR(&MSG) VALUE('Hello, Batch World!')
        SNDPGMMSG MSG(&MSG)
    ENDPGM
    
  3. Submit the batch job:

    SBMJOB CMD(CALL PGM(MYLIB/HELLOCLPGM)) JOB(HELLOBATCH) JOBD(MYJOBD)
    

Exercise 2: Monitor and Manage a Batch Job

  1. Submit a batch job that runs a CL program to create a backup of a library.
  2. Use the WRKSBMJOB command to monitor the job.
  3. Hold the job using the HLDJOB command.
  4. Release the job using the RLSJOB command.

Solution

  1. Submit the batch job:

    SBMJOB CMD(CALL PGM(MYLIB/BACKUPCLPGM)) JOB(BACKUPJOB) JOBD(BACKUPJOBD)
    
  2. Monitor the job:

    WRKSBMJOB JOB(BACKUPJOB)
    
  3. Hold the job:

    HLDJOB JOB(BACKUPJOB)
    
  4. Release the job:

    RLSJOB JOB(BACKUPJOB)
    

Conclusion

In this section, we covered the basics of batch processing in CL, including creating and managing batch jobs. We also provided practical examples and exercises to help you understand and implement batch processing in your CL programs. Batch processing is a powerful tool for automating repetitive tasks and optimizing system performance. In the next section, we will explore data integration techniques to further enhance your CL programming skills.

© Copyright 2024. All rights reserved