OUTREC: Date Operations
OUTREC: Date Operations
Summary
Converting date -
OUTREC statement can be used for converting date formats of a date field while sorting.
Syntax -
OUTREC BUILD=(Starting position of field1, Length of field1,
existing date field1 format(Y2X/Y4X),
Conversion operator=Target date field1 formats(Y2X/Y4X),….. )
Starting position of field1 | Specifies field1 starting position in the input file after sorting. |
Length of feild1 | Field1 physical length in input file. |
Existing date field1 format | Specifies source n-digit year date field formats.
|
Conversion operator | Specifies the keyword for target format operator.
The below are the list of format operators -
|
Target date field1 formats | Specifies the target n-digit year date field formats. |
Example -
Scenario - Convert the date from mmddccyy to ccyymmm(juliyan date). New ouput layout would be
01 OUTPUT-REC.
05 STD-ID PIC X(05).
05 FILLER PIC X(05).
05 STD-NAME PIC X(15).
05 FILLER PIC X(05).
05 STD-DEPT PIC X(10).
05 FILLER PIC X(05).
05 STD-MARKS PIC 9(03).
05 FILLER PIC X(07).
05 STD-JDATE PIC X(07).
05 FILLER PIC X(18).
Input File - MTHUSER.SORT.INPUT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
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
******************************** Bottom of Data ********************************
Input Record Layout -
01 INPUT-REC.
05 STD-ID PIC X(05).
05 FILLER PIC X(05).
05 STD-NAME PIC X(15).
05 FILLER PIC X(05).
05 STD-DEPT PIC X(10).
05 FILLER PIC X(05).
05 STD-MARKS PIC 9(03).
05 FILLER PIC X(07).
05 STD-DATE PIC X(08).
05 FILLER PIC X(17).
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card
//*
//**********************************************************************
//*
//* SORT FOR OUTREC STATEMENT
//*
//**********************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTREC FIELDS=(1,54,55,8,Y4W,TOJUL=Y4T)
/*
**************************** Bottom of Data ****************************
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
00001 student1 dept1 560 2015001
00002 student2 dept3 510 2015138
00003 student3 dept2 520 2015062
00004 student4 dept1 540 2015153
00005 student5 dept2 500 2015263
******************************** BOTTOM OF DATA ********************************
Explaining Example -
- OUTREC FIELDS=(1,54,..) copies first 54 bytes of input file data to output as it is.
- OUTREC FIELDS=(..,55,8,Y4W,TOJUL=Y4T)- data from 55th byte of length 8 will be converted to Y4T Julian date format.
Input date 01012015 will be converted as 2015001.
Arithmetic operations on date -
OUTREC statement can be used for arithmetic data operations on the date field while sorting.
Syntax -
OUTREC BUILD=(Starting position of field1, Length of field1,
existing date field1 format(Y2X/Y4X), Arithmetic operator, +n/-n,…)
Starting position of field1 | Specifies field1 starting position in the input file after sorting. |
Length of feild1 | Field1 physical length in input file. |
Existing date field1 format | Specifies source n-digit year date field formats.
|
Arithmetic operator | Arithmetic operation to perform
The below are list of Arithmetic operations used -
|
+n/-n | Specifies the number days/months/years used to perform an arithmetic operation |
Example -
Scenario - Add two days, two years to the date in the input file. The new output record layout should be
01 OUTPUT-REC.
05 STD-ID PIC X(05).
05 FILLER PIC X(05).
05 STD-NAME PIC X(15).
05 FILLER PIC X(04).
05 STD-DEPT PIC X(10).
05 FILLER PIC X(05).
05 STD-MARKS PIC 9(03).
05 FILLER PIC X(07).
05 STD-DATE PIC X(08).
05 FILLER PIC X(05).
05 STD-DATE PIC X(08).
05 FILLER PIC X(05).
Input File - MTHUSER.SORT.INPUT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
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
******************************** Bottom of Data ********************************
Input Record Layout -
01 INPUT-REC.
05 STD-ID PIC X(05).
05 FILLER PIC X(05).
05 STD-NAME PIC X(15).
05 FILLER PIC X(04).
05 STD-DEPT PIC X(10).
05 FILLER PIC X(05).
05 STD-MARKS PIC 9(03).
05 FILLER PIC X(07).
05 STD-DATE PIC X(08).
05 FILLER PIC X(17).
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card
//*
//**********************************************************************
//*
//* SORT FOR OUTREC STATEMENT
//*
//**********************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR
//SORTOUT DD SYSOUT=*
//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(/))
/*
**************************** Bottom of Data ****************************
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
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
******************************** BOTTOM OF DATA ********************************
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.