OUTFIL: Repeating


  • OUTFIL can be used to repeat the records for specific times.
  • REPEAT keyword is used to specify the repeat the records.
  • OUTFIL's REPEAT=n parameter repeat each output record n times.
  • If the BUILD, OUTREC, OVERLAY, or IFTHEN parameters specified with a sequencenumber, the sequence numbers are incremented for each repeated record.
  • If no BUILD, OUTREC, OVERLAY, or IFTHEN parameters specified with a sequencenumber, the repeated records are identical as specified.

Syntax -


OPTION COPY
INCLUDE/OMIT COND=(……)
OUTFIL FNAMES=DDNAME1, REPEAT=n, BUILD=(..)/OUTREC=(..)
OUTFIL FNAMES=DDNAME2,REPEAT=n, BUILD=(..)/OUTREC=(..)
…..
OUTFIL FNAMES=DDNAMEn,REPEAT=n, BUILD=(..)/OUTREC=(..)
DDNAMEnDDNAME is eight character’s name that representing the actual dataset in JCL.
REPEAT=nSpecifies the number of times the records needs to repeated

Example -


Scenario -

Create three output files like below.

  • Repeat dept1 records 1 time, move to file1 and add 1 digit sequence number from 60th byte starting from 1 and increment by 1.
  • Repeat dept2 records 2 times, move to file2 and add 2 digit sequence number from 60th byte starting from 2 and increment by 2.
  • Repeat dept3 records 3 times, move to file3 file2 and add 3 digit sequence number from 60th byte starting from 2 and increment by 3.

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,INCLUDE=(30,5,CH,EQ,C'dept1'),               
     BUILD=(1,59,X,SEQNUM,1,ZD,START=1,INCR=1)                          
                                                                        
     OUTFIL FNAMES=OUTPUT2,REPEAT=2,INCLUDE=(30,5,CH,EQ,C'dept2'),      
     BUILD=(1,59,X,SEQNUM,2,ZD,START=1,INCR=2)                          
                                                                        
     OUTFIL FNAMES=OUTPUT3,REPEAT=3,INCLUDE=(30,5,CH,EQ,C'dept3'),      
     BUILD=(1,59,X,SEQNUM,3,ZD,START=1,INCR=3)                          
/*                                                                      
**************************** 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             1                   
00004     student4           dept1          540             2                   
00008     student8           dept1          530             3                   
******************************** Bottom of Data ********************************

Output File2 - MTHUSER.SORT.OUTPT02 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00003     student3           dept2          520             01                  
00003     student3           dept2          520             03                  
00005     student5           dept2          500             05                  
00005     student5           dept2          500             07                  
00009     student9           dept2          520             09                  
00009     student9           dept2          520             11                  
00010     student10          dept2          505             13                  
00010     student10          dept2          505             15                  
******************************** 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             001                 
00002     student2           dept3          510             004                 
00002     student2           dept3          510             007                 
00006     student6           dept3          550             010                 
00006     student6           dept3          550             013                 
00006     student6           dept3          550             016                 
00007     student7           dept3          510             019                 
00007     student7           dept3          510             022                 
00007     student7           dept3          510             025                 
******************************** Bottom of Data ********************************

Explaining Example -

  1. SORT FIELDS=(1,5,ZD,A) - sort all outputs in ascending order based on the ZD value from 1 to 5 positions.
  2. OUTFIL FNAMES=OUTPUT1,INCLUDE=(30,5,CH,EQ,C'dept1') - All the records marching with "dept1" from the 30th position of length 5 will be copied to output1 file.
  3. OUTFIL FNAMES=OUTPUT1,.., BUILD=(1,59,...) - Copies 1 to 59 bytes data from input file to output file1 as it is (which satisfies the above condition).
  4. OUTFIL FNAMES=OUTPUT1,.., BUILD=(1,59,X,..) - Add space to the 60th byte.
  5. OUTFIL FNAMES=OUTPUT1,.., BUILD=(..,SEQNUM,1,ZD,START=1,INCR=1) - generates the sequence number in OUTPUT1 file starts with 1 and increments by 1 every time from 61st byte of length one byte.
  6. OUTFIL FNAMES=OUTPUT2,INCLUDE=(30,5,CH,EQ,C'dept2') - All the records marching with "dept2" from the 30th position of length 5 will be copied to output2 file.
  7. OUTFIL FNAMES=OUTPUT2,.., BUILD=(1,59,...) - Copies 1 to 59 bytes data from input file to output2 file as it is (which satisfies the above condition).
  8. OUTFIL FNAMES=OUTPUT2,.., BUILD=(1,59,X,..) - Add space to the 60th byte.
  9. OUTFIL FNAMES=OUTPUT2,.., BUILD=(..,SEQNUM,2,ZD,START=1,INCR=2) - generates the sequence number in OUTPUT2 file starts with 1 and increments by 2 every time from 61st byte of length 2 bytes.
  10. OUTFIL FNAMES=OUTPUT3,INCLUDE=(30,5,CH,EQ,C'dept3') - All the records marching with "dept3" from the 30th position of length 5 will be copied to output3 file.
  11. OUTFIL FNAMES=OUTPUT3,.., BUILD=(1,59,...) - Copies 1 to 59 bytes data from input file to output3 file as it is (which satisfies the above condition).
  12. OUTFIL FNAMES=OUTPUT3,.., BUILD=(1,59,X,..) - Add space to the 60th byte.
  13. OUTFIL FNAMES=OUTPUT3,.., BUILD=(..,SEQNUM,3,ZD,START=1,INCR=3) - generates the sequence number in OUTPUT2 file starts with 1 and increments by 3 every time from 61st byte of length 3 bytes.