OUTREC Arithmetic Operations on Date
OUTREC Arithmetic Operations on Date Example
Scenario - Add two days, two years to the date in the input file. Change the date format to YYYY/DDD.
Input File - MATEPK.SORT.INPUT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 00001 student1 dept1 560 01012015 00003 student3 dept2 520 03032015 00004 student4 dept1 540 06022015 00005 student5 dept2 500 09202015 00002 student2 dept3 510 05182015
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//MATEPKD JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MATEPK.SORT.INPUT01,DISP=SHR
//SORTOUT DD DSN=MATEPK.MERGE.OUTPUT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(1,4),RLSE),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTREC FIELDS=(1,54,55,8,Y4W,ADDDAYS,+2,TOJUL=Y4T(/),
5X,55,8,Y4W,ADDYEARS,+2,TOJUL=Y4T(/))
/*
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 00001 student1 dept1 560 2015/003 2017/001 00002 student2 dept3 510 2015/140 2017/138 00003 student3 dept2 520 2015/064 2017/062 00004 student4 dept1 540 2015/155 2017/153 00005 student5 dept2 500 2015/265 2017/263
Explaining Example -
- OUTREC FIELDS=(1,54,..) copies the first 54 bytes from the input file to output as it is.
- OUTREC FIELDS=(..,55,8,Y4W,ADDDAYS,+2,TOJUL=Y4T(/),..) – adds +2 days to the date in the input file and converts it to Julian date before writing it to output file from 55th position.
- OUTREC FIELDS=(..,5X,..) - adds 5 spaces from 63rd position
- OUTREC FIELDS=(..,55,8,Y4W,ADDYEARS,+2,TOJUL=Y4T(/)) - adds +2 years to the date in the input file and converts it to Julian date before writing it to output file from 68th position.