问题
I have a request similar to the "JCL for previous month-year in dataset name" question. The answer to that question used an ALTER statement, which assumes knowledge of the date. I have JCL to append the year to the DSN, however in January, I need the previous year. I think this is possible with the help of SYNCSORT or DFSORT, but am not experienced with either of these. Any assistance is appreciated.
Here is the current JCL:
//B999999X JOB (80594,XXX),'MAKE DATE',
// CLASS=C,MSGCLASS=C,NOTIFY=&SYSUID
//STEP0100 EXEC PGM=EZACFSM1
//SYSOUT DD SYSOUT=(*,INTRDR)
//SYSIN DD DATA,DLM=@@
//B8025501 JOB (,9999),'TESTING',
// CLASS=A,MSGCLASS=C,MSGLEVEL=(1,1),NOTIFY=&SYSUID
//STEP01 EXEC PGM=IEFBR14
//FILE01 DD DSN=B999999.TEST.MYFILE.FUEL&YR2,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(10,10),RLSE),
// DCB=(LRECL=80,RECFM=FB,BLKSIZE=0)
/*
@@
回答1:
Actually, the answer to the question you reference first states "The best solution for this is to use the features of your job scheduler." That remains the best answer. That I showed how something could be done was not intended to imply I thought it was the best or most maintainable method.
You could do this with Rexx, or a Unix System Services shell script, or an awk script, or Perl, again constructing an ALTER statement to be used in a subsequent step to rename a statically-named dataset to one containing the date qualifier you desire.
There are some other techniques here.
But, if you have a job scheduler package available, you really should be using its capabilities.
Examples of the above proposed solutions follow.
Rexx program MKALTR
dsn = Arg(1)
Parse Value Date('O') With yy '/' mm '/' dd
If mm = 1 Then
If yy > 0 Then
yy = yy - 1
Else
yy = 99
outLine.1 = ' ALTER ' || dsn || ' - '
outLine.2 = ' NEWNAME(' || dsn || yy || ')'
outLine.0 = 2
Address TSO 'EXECIO * DISKW OUTPUT01 ( STEM' outLine. 'FINIS )'
Exit
JCL to run Rexx program MKALTR
//*
// SET &DS=MY.DATASET.NAME
//*
//CATLG EXEC PGM=IEFBR14
//STDOUT DD DISP=(,CATLG),
// DSN=&DS,
// AVGREC=U,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(1,1))
//*
//MKALTER EXEC PGM=IKJEFT1B,PARM='MKALTR &DS'
//SYSEXEC DD DISP=SHR,DSN=dataset.where.rexx.code.resides
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSTSIN DD DUMMY
//OUTPUT01 DD DISP=(,PASS),
// AVGREC=K,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(2,1))
//*
//DOALTER EXEC PGM=IDCAMS
//SYSIN DD DISP=(OLD,DELETE),DSN=*.MKALTER.OUTPUT01
//SYSPRINT DD SYSOUT=*
//*
Shell script mkaltr
let "mon=`date +'%m'`"
let "yr=`date +'%y'`"
if [ $mon -eq 01 ]
then
let "outyr=$yr-1"
fi
echo \ ALTER $1 -
echo \ \ NEWNAME\($1$outyr\)
JCL to run shell script mkaltr
//*
// SET &DS=MY.DATASET.NAME
//*
//CATLG EXEC PGM=IEFBR14
//STDOUT DD DISP=(,CATLG),
// DSN=&DS,
// AVGREC=U,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(1,1))
//*
//MKALTER EXEC PGM=BPXBATCH,
// PARM='SH /path/to/script/mkaltr &DS'
//STDOUT DD DISP=(,PASS),
// AVGREC=U,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(2,1))
//STDERR DD SYSOUT=*
//*
//DOALTER EXEC PGM=IDCAMS
//SYSIN DD DISP=(OLD,DELETE),DSN=*.MKALTER.STDOUT
//SYSPRINT DD SYSOUT=*
//*
Shell script mkaltr using awk
date +"$1 %m %y" | awk '
{
yr = $3
if ( $2 = 1 ) yr -= 1
if ( yr > 100 ) yr -= 100
printf( " ALTER %s -\n NEWNAME(%s%2d)\n", $1, $1, yr )
}'
JCL to run shell script mkaltr
//*
// SET &DS=MY.DATASET.NAME
//*
//CATLG EXEC PGM=IEFBR14
//STDOUT DD DISP=(,CATLG),
// DSN=&DS,
// AVGREC=U,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(1,1))
//*
//MKALTER EXEC PGM=BPXBATCH,
// PARM='SH /path/to/script/mkaltr &DS'
//STDOUT DD DISP=(,PASS),
// AVGREC=U,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(2,1))
//STDERR DD SYSOUT=*
//*
//DOALTER EXEC PGM=IDCAMS
//SYSIN DD DISP=(OLD,DELETE),DSN=*.MKALTER.STDOUT
//SYSPRINT DD SYSOUT=*
//*
Perl program mkaltr
if ( @ARGV ) {
$dsn = shift( @ARGV );
} else {
die "dataset name required";
}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($mon == 0) {
$year -= 1
}
if ($year >= 100) {
$year -= 100;
}
printf (" ALTER %s -\n NEWNAME(%s%2d)\n", $dsn, $dsn, $year);
JCL to run Perl program mkaltr
//*
// SET &DS=MY.DATASET.NAME
//*
//CATLG EXEC PGM=IEFBR14
//STDOUT DD DISP=(,CATLG),
// DSN=&DS,
// AVGREC=U,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(1,1))
//*
//MKALTER EXEC PGM=BPXBATCH,
// PARM='SH perl /path/to/perl/program/mkaltr &DS'
//STDOUT DD DISP=(,PASS),
// AVGREC=U,
// LRECL=80,
// RECFM=FB,
// SPACE=(80,(2,1))
//STDERR DD SYSOUT=*
//*
//DOALTER EXEC PGM=IDCAMS
//SYSIN DD DISP=(OLD,DELETE),DSN=*.MKALTER.STDOUT
//SYSPRINT DD SYSOUT=*
//*
来源:https://stackoverflow.com/questions/13996444/incude-the-year-from-last-months-date-in-the-dsn-using-jcl