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
- Batch Job: A job that is submitted to the system to be processed at a later time or under specific conditions.
- Job Queue: A queue where batch jobs are placed before they are executed.
- Job Description: A set of attributes that define how a job should be processed.
- 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.
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.
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.
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
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
- Create a job description named
MYJOBD
with the job queueQBATCH
and userMYUSER
. - Write a CL program that sends a message "Hello, Batch World!".
- Submit the CL program as a batch job named
HELLOBATCH
.
Solution
-
Create the job description:
CRTJOBD JOBD(MYJOBD) JOBQ(QBATCH) USER(MYUSER) TEXT('My Job Description')
-
Write the CL program:
PGM DCL VAR(&MSG) TYPE(*CHAR) LEN(50) CHGVAR VAR(&MSG) VALUE('Hello, Batch World!') SNDPGMMSG MSG(&MSG) ENDPGM
-
Submit the batch job:
SBMJOB CMD(CALL PGM(MYLIB/HELLOCLPGM)) JOB(HELLOBATCH) JOBD(MYJOBD)
Exercise 2: Monitor and Manage a Batch Job
- Submit a batch job that runs a CL program to create a backup of a library.
- Use the
WRKSBMJOB
command to monitor the job. - Hold the job using the
HLDJOB
command. - Release the job using the
RLSJOB
command.
Solution
-
Submit the batch job:
SBMJOB CMD(CALL PGM(MYLIB/BACKUPCLPGM)) JOB(BACKUPJOB) JOBD(BACKUPJOBD)
-
Monitor the job:
WRKSBMJOB JOB(BACKUPJOB)
-
Hold the job:
HLDJOB JOB(BACKUPJOB)
-
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.
CL (Control Language) Course
Module 1: Introduction to CL
- What is Control Language?
- Setting Up Your Environment
- Basic Syntax and Structure
- Writing Your First CL Program
Module 2: Basic CL Commands
- Introduction to CL Commands
- File Management Commands
- Job Management Commands
- System Management Commands
Module 3: Variables and Expressions
Module 4: Control Structures
Module 5: Advanced CL Commands
- Advanced File Operations
- Advanced Job Scheduling
- System Configuration Commands
- Security and Permissions