Can we write a job so as to attach a date to a file name? For example, suppose file name is AAA.BBB.CCC and it gets generated everyday so can we name the file as AAA.BBB.CCC.DDMMYY so that DDMMYY will change according to run date?
I tried by passing a PARM, but am not being sure where to put values for the PARM, or how the JCL can pick up the current date.
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
Abhash, think about what you're doing for a moment.
When a job is submitted, before it ever executes on the JES Internal Reader, any variables you specify must be resolved into their designated values. This means that the values any variables you use MUST be known to the job BEFORE it is ever allowed to start execution.
In your case, you assigned the value 'CYYMMDD' to the variable 'DATE', so that is its value. You need to assign the actual value, i.e. 'DATE='C070110' before the job is submitted. One easy way to do this is with the SET statement, such as this:
Code:
// JCLLIB ORDER=(APG.INFY.DATE.PARM)
// SET DATE='C070110'
//STEP1 EXEC DATEPARM
or by using an INCLUDE statement:
Code:
PDS 'MY.PROD.PARMLIB' member 'CURRDATE' contains one record with the value:
// SET DATE='C070110'
// JCLLIB ORDER=(APG.INFY.DATE.PARM,MY.PROD.PARMLIB)
// INCLUDE CURRDATE
//STEP1 EXEC DATEPARM
You can use the EZACFSM1 System Symbolic Variable Resolution utility to output the current system date to an output DD:
Section 3. Using a program to create and submit the JCL.
/* REXX to capture the current date and save it in an INCLUDE group */
Drop jcl. /* clear STEM */
jcl.0 = 1 /* plug in record count. */
jcl.1 = "// SET DATE="D20||DATE('J') /* create SET statement */
jcl.1 = LEFT(jcl.1,80) /* Pad to 80 bytes, and */
"EXECIO 1 DISKW DATEDD (FINIS STEM jcl." /* Output to library */
Exit 0 /* quit with COND CODE = 0 */
Time stamp method
This solution could be used when multiple versions of a data set are to be created through out the day, and both date and time are to form part of the data set name. It requires two steps, the first creates the data set, and the second renames the data set replacing a particular node with the date and time. The issue not dealt with directly here is one of co-ordination to ensure that two jobs do not attempt to create data sets with the same time stamp. If an installation runs with the standard JES2 default of NOT allowing concurrent execution of jobs with duplicate names, it provides some assistance.
Sample REXX Routine to rename the data set
/* REXX to rename a data set to include current date as part of the
data set name. */
Parse Arg odsn onode /* Obtain parameters
odsn = existing dsn
onode = date location */
tod = TIME('N') /* Get Time of Day */
Parse var tod hh ':' mm ':' ss /* Remove the semi-colons */
lnode = LENGTH(onode) /* Get length of node */
lodsn = LENGTH(odsn) /* Get length of dsname */
start = POS(onode,odsn) /* Find onode */
more = POS('.',odsn,start) /* Anything after onode */
ndsn = SUBSTR(odsn,1,start-1)||'D20'||DATE('J')||'.T'||hh||mm||ss
If more > 0 Then ndsn = ndsn||SUBSTR(odsn,more)
x = MSG('OFF') /* Suppress messages */
"RENAME '"odsn"' '"ndsn"' " /* Rename the data set */
If rc ?= 0 Then Do /* Check for success */
Say "Rename Error"
Exit rc
End
Exit 0 /* quit with COND CODE = 0 */
//*
/*JOBPARM ROOM=SOP,LINES=9999
//*
//STEP0001 EXEC PGM=IEFBR14
##DD1
// DISP=(,CATLG,DELETE),UNIT=SYSDA,SPACE=(CYL,(1,1)),
// RECFM=FB,LRECL=80
//*
//STEP0002 EXEC PGM=IEBGENER
//SYSUT1 DD DATA
TEST RECORD 01 OF 10
TEST RECORD 02 OF 10
TEST RECORD 03 OF 10
TEST RECORD 04 OF 10
TEST RECORD 05 OF 10
TEST RECORD 06 OF 10
TEST RECORD 07 OF 10
TEST RECORD 08 OF 10
TEST RECORD 09 OF 10
TEST RECORD 10 OF 10
/*
##SYSUT2
// DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSIN DD DUMMY
//*
Next, I created the JCL that follows. I am using DFSORT to:
first, generate a sequential number for each record so that they can be kept in order.
then, I separate the JCL into two datasets - one with everything minus the ## records, and one with just the ## records, with the ## replaced by //, the data 'DD DSN=', and a dataset, with the SORT function DATE3 supplying the current Julian date.
lastly, the two sets of JCL are concatenated back together, using the sequence numbers to retain the proper order, with the resulting concatenated file going to the Internal Reader for submission. I'm sure it could use some tweaking here and there, but here goes nothing:
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
A different approach might be to consider creating a generation data set. It would not have the current date in the dsn, but WOULD allow for multiple runs in the same day with no penalty.
Let's suppose "this" job runs every night at 21:30. Now let's suppose that something happens that it cannot run until 03:45 the next morning. By the time 21:30 comes around the next night, the file for that day will already exist and have to be dealt with.