OUTFIL: Selecting and sampling by RRN
OUTFIL: Selecting and sampling by RRN
Summary
- OUTFIL statement is used to copy, sort or merge input records by using RRN.
- RRN stands for relative record number.
- When performing copy, sort or merge operations, the resulting records have implicit relative record.
- The implicit relative record numbers are starting from 1 for the first record and n for the last record (n is the total number of records).
Syntax -
SORT FILEDS=(Starting position, length, data-format, A/D)
OUTFIL FNAMES=DDNAMEn, STARTREC=starting RRN, ENDREC= Ending RRN
DDNAMEn | DDNAME is eight character’s name that representing the actual dataset in JCL. |
STARTREC=starting RRN | Specifies the starting record RRN from where the copy starts |
ENDREC=Ending RRN | Specifies the ending record RRN where the copy ends |
Example -
Scenario -
Create three output files like below -
- 1,4,7,10 records to file1
- 4,8 records to file2
- 2,3,5,6,8,9 records to file3
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
00003 student3 dept2 520
00004 student4 dept1 540
00005 student5 dept2 500
00002 student2 dept3 510
00006 student6 dept3 550
00008 student8 dept1 530
00007 student7 dept3 510
00009 student9 dept2 520
00010 student10 dept2 505
******************************** Bottom of Data ********************************
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- ***************************** Top of Data ****************************** //Job-card //* //********************************************************************** //* //STEP01 EXEC PGM=SORT //SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR //OUTPUT1 DD DSN=MTHUSER.SORT.OUTPT01, // SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN, // DISP=(NEW,CATLG,DELETE) //OUTPUT2 DD DSN=MTHUSER.SORT.OUTPT02, // SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN, // DISP=(NEW,CATLG,DELETE) //OUTPUT3 DD DSN=MTHUSER.SORT.OUTPT03, // SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN, // DISP=(NEW,CATLG,DELETE) //SYSOUT DD SYSOUT=* //SYSIN DD * SORT FIELDS=(1,5,ZD,A) OUTFIL FNAMES=OUTPUT1,SAMPLE=3 OUTFIL FNAMES=OUTPUT2,STARTREC=4,SAMPLE=4,ENDREC=10 OUTFIL FNAMES=OUTPUT3,STARTREC=2,SAMPLE=(3,2) /* **************************** Bottom of Data ****************************Output File1 - MTHUSER.SORT.OUTPT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00001 student1 dept1 560
00004 student4 dept1 540
00007 student7 dept3 510
00010 student10 dept2 505
******************************** Bottom of Data ********************************
Output File2 - MTHUSER.SORT.OUTPT02 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00004 student4 dept1 540
00008 student8 dept1 530
******************************** Bottom of Data ********************************
Output File3 - MTHUSER.SORT.OUTPT03 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00002 student2 dept3 510
00003 student3 dept2 520
00005 student5 dept2 500
00006 student6 dept3 550
00008 student8 dept1 530
00009 student9 dept2 520
******************************** Bottom of Data ********************************
Explaining Example -
- SORT FIELDS=(1,5,ZD,A) - sort all outputs in ascending order based on the ZD value from 1 to 5 positions.
- OUTFIL FNAMES=OUTPUT1,SAMPLE=3 - Copies 1st record and picked up every third record from the current record. The output1 file contains 1, 4,7,10 records.
- OUTFIL FNAMES=OUTPUT2,STARTREC=4,SAMPLE=4,ENDREC=10 - Copy starts from 4th record and picked up every fourth record from the current record. The output2 file contains 4,8 records.
- OUTFIL FNAMES=OUTPUT3,STARTREC=2,SAMPLE=(3,2) - Copy starts from 2nd record and ignores every third record after copying two records along with current record. The output3 file contains 2,3,5,6,8,9 records.