Version 5.5
Examples Cookbook
First Edition (June 2007)
This documentation and any related computer software help programs (hereinafter referred to as the “Documentation”) is for the end user’s informational purposes only and is subject to change or withdrawal by CA at any time.
This Documentation may not be copied, transferred, reproduced, disclosed, modified or duplicated, in whole or in part, without the prior written consent of CA. This
Documentation is confidential and proprietary information of CA and protected by the copyright laws of the United States and international treaties.
Notwithstanding the foregoing, licensed users may print a reasonable number of copies of the documentation for their own internal use, and may make one copy of the related software as reasonably required for back-up and disaster recovery purposes, provided that all CA copyright notices and legends are affixed to each reproduced copy. Only authorized
employees, consultants, or agents of the user who are bound by the provisions of the license for the product are permitted to have access to such copies.
The right to print copies of the documentation and to make a copy of the related software is limited to the period during which the applicable license for the Product remains in full force and effect. Should the license terminate for any reason, it shall be the user’s responsibility to certify in writing to CA that all copies and partial copies of the Documentation have been returned to CA or destroyed.
EXCEPT AS OTHERWISE STATED IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS DOCUMENTATION “AS IS” WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. IN NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS DOCUMENTATION, INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE.
The use of any product referenced in the Documentation is governed by the end user’s applicable license agreement.
The manufacturer of this Documentation is CA.
Provided with “Restricted Rights.” Use, duplication or disclosure by the United States Government is subject to the restrictions set forth in FAR Sections 12.212, 52.227-14, and 52.227-19(c)(1) - (2) and DFARS Section 252.227-7014(b)(3), as applicable, or their successors.
All trademarks, trade names, service marks, and logos referenced herein belong to their respective companies.
ESP-5.5-EC-01 iii
About this document vii
Using this document ... viii
Summary of changes ... x
ESP Workload Manager examples 1 Scheduling a weekly job and adjusting it for holidays ... 2
Scheduling a job within a month... 3
Scheduling a job to run based on a different day’s holiday status ... 4
Scheduling a job to run based on a previous day’s holiday status ... 5
Scheduling a job to run within a specific date range ... 6
Scheduling a job to run on selected workdays only... 7
Scheduling a job relative to a special day ... 8
Scheduling a monthly job and delaying it for non-workdays ... 9
Scheduling a job based on the day of the week for the 1st day of month ... 10
Scheduling a job to run on the last five workdays of the month... 11
Scheduling a job based on when another job was scheduled ... 13
Scheduling a job based on the workday status of the last day of the previous month... 14
Determining if a day in the past was a workday... 15
Scheduling a job to run every two days... 16
Scheduling a job to run every two weeks and advancing it for holidays ... 17
Scheduling different jobs to run based on the calendar quarter... 19
Scheduling a job on a random day of the month ... 20
Scheduling an hourly Application within a time range ... 21
Scheduling an hourly job within a time range ... 22
Scheduling a different job to run every hour... 24
Scheduling a job in an Application to run based on day and time ... 26
Scheduling an ad hoc job to run multiple times ... 27
Scheduling a job to run every two hours... 29
Scheduling a job to run multiple times within a time range... 30
Running ad hoc sequential jobs... 32
Dynamically defining and scheduling an Event ... 35
Scheduling a weekly Application based on the number of workdays in the week... 36
Running the next scheduled Application early... 38
Running an Application for any future date ... 39
Delaying job submission until the next hour ... 40
Setting up a dependency with a job’s previous run ... 41
Using date-qualified file names... 43
Processing a changing file name ... 44
Copying a file to another location upon the file’s creation... 45
Ensuring a file exists before processing ... 46
Bypassing a job based on the status of another job... 48
Bypassing non-critical jobs when jobs are late ... 49
Taking different actions based on 1 of 3 successful return codes... 52
Running different jobs based on the return code of a predecessor job... 54
Auto-triggering an Event for a reoccurring job ... 55
Scheduling a job to run based on its previous run status... 56
Scheduling a cyclic Application ... 57
Incrementing a cycle number ... 59
Building Applications dynamically based on an input file... 62
Running a job based on resource availability ... 64
Running or completing a job based on the order in which its predecessors complete ... 65
Scheduling a job based on a data set, time, and weekdays... 67
Using the Application name in the script path ... 69
Identifying critical jobs for disaster recovery planning ... 70
Using a one-time job section in Applications... 71
Using the same Application for different locations ... 73
Merging Applications into a single PDS member ... 75
Consolidating data set triggers to minimize the number of Event definitions ... 77
Resubmitting a job 5 minutes after it fails ... 79
Resubmitting a failed job a maximum of two times... 80
ESP-5.5-EC-01 v
Sending email notification for job failures ... 85
Sending a message when an Agent becomes inactive... 87
Displaying job details from CSF... 88
Bypassing a job across multiple Applications ... 89
Holding all incomplete generations of an Application ... 90
Listing a job plus its successor chains in an active Application ... 91
Creating a variable for the day of week number... 93
Creating a variable for the accounting year... 94
Calculating the week number... 95
Providing a variable for all data sets in a DSTRIG Event... 97
Running jobs using ESP Encore’s SCAN mode... 99
Setting COPYJCL as the default JCL library for resubmission ... 100
Using date-qualified TEMPLIBs ... 101
ESP-5.5-EC-01 vii
This document contains real-life examples of using ESP Workload Manager to solve common workload scheduling challenges. You can adapt these examples to meet your own business requirements. Many of these examples come from our users’ work experience and are being used in their installations.
Section–Using this document
Using this document
Instructions for copying code
The code in the examples is meant to be copied and used as needed. You can use the code in the examples by copying and pasting it from the PDF. If you need to
download the Adobe Acrobat PDF reader, you can download it for free from the Adobe website at www.adobe.com.
To copy and paste code from Adobe PDF
1. Activate the Select Text Tool by clicking this button .
2. Click and drag to select text.
3. Copy selected text by pressing Ctrl+C.
4. Paste text by pressing Ctrl+V.
Intended audience
The examples in this document are intended for users who have a basic working knowledge of ESP Workload Manager. A wide range of examples is provided and will be of use to beginners through to advanced users. For more information on ESP Workload Manager, see the following guides:
• ESP Workload Manager User’s Guide • ESP Workload Manager Operator’s Guide • ESP Workload Manager Advanced User’s Guide
• ESP Workload Manager Installation and Configuration Guide • ESP Workload Manager Reference Guide
• ESP Encore User’s Guide
Conventions for using commands and statements
ESP Workload Manager commands may be entered in line mode, page mode, batch or loaded from a data set (using the LOAD command). In ESP Workstation or the ESP Workload Manager Web Interface, commands can be entered from the line mode interface. Many commands can also be entered from a system console.
ESP Workload Manager statements must be entered into a Procedure within a data set, specific to the type of statement used. The following conventions apply to entering statements, as well as to entering commands and initialization parameters that are contained in a data set.
ESP-5.5-EC-01 ix
Continuation
Statements cannot extend beyond column 72. To continue lines longer than 72 characters, type either a hyphen (-) or a plus sign (+) as the last non-blank character on a line to continue a line of input. The hyphen attaches the next line including any leading blank positions. The plus sign strips leading blanks from a continuation line. Blanks preceding the hyphen or the plus sign are retained.
Note: A hyphen can also be used as a wildcard character in some commands.
Wildcards and masking
Many statements, commands, and initialization parameters permit the use of the following wildcard characters (also called masking):
• An asterisk matches a specific single character.
• A hyphen matches zero or more characters. It can only be used as the last character
of the operand. If the wildcard hyphen is the last character on the line, it will be interpreted as a continuation character and not as a wildcard. For the hyphen to be interpreted as a wildcard, it must be followed by a semicolon or something else on the line such as a comment: (/* */).
Comments
Enclose comments between /* and */. Comments can be written anywhere in an ESP Procedure.
Data sets
Enclose all data set names in single quotation marks; otherwise, ESP Workload Manager adds your TSO data set prefix to the name. Use ROS-, LIB- or PAN- prefixes to identify Roscoe, Librarian, and Panvalet data sets respectively.
Delimiters
Use single quotation marks when you want to denote character strings and literal data in expressions, assignment statements, and built-in functions. You must include single quotation marks around a string that contains blanks.
Indentation
Section–Summary of changes
Naming Conventions
The following shortened names are used in place of their respective full names:
Summary of changes
This book contains information previously presented in Examples Cookbook, ESP-5.4-EC-01, which supports ESP Workload Manager 5.4.
What’s New
This edition includes the following new examples:
• “Copying a file to another location upon the file’s creation” on page 45
• “Sending a message when an Agent becomes inactive” on page 87
What’s Changed
The solutions for the following examples have been rewritten to take advantage of new features in ESP Workload Manager 5.5.
IFHOLIDAYPLUS run criteria
• “Scheduling a job based on when another job was scheduled” on page 13
• “Scheduling a job to run every two weeks and delaying it for holidays” on page 18
EVERY run criteria
• “Scheduling a job to run every two days” on page 16
• “Scheduling a job to run every two weeks and advancing it for holidays” on
page 17
• “Scheduling a job to run every two weeks and delaying it for holidays” on page 18
Self-completing tasks
• “Scheduling an ad hoc job to run multiple times” on page 27
• “Bypassing a job based on the status of another job” on page 48
• “Running a job based on resource availability” on page 64
• “Resubmitting a failed job a maximum of two times” on page 80
Full Name Short Name
ESP Application Application
ESP Event Event
ESP-5.5-EC-01 xi
Conditional release expressions
• “Taking different actions based on 1 of 3 successful return codes” on page 52
Scheduling a weekly job and adjusting it for holidays
ObjectiveSchedule a job to run every Monday, unless Monday is a holiday. If Monday is a holiday, then run the job on the previous workday.
Solution
Use the following RUN statement for the job:
RUN MONDAY LESS 0 WORKDAYS
Explanation
The job always runs on Mondays that are workdays. When Monday is a holiday, and thus a non-workday, the job runs on the previous workday.
Variation
If, instead, you wanted to run the job on the first workday after the holiday, use the following RUN statement for the job:
RUN MONDAY PLUS 0 WORKDAYS
Variation
If, instead, you didn’t want to run the job at all when Monday falls on a holiday, you can use the following RUN statement for the job:
ESP-5.5-EC-01 3
Scheduling a job within a month
ObjectiveRun a job on the 5th Friday of the month but only in months that have 5 Fridays.
Solution
Use the following run criteria for the job:
RUN 5th friday within month
Explanation
This solution runs the job on the 5th Friday of the month in months that contain 5 Fridays.
Scheduling a job to run based on a different day’s holiday
status
Objective
Schedule a job to run every Saturday, unless the following Monday falls on a holiday. If the following Monday falls on a holiday, the job should not run.
Solution
Use the following statements for the job:
JOB A RUN SAT
IF DAYS_TO('HOLIDAY') = 2 THEN NORUN TODAY ENDJOB
Explanation
The job is scheduled to run on Saturdays. However, if the number of days to the next holiday is 2, the job is not scheduled.
ESP-5.5-EC-01 5
Scheduling a job to run based on a previous day’s holiday
status
Objective
Schedule a job to run every Monday, except when the previous Friday is a holiday. Workdays are Monday through Friday.
Solution
Use the following statements for the job:
JOB A
IF TODAY('MON') AND DAYS_FROM('TODAY LESS 1 WORKDAY')=3 THEN RUN TODAY
ENDJOB
Explanation
This solution checks to see if today is a Monday and the number of days from the previous workday is 3 (in other words, Friday was a workday). If both conditions are true, the job is selected to run.
Variations
Another way of coding this, assuming that holidays do not fall on Saturday or Sunday, is:
IF TODAY('MON') AND NOT TODAY('HOLIDAY PLUS 1 WEEKDAY') THEN -RUN TODAY
Or, you can use the following run criteria:
RUN MONDAY
NORUN HOLIDAY PLUS 1 WEEKDAY
For a general approach to determining whether a day in the past was a workday, refer to “Determining if a day in the past was a workday” on page 15.
Scheduling a job to run within a specific date range
ObjectiveRun a job every Thursday between April 17, 2005 and November 6, 2005, inclusively.
Solution
Use the following statements for the job:
JOB A
IF DAYS_FROM('APR 17,2005') GE 0 AND DAYS_TO('NOV 6,2005') GE 0
THEN RUN THURSDAY ENDJOB
Explanation
This solution uses the DAYS_FROM and DAYS_TO built-in functions to check if the current day is within the required date range. If it is, the job is selected to run on Thursdays.
ESP-5.5-EC-01 7
Scheduling a job to run on selected workdays only
ObjectiveRun a job from the 15th day to 25th day of the month, but only on workdays.
Solution
Use the following statements for the job:
JOB A
IF TODAY('15TH-25TH DAY OF MONTH') THEN RUN WORKDAYS ENDJOB
Explanation
This solution uses the TODAY built-in function to determine if today is within the required day range. If it is, the job is selected to run on workdays.
Scheduling a job relative to a special day
ObjectiveRun a job on the first Saturday on or after a special day.
Solution
Use the following run criteria for the job:
RUN 1ST SATURDAY OF SPECIAL_DAY
Explanation
This solution selects the job to run on the first instance of Saturday on or after SPECIAL_DAY.
ESP-5.5-EC-01 9
Scheduling a monthly job and delaying it for non-workdays
ObjectiveRun a job on the 5th day of the month if it is a workday. If it is not a workday, run the job on the day after the 5th day of the month, regardless of whether it is a workday.
Solution
Use the following statements for the job:
JOB A
GENTIME AA 5TH DAY OF MONTH
GENTIME BB 5TH DAY OF MONTH PLUS 0 WORKDAYS IF AADATE = BBDATE THEN RUN %AADATE
ELSE RUN %AADATE PLUS 1 DAY ENDJOB
Explanation
This solution uses two GENTIME commands to generate date and time variables for the 5th day of the month and for the first workday on or after the 5th day of the month. If these dates are equal, then the 5th day of a month is a workday, and job A runs on the 5th day of the month. Otherwise, job A runs 1 day after the 5th day of the month.
For a general approach to determining whether a day in the past was a workday, refer to “Determining if a day in the past was a workday” on page 15.
Scheduling a job based on the day of the week for the 1st day
of month
Objective
Run a job on the 1st Monday of each month. However, if the month starts on a Saturday or a Sunday, run the job on the 2nd Monday of the month instead.
Solution
Use the following statements for the job:
JOB A
GENTIME ONE 1ST DAY OF MONTH STARTING TODAY IF ONEDAY='SATURDAY' OR ONEDAY='SUNDAY' THEN RUN 2ND MONDAY OF MONTH
ELSE RUN 1ST MONDAY OF MONTH ENDJOB
Explanation
This solution uses the GENTIME command to generate date and time variables for the 1st day of the current month. If the day-of-week variable from the GENTIME (in other words, ONEDAY) is Saturday or Sunday, job A runs on the 2nd Monday of the month. Otherwise, job A runs on the 1st Monday of the month.
ESP-5.5-EC-01 11
Scheduling a job to run on the last five workdays of the month
ObjectiveSchedule a job to run only on the last 5 workdays of each month.
Solution
Use the following statements for the job:
JOB A
GENTIME LAST5 LAST WORKDAY OF MONTH LESS 4 WORKDAYS IF LAST5DD <= ESPSDD AND TODAY('WORKDAY') THEN RUN TODAY ENDJOB
Explanation
The GENTIME command generates date and time variables for 4 workdays prior to the last workday of the month (in other words, the 5th last workday of the month). If the day of the month for the 5th last workday of the month (as indicated by the LAST5DD variable) is less than or equal to the scheduled day, and it also is a workday, then the job is selected to run.
Example
The calendar below shows October 2005.
If workdays are Monday through Friday and there are no holidays at the end of October 2005, then the 5th last workday of the month falls on October 25. The LAST5DD variable has a value of 25. This means that in October 2005, the job would be scheduled only on October 25, 26, 27, 28, and 31 (not on October 29 or 30, which fall on a weekend).
Variation
Another solution is to use the following run criteria for the job:
RUN LAST WORKDAY OF MONTH
RUN LAST WORKDAY OF MONTH LESS 1 WORKDAY RUN LAST WORKDAY OF MONTH LESS 2 WORKDAYS RUN LAST WORKDAY OF MONTH LESS 3 WORKDAYS RUN LAST WORKDAY OF MONTH LESS 4 WORKDAYS
ESP-5.5-EC-01 13
Scheduling a job based on when another job was scheduled
ObjectiveJob A runs every Wednesday, unless Wednesday is a holiday. If Wednesday is a holiday, job A runs on Thursday.
Schedule job B to run every Thursday, except when job A runs on Thursday. When job A runs on Thursday, run job B on Friday.
Solution
Use the following statements for the jobs:
GENTIME A WEDNESDAY STARTING TODAY LESS 2 DAYS GENTIME B %ADATE PLUS 0 WORKDAYS
JOB A
RUN WEDNESDAY IFHOLIDAYPLUS 1 DAY ENDJOB
JOB B
IF NOT SELECTED('A') THEN RUN THURSDAY
IF TODAY('FRIDAY') AND ADATE NE BDATE THEN RUN TODAY ENDJOB
Explanation
Two GENTIME commands are used in this solution. The first GENTIME command generates date and time variables for Wednesday of the current week. The second GENTIME command generates date and time variables for the first workday on or after Wednesday’s date. If the two GENTIME dates are not equal, then Wednesday was a holiday.
Job A is selected to run every Wednesday. If Wednesday falls on a holiday, ESP Workload Manager selects job A to run on Thursday instead.
Job B is selected to run when either of these conditions is true:
• Today is Thursday and job A is not selected to run.
• Today is Friday and Wednesday was a holiday.
For a general approach to determining whether a day in the past was a workday, refer to “Determining if a day in the past was a workday” on page 15.
Scheduling a job based on the workday status of the last day
of the previous month
Objective
Run a job on the 2nd workday of each month, but only if the last day of the previous month was a workday.
Solution
Use the following statements for the job:
JOB A
GENTIME LD LAST DAY OF MONTH STARTING TODAY LESS 1 MONTH GENTIME LWD LAST WORKDAY OF MONTH STARTING TODAY LESS 1 MONTH IF %LDDATE EQ %LWDDATE THEN RUN 2ND WORKDAY OF MONTH
ENDJOB
Explanation
This solution uses two GENTIME commands to generate date and time variables for the last day of the previous month and for the last workday of the previous month. If these two dates are equal, then the last day of the previous month was a workday, and the job is selected to run on the 2nd workday of the month.
For a general approach to determining whether a day in the past was a workday, refer to “Determining if a day in the past was a workday” on page 15.
ESP-5.5-EC-01 15
Determining if a day in the past was a workday
ObjectiveDetermine whether some day in the past was a workday. For example, you may need to determine if last Friday was a workday, or if a fixed date fell on a workday, and schedule a job based on the result.
Solution
The following code sets the variable VALUE to either true or false based on whether or not May 13, 2004 was a workday.
GENTIME ONE MAY 13, 2004
GENTIME TWO %ONEDATE PLUS 0 WORKDAYS IF ONEDATE=TWODATE THEN VALUE='TRUE' ELSE VALUE='FALSE'
Explanation
This solution shows a general approach to checking if a day in the past was a workday. The first GENTIME generates date and time variables for the day in the past. This could be a criteria, such as LAST DAY OF MONTH STARTING TODAY LESS 1 MONTH, or it could be a date such as MAY 13, 2004.
The second GENTIME generates date and time variables for the first workday on, or after, your first criteria. It uses the DATE variable from your first GENTIME (in other words, %ONEDATE) and adds ‘PLUS 0 WORKDAYS’.
The two dates from the GENTIMEs are then compared. If they are equal then the day in the past was a workday; otherwise, it was a non-workday.
Note: The default retain count for holidays is 2 days. Since holidays affect what is considered a workday, you may need to retain some holidays for a longer period if you need to refer back to them after two days.
Scheduling a job to run every two days
ObjectiveA job needs to run every two days and belongs to an Application containing jobs with many different frequencies. Use April 1, 2004 as the starting point for the schedule.
Solution
Use the following run criteria for the job:
RUN EVERY 2 DAYS STARTING APR 1ST 2004
Explanation
ESP-5.5-EC-01 17
Scheduling a job to run every two weeks and advancing it for
holidays
Objective
A job in an Application needs to run every two weeks on Friday. If this falls on a non-workday, run the job on the previous workday instead. Use Friday, August 1, 2003 as the starting point for the schedule.
Solution
Use the following run criteria for the job:
RUN EVERY 2 WEEKS STARTING AUG 1ST 2003 LESS 0 WORKDAYS
Explanation
This solution selects the job to run every two weeks starting on Friday, August 1, 2003. If the Friday is a holiday, ESP Workload Manager selects the job to run on the previous workday instead.
Scheduling a job to run every two weeks and delaying it for
holidays
Objective
Schedule a job to run every second Wednesday, unless Wednesday is a holiday. If Wednesday is a holiday, run the job on Thursday regardless of whether Thursday is a holiday. Use Wednesday, April 7, 2004, as the starting point for the schedule.
Solution
Use the following run criteria for the job:
RUN EVERY 2 WEEKS STARTING APR 7TH 2004 IFHOLIDAYPLUS 1 DAY
Explanation
This solution selects the job to run every two weeks starting on Wednesday, April 7, 2004. If the Wednesday falls on a holiday, ESP Workload Manager selects the job to run on Thursday instead.
ESP-5.5-EC-01 19
Scheduling different jobs to run based on the calendar quarter
ObjectiveSchedule a different job to run each calendar quarter. Each calendar quarter consists of three months, and the first quarter starts on January 1.
Solution
Use the following Application:
APPL CYBER
JCLLIB 'CYBER.JCLLIB'
JOB A.QTR1
RUN ANYDAY OF JAN FEB MAR ENDJOB
JOB B.QTR2
RUN ANYDAY OF APR MAY JUN ENDJOB
JOB C.QTR3
RUN ANYDAY OF JUL AUG SEP ENDJOB
JOB D.QTR4
RUN ANYDAY OF OCT NOV DEC ENDJOB
Explanation
Each job has a different RUN statement to reflect the quarter in which it should run. Depending on the month, one of the RUN statements applies, and the appropriate job is selected to run.
Scheduling a job on a random day of the month
ObjectiveA job needs to run at 11 AM on a random day each month.
Solution
Schedule an Event on the last day of the month to invoke the following Procedure:
/* CALCULATE NUMBER OF DAYS IN NEXT MONTH - NUMDD /*
GENTIME NUM LAST DAY OF MONTH STARTING TODAY PLUS 1 MONTH /*
/* USE REXX TO GENERATE A RANDOM NUMBER BETWEEN 1 AND /* NUMBER OF DAYS IN NEXT MONTH
/* REXXON DAYS_IN_MONTH=CLANGVAR('%NUMDD') DAY=RANDOM(1,DAYS_IN_MONTH) "NUMBER="DAY REXXOFF /*
/* GENERATE APPLICATION - DELAY JOB UNTIL 11AM ON THE /* RANDOM DAY /* APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB RANDOM RUN ANY
DELAYSUB 11AM TODAY PLUS %NUMBER DAYS ENDJOB
Explanation
This Procedure runs on the last day of the month and determines when the job should run in the following month. GENTIME creates date and time variables, prefixed with NUM, for the next month. The NUMDD variable represents the number of days in the next month. This solution uses REXX to generate a random number between 1 and NUMDD.
The Application builds with the job delayed for the random number of days at 11 AM.
ESP-5.5-EC-01 21
Scheduling an hourly Application within a time range
ObjectiveSchedule an Application to run every hour from 8 AM to 4 PM on workdays.
Solution
Use the following Event to run your Application:
EVENT ID(PROD.HOURJOB)
SCHEDULE HOURLY ROUND STARTING TODAY SUSPEND 4:01PM WORKDAYS
RESUME 7:59AM WORKDAYS
INVOKE 'PROD.PROCLIB(HOURJOB)' ENDDEF
Explanation
The Event is scheduled every hour on the hour. SUSPEND and RESUME commands are used within the Event to control processing. The Event is suspended just after its 4 PM execution on workdays and resumed just prior to its 8 AM execution on workdays. This enables the Event to run hourly between 8 AM and 4 PM on workdays.
Variation
Another solution is to schedule the Event multiple times each workday. For example:
SCHEDULE 8AM WORKDAYS SCHEDULE 9AM WORKDAYS .
. .
Scheduling an hourly job within a time range
ObjectiveSchedule a job to run every hour from 8 AM to 4 PM on workdays. The job belongs to an Application containing many different jobs with different frequencies.
Solution
One solution is to use a template within your Application definition. Take the following steps:
1. Use a template in your Application to define multiple instances of the job. For example:
APPL CYBER
JCLLIB 'CYBER.JCLLIB'
TEMPLATE HOURLY (1,OFFSET) JOB A.%OFFSET
RUN WORKDAYS
DELAYSUB 8AM PLUS %OFFSET HOURS ENDJOB ENDTEMPL HOURLY 0 HOURLY 1 HOURLY 2 HOURLY 3 HOURLY 4 HOURLY 5 HOURLY 6 HOURLY 7 HOURLY 8
2. Schedule an Event prior to 8 AM that invokes this Application.
Explanation
This solution uses a template called HOURLY. Instead of creating separate job definitions for each instance of job A in the Application, the template defines the job requirements for all instances of the job in a few statements.
The template accepts one parameter for the offset from 8 AM (0 hours, 1 hour, 2 hours, and so on). This offset is used as a job qualifier for the job to ensure uniqueness within each generation of the Application. It is also used in the DELAYSUB statement to specify the time dependency relative to 8 AM.
ESP-5.5-EC-01 23
The code generated through calling the template is shown below:
Note: If the Application contains only the one job that needs to run each hour, you can simply schedule the Event each hour between these times and invoke an Application containing the job to be run.
JOB A.0
RUN WORKDAYS
DELAYSUB 8AM PLUS 0 HOURS ENDJOB
JOB A.1
RUN WORKDAYS
DELAYSUB 8AM PLUS 1 HOURS ENDJOB . . . JOB A.8 RUN WORKDAYS
DELAYSUB 8AM PLUS 8 HOURS ENDJOB
Scheduling a different job to run every hour
ObjectiveA one-job Application runs each hour. The name of the job in the Application depends upon its scheduled time. The jobnames are called MYJOB followed by a letter of the alphabet which is based on the scheduled hour. At 1 AM use the letter A, at 2 AM use the letter B, and so on, as shown in the following table:
Solution
Take the following steps:
1. Use the following Application:
LETTERS='ABCDEFGHIJKLMNOPQRSTUVWX' INTEGER HOUR
IF ESPSHH='00' THEN HOUR=24 ELSE HOUR=ESPSHH CHAR='%LETTERS(%HOUR:%HOUR)' APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB MYJOB%CHAR RUN ANY ENDJOB
2. Schedule an Event hourly to submit the one-job Application.
Explanation
The solution uses a symbolic variable called LETTERS, which is assigned a string representing the letters of the alphabet from A to X. Each hour, ESP Workload Manager uses a different substring of this variable based on the scheduled hour (ESPSHH).
The HOUR variable is used as an integer variable to enable substrings since substring notation requires numbers and not characters. If the scheduled hour is midnight then
Time Jobname 1 AM MYJOBA 2 AM MYJOBB 3 AM MYJOBC ... ... 11 PM MYJOBW 12 AM MYJOBX
ESP-5.5-EC-01 25
enable the correct substring. Otherwise, HOUR is assigned the value of the ESPSHH variable.
The CHAR variable is assigned the letter to be used based on the scheduled hour. For
example, at 4 AM, CHAR is determined by %LETTERS(4:4), which has the value
D. Job MYJOBD is submitted. Variation
If you want to use the same JCL member for all of the jobs, you can use a MEMBER statement for the job and specify this common member. For example:
JOB MYJOB%CHAR RUN ANY
MEMBER MYJOB ENDJOB
In the MYJOB JCL member, you can use %ESPAPJOB in place of the job name. ESP
Workload Manager substitutes the correct job name at the time of submission. For example:
Scheduling a job in an Application to run based on day and
time
Objective
An Event is scheduled every hour on the hour to run an Application. Job X in the Application should only be selected to run on Fridays at 3 PM.
Solution
Take the following steps:
1. Use the following statements for the job:
JOB X
IF TODAY('FRI') AND ESPSHH = '15' THEN RUN TODAY ENDJOB
2. Schedule an hourly Event to run the Application. For example:
EVENT ID(PROD.HOURLY) SYSTEM(-) REPLACE SCHEDULE 00.00 HOURLY DAILY
INVOKE 'PROD.PROCLIB(CYBER)' ENDDEF
Explanation
Job X is selected to run only if it is Friday and the Event’s scheduled hour (ESPSHH)
ESP-5.5-EC-01 27
Scheduling an ad hoc job to run multiple times
ObjectiveWithin the same generation of an Application, run an ad hoc job every 30 minutes for four hours (in other words, 8 times). The name of the ad hoc job is supplied by a user and may change from one generation of the Application to another.
Solution
One solution is to use a task to dynamically insert the jobs. Take the following steps: 1. Use the following Application:
APPL CYBER
JCLLIB 'CYBER.JCLLIB'
JOB INSERT.JOBS TASK SELFCOMPLETING RUN ANY
TIME='%ESPAHH%ESPAMN%ESPASS' IF ESPREEXEC# LT 8 THEN DO
ESP AJ %USER1..T%TIME INSERT APPL(%ESPAPPL..%ESPAPGEN) REEXEC AT('REALNOW PLUS 30 MINUTES')
ENDDO ENDJOB
2. Set up an Event (for example, PROD.CYBER) to invoke this Application. 3. To run an ad hoc job, trigger the Event and specify the name of the job as the
USER1 parameter. For example:
TRIGGER PROD.CYBER USER1('MYJOB')
Explanation
This solution uses a self-completing task named INSERT.JOBS to insert the ad hoc job every 30 minutes into this Application. A variable called TIME uniquely qualifies the job with a time stamp (actual hours, minutes, and seconds) as it is inserted into the Application.
The Procedure uses the ESPREEXEC# built-in symbolic variable to check the number of re-executions, and does one of the following:
• If ESPREEXEC# is less than 8, the task issues an AJ command to insert another
instance of the job. The task re-executes in 30 minutes.
• Otherwise, the task completes itself automatically.
Note: The AJ command uses the ESPAPPL and ESPAPGEN variables to ensure the correct generation of the correct Application is used.
This example inserts a z/OS job. For an example of inserting a UNIX job at a regular interval, refer to “Scheduling a job to run every two hours” on page 29.
Example
If you pass MYJOB as the USER1 variable and the actual time is 10.32.45, the jobnames are: MYJOB.T103245 MYJOB.T110245 ... MYJOB.T140245 Variation
The AJ command can also be prefixed with ESPNOMSG. For example:
ESPNOMSG AJ %USER1..T%TIME INSERT APPL(%ESPAPPL..%ESPAPGEN)
Using ESPNOMSG suppresses responses from the command (such as a message indicating the job was inserted). Warning and error messages are not suppressed.
ESP-5.5-EC-01 29
Scheduling a job to run every two hours
ObjectiveAn Application is scheduled each workday. Within the Application, a UNIX job needs to run every two hours until 00:30 the next workday.
Solution
Use the following Application:
APPL CYBER
JOB INSERT.JOBS TASK RUN WORKDAYS
TIME='%ESPAHH%ESPAMN%ESPASS'
ESP APPLINS APPL(%ESPAPPL..%ESPAPGEN) STATEMENTS('UNIX_JOB A.T%TIME; AGENT AGENT;
SCRIPTNAME /export/home/jsmith/scripts/a; ENDJOB')
REEXEC AT('REALNOW PLUS 2 HOURS') ENDJOB
JOB STOP.INSERTS LINK PROCESS RUN WORKDAYS
DELAYSUB 00:30 TODAY PLUS 1 WORKDAY
ESP AJ INSERT.JOBS COMPLETE APPL(%ESPAPPL..%ESPAPGEN) ENDJOB
Explanation
This solution uses a task called INSERT.JOBS and a link called STOP.INSERTS. The INSERT.JOBS task does the following:
• Builds a time symbolic variable (%TIME) for the job, consisting of the actual
hour, minute, and second.
• Issues an APPLINS command to dynamically insert job A with a qualifier of
T%TIME into the Application.
• Re-executes in 2 hours.
At 00:30 the next workday, the link issues an AJ command to complete the INSERT.JOBS task.
Note: The ESPAPPL and ESPAPGEN variables are used on the APPLINS and AJ commands. This ensures the correct generation of the correct Application is used. This example inserts a UNIX job. For an example of inserting a z/OS job at a regular interval, refer to “Scheduling an ad hoc job to run multiple times” on page 27.
Scheduling a job to run multiple times within a time range
ObjectiveAn Application is scheduled daily. Within the Application, a UNIX job needs to run every 10 minutes between 10 PM and 2 AM inclusively. The Application contains many jobs with many different frequencies.
Solution
One solution is to use a template in your Application definition. A sample template is shown below:
TEMPLATE MULTIRUN (1,TIME) UNIX_JOB A.%TIME
AGENT AGENT
SCRIPTNAME /export/home/jsmith/scripts/a DELAYSUB 10PM PLUS %TIME MINUTES
RUN ANY ENDJOB ENDTEMPL REXXON DO I=0 TO 240 BY 10 "MULTIRUN "I END REXXOFF Explanation
This solution uses REXX and a template to build all instances of the job when the Application generates. Each instance of the job is qualified with the offset, in minutes, from 10 PM. For example: 0, 10, 20,..., 240.
ESP-5.5-EC-01 31
The code generated through calling the template is shown below:
Note: If the Application contains only the one job that needs to run every 10 minutes within the time range, you can simply schedule the Event every 10 minutes between these times and invoke an Application containing the job to be run.
UNIX_JOB A.0 AGENT AGENT
SCRIPTNAME /export/home/jsmith/scripts/a DELAYSUB 10PM PLUS 0 MINUTES
RUN ANY ENDJOB
UNIX_JOB A.10 AGENT AGENT
SCRIPTNAME /export/home/jsmith/scripts/a DELAYSUB 10PM PLUS 10 MINUTES
RUN ANY ENDJOB . . . UNIX_JOB A.240 AGENT AGENT SCRIPTNAME /export/home/jsmith/scripts/a DELAYSUB 10PM PLUS 240 MINUTES
RUN ANY ENDJOB
Running ad hoc sequential jobs
ObjectiveUsers often request from one to six jobs to run one after the other as a stand-alone Application. Each jobname is 8 characters in length.
Solution
The following is a sample Application that builds a sequence of jobs based on data supplied via a USER1 parameter on an Event trigger.
APPL CYBER JCLLIB 'CYBER.JCLLIB' J1='%USER1(1:8)' J2='%USER1(10:17)' J3='%USER1(19:26)' J4='%USER1(28:35)' J5='%USER1(37:44)' J6='%USER1(46:53)'
IF J1 = '' THEN JUMPTO JDONE JOB %J1
RUN ANY ENDJOB
IF J2 = '' THEN JUMPTO JDONE JOB %J2
RUN ANY AFTER %J1 ENDJOB
IF J3 = '' THEN JUMPTO JDONE JOB %J3
RUN ANY AFTER %J2 ENDJOB
IF J4 = '' THEN JUMPTO JDONE JOB %J4
RUN ANY AFTER %J3 ENDJOB
IF J5 = '' THEN JUMPTO JDONE JOB %J5
RUN ANY AFTER %J4
ESP-5.5-EC-01 33
IF J6 = '' THEN JUMPTO JDONE JOB %J6 RUN ANY AFTER %J5 ENDJOB JDONE: EXIT Explanation
Users can trigger an ad hoc Event and pass a list of 8-character jobnames as the USER1 parameter.
The Procedure parses the USER1 parameter into jobnames, J1 to J6, and builds the Application of sequential jobs. AFTER statements are used to set up relationships between jobs, since the number of jobs to be run varies.
The following shows the generated code and the Application that builds after specifying four jobnames in the USER1 field:
JOB CYBBP01A RUN ANY ENDJOB JOB CYBBP01B RUN ANY AFTER CYBBP01A ENDJOB JOB CYBBP01C RUN ANY AFTER CYBBP01B ENDJOB JOB CYBBP01D RUN ANY AFTER CYBBP01C ENDJOB
CYBBP01A CYBBP01B CYBBP01C CYBBP01D
USER1 Parameter
Job Statements Application
CYBBP01A
CYBBP01B
CYBBP01C
Variation
There are many different ways you can adapt this approach. For example, you could have the user enter the jobnames into a panel or have the user update a data set. Either of these could cause a data set-triggered Event to invoke a Procedure similar to the one shown here.
ESP-5.5-EC-01 35
Dynamically defining and scheduling an Event
ObjectiveJob B needs to run at 9 PM 45 days after job A completes successfully.
Solution
Use a JOBEND job monitor Event for job A to invoke the following Procedure:
IF MNRC NE 0 THEN EXIT
ESPNOMSG EVENT ID(PROD.SUB_B) REPLACE
ESPNOMSG SCHEDULE 9PM TODAY PLUS 45 DAYS ONCE ESPNOMSG SUBMIT 'CYBER.JCLLIB(B)'
ESPNOMSG ENDDEF
Explanation
The job monitor Procedure checks the return code for job A. If the return code is not 0, then the Procedure exits. Otherwise, the Procedure defines a one-time Event to execute at 9 PM 45 days later, which will submit job B.
ONCE is used on the SCHEDULE statement so that the Event will be automatically deleted 24 hours after it has scheduled.
Scheduling a weekly Application based on the number
of workdays in the week
Objective
Schedule an Application to run at 4 PM on the 2nd last workday of each week, unless a week has only one workday. If a week has only one workday, schedule the
Application to run on that workday instead.
Solution
Take the following steps:
1. Use the following Application:
IF TODAY('FRI') THEN DO
ESP TR %ESPEVENT ADD AT('16:00 TODAY PLUS 1 WORKDAY') EXIT ENDDO APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB A RUN ANY ENDJOB
2. Schedule an Event for 4 PM on the 2nd last workday of each week. For example:
EVENT ID(PROD.CYBER) SYSTEM(ESPM) REPLACE
SCHEDULE 16.00 LAST WORKDAY OF EACH WEEK LESS 1 WORKDAY INVOKE 'PROD.PROCLIB(CYBER)'
ESP-5.5-EC-01 37
Explanation
The Event is scheduled for the 2nd last workday of each week. A problem can arise if
a week contains only one workday, which causes the LESS 1 WORKDAY clause to
go back to the Friday of the previous week. This would cause the Application to run twice in one week.
To handle this case, the IF statement in the Application (before the APPL statement) checks to see if today is Friday. In this case, you do not want to generate the
Application. Instead, retrigger the same Event on the following workday, putting it back to the first and only workday of the original week containing the holidays. Example
For example, in the calendar below, if July 20-23 are holidays and July 19 is a workday, then the week of July 19-23 contains only one workday. When the Event schedules on July 15, the last workday of the next week less 1 workday is Friday July 16.
On Friday, July 16, ESP Workload Manager retriggers the Event with the ADD option for the next workday, which will be July 19. The next scheduled occurrence after that will be the last workday of the following week less 1 workday (in other words, July 29).
Running the next scheduled Application early
ObjectiveRun the next day’s version of an Application today.
Solution
As long as you need to replace the next scheduled instance of the Application, you can simply trigger the Event to run the Application and use the REPLACE option. For example, if an Application runs daily at 8 AM, and you want to run Friday’s Application on Thursday afternoon, you can trigger the Event now and use the REPLACE option.
Explanation
ESP Workload Manager automatically selects the jobs and resolves variables based on the “replaced” scheduled date.
Note: If you want to run a future version of the Application other than the next scheduled occurrence, you can use the approach discussed in “Running an Application for any future date” on page 39.
ESP-5.5-EC-01 39
Running an Application for any future date
ObjectiveRun a future version of an Application today.
Solution
Take the following steps:
1. Define another Event that invokes the Application. Schedule the Event for the particular date in the future and use the ONCE keyword on the SCHEDULE statement.
2. Trigger this Event with the REPLACE option.
Explanation
For example, if you want to run an Event today as if it was Oct. 17, 2004, take the following steps:
1. Schedule another Event to invoke the Application and specify SCHEDULE OCT 17, 2004 ONCE.
2. Trigger the Event with the REPLACE option. ESP Workload Manager triggers the Event now and replaces the Oct. 17, 2004 execution.
ESP Workload Manager selects jobs and resolves criteria variables based on the Oct. 17, 2004 date.
The use of ONCE ensures the Event will not be scheduled again after you have triggered it with the REPLACE option. The Event is automatically deleted 24 hours later.
Note: If the future version of the Application is the next scheduled occurrence, you can use the approach discussed in “Running the next scheduled Application early” on page 38.
Delaying job submission until the next hour
ObjectiveWhen a job’s predecessor is complete, the job needs to be delayed until the beginning of the next hour. For example, if job A completes at 10:17 AM then job B should be submitted at 11:00 AM.
Solution
One solution is to use an Application like that shown below:
APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB A RELEASE B RUN DAILY ENDJOB JOB B IF ESPREEXEC#=0 THEN
-REEXEC AT('HOURLY ROUND STARTING REALNOW') RUN DAILY
ENDJOB
Explanation
Often you may need a job in an Application to wait for a particular time before submission. You can use the DELAYSUB statement to specify a delayed submission time, such as DELAYSUB 7PM or DELAYSUB NOW PLUS 30 MINUTES. You can also use the RELDELAY statement to delay submission of a job relative to the time the job’s predecessors are all complete (for example, RELDELAY 30).
In this example, you do not know what time the job’s predecessors will be complete, and so it is not possible to use either a DELAYSUB or a RELDELAY statement. When job B becomes ready, the ESPREEXEC# variable is set to 0. ESP Workload Manager schedules re-execution for the beginning of the next hour. At that time, ESPREEXEC# is 1 and ESP Workload Manager submits the job.
ESP-5.5-EC-01 41
Setting up a dependency with a job’s previous run
ObjectiveAn Application is scheduled each day. One daily job in the Application, job X, needs to wait for its previous run to complete. However, other jobs in the Application can run even if the previous day’s Application is not complete.
The dependencies look like this:
Solution
Take the following steps to set up the Application:
1. Use a variable as a qualifier for job X that is equal to the first 3 characters of the scheduled day of the week.
2. Use GENTIME to generate date and time variables for the previous day. 3. Define the previous run of job X as an external job.
• Use the first 3 characters of the previous day’s day-of-week variable as a
qualifier for the external job.
• Set up this job to release today’s run of job X.
• Use the SCHEDULED parameter on this external job to reflect the previous
day.
• Use the APPLID parameter to specify the name of the Application.
X.TUE X.MON
B A
The following is a sample Application: APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB A RUN DAILY RELEASE B ENDJOB JOB B RUN DAILY RELEASE Y ENDJOB
GENTIME PREV YESTERDAY
JOB X.%PREVDAY(1:3) EXTERNAL SCHEDULED('YESTERDAY') -APPLID(CYBER) RUN DAILY RELEASE X.%ESPSDAY(1:3) ENDJOB JOB X.%ESPSDAY(1:3) RUN DAILY RELEASE Y ENDJOB JOB Y RUN DAILY ENDJOB Explanation
Although there are some WAIT options available at the Application level and job level, they cannot be used here. Application WAIT would cause all jobs to wait for the previous day’s Application to complete; JOB_ANCESTOR_WAIT would cause each job to wait for its previous run to complete. In this scenario, there is only one job that needs to wait.
This solution qualifies job X, and sets up the previous day’s run as an external dependency to today’s run of job X. This does not prevent the other jobs in the Application from running.
Variation
Another approach is to define job X in a subApplication and use the WAIT option on the SUBAPPL statement. This approach is useful if you have a number of jobs, but not all, that need to wait for the previous day’s runs to complete.
For example:
JOB X
ESP-5.5-EC-01 43
Using date-qualified file names
ObjectiveAn Application contains some file trigger jobs where the names of the files being monitored for creation contain a date qualifier and a literal in the form:
MMDDYY_ok. MM is the scheduled month, DD is the scheduled day, and YY is the scheduled year.
Solution
On the FILENAME statement for the file trigger jobs, you can use built-in symbolic variables for the date and concatenate the literal at the end. For example:
FILE_TRIGGER file1 RUN DAILY
FILENAME /batch/interfaces/file1.%ESPSMM%ESPSDD%ESPSYY._ok ENDJOB
Explanation
When the Application generates, it resolves the built-in variables based on the scheduled date of the Event. For example, on November 6, 2005, the above example resolves to the following file name:
/batch/interfaces/file1.110605_ok
Variation
Another approach is to define a symbolic variable representing the date qualified string. You can then use this variable in your job definitions. This is useful when you need to use this file qualifier for many file trigger jobs. Also, if the format of the file name changes, you need only to update the format in one place.
For example, use the following assignment statement:
DATEQUAL=ESPSMM + ESPSDD + ESPSYY + '_ok'
On the FILENAME statement for the file trigger jobs, you can use this variable, as shown below.
FILE_TRIGGER file2 RUN DAILY
FILENAME /batch/interfaces/file2.%DATEQUAL ENDJOB
Processing a changing file name
ObjectiveWhen a file is created, a UNIX script needs to use the file name as input. The last 12 characters of the file name always change and are based on a date and time stamp. An example of such a filename is ‘file092904231456’.
Solution
The following Application shows how to define the file trigger job, CREATE, and the successor job, PROCESS.
APPL CYBER AGENT AGENT
FILE_TRIGGER CREATE RUN DAILY
FILENAME /export/home/jsmith/scripts/file* CREATE RELEASE PROCESS ENDJOB UNIX_JOB PROCESS RUN DAILY SCRIPTNAME /export/home/jsmith/scripts/echoit ARGS %ESPFTFILE ENDJOB Explanation
The built-in variable, ESPFTFILE, is assigned a value of the full file name whenever file trigger activity takes place. You can pass this variable as an argument to the UNIX script run after the file trigger completes.
Note: There is only one ESPFTFILE variable per generation of an Application. When additional file triggers take place in the same generation of the Application, the previous ESPFTFILE variable is overwritten.
ESP-5.5-EC-01 45
Copying a file to another location upon the file’s creation
ObjectiveWhen a file is created, copy the file to another location.
Solution
The following Application shows you how to define a file trigger job, CREATE, to monitor for a file’s creation and a successor job, COPY, to copy the newly created file to another location.
APPL COPYFILE AGENT AGENT
FILE_TRIGGER CREATE RUN DAILY
FILENAME C:\env.txt CREATE RELEASE COPY
ENDJOB NT_JOB COPY RUN DAILY
CMDNAME C:\Windows\system32\cmd.exe
ARGS /C "copy C:\env.txt C:\test\env.txt" ENDJOB
Explanation
When the file is created, ESP Workload Manager completes the CREATE file trigger job and releases the COPY job. The COPY job uses the Windows command
interpreter cmd.exe to copy the file to another location. To pass an argument to
cmd.exe, such as the copy command in this example, enclose the argument in
double quotation marks and precede the argument with the /C switch.
Note: The path to the Windows command interpreter cmd.exe depends on your
Windows operating system version. On Windows NT, the path would be
C:\WINNT\system32\cmd.exe. For the path your Windows operating system
uses, see your Windows administrator.
For more information on running Windows operating-system commands using
cmd.exe, see the CMDNAME statement in the ESP Workload Manager Reference Guide.
Ensuring a file exists before processing
ObjectiveCheck to ensure a file exists before processing it. If the file does not exist, run a script to create it.
The dependencies look like this:
Solution
The following Application shows how to define the different workload objects.
APPL CYBER AGENT AGENT
FILE_TRIGGER CHECK4.FILE CONDITIONAL RUN DAILY
FILENAME /export/home/jsmith/scripts/myfile EXIST RELEASE (CREATE.FILE(A),PROCESS.FILE)
ENDJOB
UNIX_JOB CREATE.FILE CONDITIONAL RUN DAILY SCRIPTNAME /export/home/jsmith/scripts/create.file RELEASE PROCESS.FILE ENDJOB UNIX_JOB PROCESS.FILE RUN DAILY RELCOUNT 1 SCRIPTNAME /export/home/jsmith/scripts/process.file ENDJOB CHECK4.FILE CREATE.FILE PROCESS.FILE
ESP-5.5-EC-01 47
Explanation
This solution uses a file trigger job, CHECK4. FILE, to check for the existence of a file. There are two possible outcomes:
• The file trigger fails. This means the file does not exist. Job CREATE.FILE is
released upon failure to create the file. Once this job completes, job
PROCESS.FILE is released to process the file. At the end of the Application, job CHECK4.FILE is bypassed to enable the Application to complete.
• The file trigger completes successfully. This means the file exists. Job
PROCESS.FILE is released to process the file. At the end of the Application, job CREATE.FILE is bypassed to enable the Application to complete.
Job PROCESS.FILE uses RELCOUNT 1 because it can be run when either CHECK4.FILE or CREATE.FILE are successful.
CHECK4.FILE and CREATE.FILE are conditional jobs. This allows them to be bypassed automatically, if necessary, at the end of the Application.
Bypassing a job based on the status of another job
ObjectiveRun or bypass a job based on whether a particular job is complete in another Application.
Solution
This solution uses a task in the Application to check the completion status of job OTHERJOB in the OTHERAPP Application. If this job is not complete, then job B is bypassed.
APPL CYBER
JCLLIB 'CYBER.JCLLIB'
JOB CHECKJOB TASK SELFCOMPLETING RUN ANY
REXXON PROC
J=JOBONCSF('OTHERJOB','X') IF J > 0 THEN DO
BYPASS='NO'
DO I=1 TO J WHILE BYPASS='NO'
IF XAPPL.I='OTHERAPP' & XCOMPLETE.I=0 THEN DO
BYPASS='YES'
“ESP AJ B BYPASS APPL(CYBER.%ESPAPGEN)” LEAVE END END END REXXOFF RELEASE B ENDJOB JOB B RUN DAILY ENDJOB Explanation
This solution uses a self-completing task named CHECKJOB. This task does the following:
• Uses REXX in Application process mode and the JOBONCSF built-in function
to find all instances of job OTHERJOB.
• If OTHERJOB is found in any generation of the OTHERAPP Application and it
ESP-5.5-EC-01 49
Bypassing non-critical jobs when jobs are late
ObjectiveThere are problems meeting a service level agreement (SLA) and the programmers recommend bypassing some non-critical jobs when a particular Application is behind. For example, if certain jobs in an Application are not complete by 6 AM, then bypass some non-critical jobs.
Solution
Using ESP Workload Manager, this bypass can be automatically “scheduled” by taking the following steps:
1. Define a link (for example, CRITICAL.POINT) as a successor to the important jobs.
2. Specify an overdue DUEOUT EXEC time for this link of 6AM. 3. Identify an Alert to be triggered if the link becomes overdue. 4. Define the Alert.
5. Set up an ESP Procedure invoked by the Alert Event to bypass the non-critical jobs.
6. Define the Alert Event to run the Procedure. Application Description
In the following Application:
• Jobs A and B are important jobs and should be complete by 6 AM
The Application looks like this:
Application Definition
The following is the definition of the Application:
APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB A RUN DAILY RELEASE CRITICAL.POINT ENDJOB JOB B RUN DAILY RELEASE CRITICAL.POINT ENDJOB
JOB CRITICAL.POINT LINK RUN DAILY
NOTIFY OVERDUE ALERT(CRIT) DUEOUT EXEC 6AM
RELEASE (C,D,E) ENDJOB JOB C RUN DAILY RELEASE F ENDJOB JOB D RUN DAILY RELEASE F ENDJOB B A CRITICAL.POINT E C F D
ESP-5.5-EC-01 51 ENDJOB JOB F RUN DAILY ENDJOB Alert Procedure
The following ESP Procedure can be invoked via the Alert Event:
/* BYPASS NON-CRITICAL JOBS IN APPLICATION
ESPNOMSG AJ C BYPASS APPL(%MNAPPL..%MNAPPLGEN) ESPNOMSG AJ E BYPASS APPL(%MNAPPL..%MNAPPLGEN)
Explanation
Jobs A and B are important jobs. Each of these jobs releases a link called
CRITICAL.POINT. If CRITICAL.POINT is not complete by 6 AM, it becomes overdue and an Alert called CRIT triggers. The Alert runs an ESP Procedure that issues ESP AJ commands to bypass jobs C and E.
This solution uses monitor variables for the Application name (%MNAPPL) and for the Application generation number (%MNAPPLGEN) to ensure the jobs are bypassed in the correct generation of the correct Application.
Taking different actions based on 1 of 3 successful return
codes
Objective
A monthly Application is scheduled for 10 AM on the last workday of each month. The first job, job A, can issue a return code of 0, 1, or 2. Different actions are required based on this return code, as described below.
The requirements look like this:
Solution
The following is a sample Application you can schedule at 10 AM on the last workday of each month:
APPL CYBER
JCLLIB 'CYBER.JCLLIB' JOB A
RUN ANYDAY
RELEASE ADD(B) COND(RC(0))
RELEASE ADD(RUNAGAIN) COND(RC(1)) RELEASE ADD(CANCEL) COND(RC(2)) ENDJOB
Return Code for Job A Action
0 Run job B
1 Complete Application and run it again at 10 AM the next workday
2 Cancel this month’s run
Run job B Run again next workday
Cancel this month's run A
ESP-5.5-EC-01 53
JOB RUNAGAIN LINK PROCESS RUN ANYDAY
SEND 'THE PROCEDURE WILL RUN NEXT WORKDAY' U(*) ESP AJ ALL COMPLETE APPL(%ESPAPPL..%ESPAPGEN)
ESP TRIGGER PROD.CYBER ADD AT('10AM TODAY PLUS 1 WORKDAY') ENDJOB
JOB CANCEL LINK PROCESS RUN ANYDAY
SEND 'THE PROCEDURE WILL RUN NEXT MONTH' U(*) ESP AJ ALL COMPLETE APPL(%ESPAPPL..%ESPAPGEN) ENDJOB
Explanation
Job A uses three conditional release expressions to take the appropriate action:
• If job A has a return code of 0, it releases job B.
• If job A has a return code of 1, it releases a link called RUNAGAIN, which
completes the Application and retriggers the Application again at 10 AM the next workday.
• If job A has a return code of 2, it releases a link called CANCEL, which completes
the Application, cancelling this month’s run.
The AJ commands use the ESPAPPL and ESPAPGEN variables to ensure the correct generation of the correct Application is used.
Running different jobs based on the return code of a
predecessor job
Objective
Run job B if job A ends with a return code of 0, and run job C if job A ends with a return code of 1.
The dependencies look like this:
Solution
Use the following Application:
APPL CYBER
JCLLIB 'CYBER.JCLLIB'
JOB A
CCCHK RC(2:4095) FAIL RUN DAILY
RELEASE ADD(B) COND(RC(0)) RELEASE ADD(C) COND(RC(1)) ENDJOB JOB B RUN DAILY ENDJOB JOB C RUN DAILY ENDJOB Explanation
Job A uses two conditional release expressions to release job B on return code 0 and job C on return code 1.
1 0
A
ESP-5.5-EC-01 55
Auto-triggering an Event for a reoccurring job
ObjectiveThe Operations department runs a special stand-alone job upon request. It is always the same job and they do not want an operator to have to trigger an Event to run the job.
Solution
Take the following steps:
1. Set up a one-job Application. Use a schedule frequency of RUN DAILY, and define the special job on hold.
2. Use a TRIGGER command within the scope of the JOB statement to retrigger the Event.
For example:
APPL HELDJOB
JCLLIB 'CYBER.JCLLIB'
JOB SPECIAL HOLD RUN DAILY
ESPNOMSG TRIGGER %ESPEVENT ENDJOB
3. Define an Event without a SCHEDULE statement to invoke this Application. 4. Manually trigger the Event to create the first generation of the Application.
Explanation
Once the first generation of the Application is built, an operator can release job SPECIAL from hold whenever it needs to run. This causes the job to run, and the TRIGGER command retriggers the same Event to build another generation with the job on hold again.
Scheduling a job to run based on its previous run status
ObjectiveSchedule a one-job Application to run every five minutes. If the previous run of the Application is not complete, then do not run the job until its next scheduled run.
Solution
Take the following steps:
1. Use the following Application:
REXXON GEN
X=TRAPOUT('LINE.') "ESPNOMSG LAP CYBER.0" X=TRAPOUT('OFF')
STATUS=SUBWORD(LINE.1,5)
IF LINE.0 \= 0 & STATUS='' THEN "QUIT" IF STATUS='' THEN "QUIT"
REXXOFF APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB A RUN ANY ENDJOB
2. Schedule an Event every 5 minutes to run this Application.
Explanation
This solution uses REXX during Application generation mode to check the status of the current generation (in other words, the last generation that was created). The status of the Application is displayed as the 5th word in the first line of the LAP output.
If this is the first time that the Application runs, there is no output (in other words,
LINE.0=0), and the Application builds to submit job A. Otherwise, the status is
either blank or COMPLETE. If the status is blank, the last generation is not complete and the new generation is not created.
This approach prevents a backlog of Applications when problems arise with the job (for example, if the job fails).
ESP-5.5-EC-01 57
Scheduling a cyclic Application
ObjectiveA group of jobs runs multiple times a day. The first run is at midnight. Once all of the jobs have completed successfully, the next generation should be run 60 minutes later. The last run each day should occur no later than 7 PM.
Solution
Take the following steps:
1. Use the following Application.
APPL CYBER JCLLIB 'CYBER.JCLLIB' JOB A.T%ESPSHH RUN DAILY RELEASE B.T%ESPSHH ENDJOB JOB B.T%ESPSHH RUN DAILY ENDJOB ... APPLEND RETRIG.EVENT RELDELAY 60
IF ESPAHH < '19' AND ESPSDATE=ESPADATE THEN -ESPNOMSG TRIGGER %ESPEVENT ADD
ENDJOB
2. Schedule the following Event to run the Application:
EVENT ID(PROD.CYBER) SYSTEM(-) REPLACE SCHEDULE 00.00 DAILY
INVOKE 'PROD.PROCLIB(CYBER)' ENDDEF
Explanation
The Event is scheduled at midnight each day to run the first group of jobs. The Application uses a time-based qualifier to distinguish each group of jobs for ease of monitoring.
An APPLEND object, called RETRIG.EVENT, waits for all jobs in the Application to complete successfully before it retriggers the Event. It is automatically a successor to all jobs in the Application that do not have any successors. This allows you to add jobs to the Application without defining those jobs as predecessors to the object that will bring in the next generation.
After all of the jobs have completed successfully, the RETRIG.EVENT object waits 60 minutes (RELDELAY 60) before it becomes ready. It then checks the actual time and if the time is before 7 PM on the same day, it re-triggers the original Event. The TRIGGER command with the ADD option is used so that the regular daily
ESP-5.5-EC-01 59
Incrementing a cycle number
ObjectiveWhen an Application processes, it uses a four-digit cycle number. This cycle number is used as part of the data set names for two data set trigger jobs, and extensively in JCL for jobs that run after the data set triggers complete. The cycle number increments each time the Application runs, and it ranges from “0001” to “9999”. The Application waits for two data sets to be created: BUS.BCnumber and RES.BCnumber, where number represents the cycle number.
Solution
Take the following steps:
1. The cycle number is passed to the Event using a User Parameter. Use the following code to assign the value of the User Parameter to a variable called THIS_CYCLE.
THIS_CYCLE=USER1
2. Define the two data set trigger jobs. Use %THIS_CYCLE as part of the data set names for these jobs. For example: BUS.BC%THIS_CYCLE and
RES.BC%THIS_CYCLE.
3. Use a link at the end of the Application to increment the cycle number and trigger the next occurrence of the Event with the USER1 parameter as the new cycle number.
Application
The following is a sample Application definition:
APPL CYBER JCLLIB 'CYBER.JCLLIB' THIS_CYCLE=USER1 DSTRIG BUS RUN ANY DSNAME BUS.BC%THIS_CYCLE RELEASE A ENDJOB DSTRIG RES RUN ANY DSNAME RES.BC%THIS_CYCLE RELEASE A ENDJOB JOB A RUN ANY RELEASE Z ENDJOB JOB Z RUN ANY RELEASE CHANGE.CYCLE ENDJOB
JOB CHANGE.CYCLE LINK PROCESS RUN DAILY
/* INCREMENT 4-DIGIT CYCLE NUMBER AND RESET TO 1 AFTER 9999 INTEGER CYCLE
CYCLE=THIS_CYCLE
IF CYCLE=9999 THEN CYCLE=1 ELSE CYCLE=CYCLE+1
NEW_CYCLE='%CYCLE(F4)'
ESPNOMSG TRIGGER %ESPEVENT USER1('%NEW_CYCLE') ENDJOB
ESP-5.5-EC-01 61
The flow looks like this:
You will need to trigger this Event manually the first time and pass the four-digit cycle number. After that, each new generation of the Application will be automatically triggered when one generation completes.
Explanation
When the Application is generated, ESP Workload Manager assigns the cycle number, which is passed as the USER1 parameter, to a variable called THIS_CYCLE. The data set trigger jobs wait for the latest cycle of the BUS.BC and RES.BC data sets.
The CHANGE.CYCLE link at the end of the Application takes the current cycle number, adds 1, and pads the result with leading zeroes, as necessary. After cycle “9999”, the cycle is reset to “0001”. The link retriggers the Event and passes this new cycle number in the USER1 field. This enables the new cycle number to be used in the next generation of the Application.
Z A
CHANGE.CYCLE
File=RES.BC1234 File=BUS.BC1234
Building Applications dynamically based on an input file
ObjectiveAn Application needs to be built dynamically based on an input file supplied by a user. The input file contains a list of jobnames with one jobname per line.
Solution
Use the following Application: