DFSORT OUTFIL Repeating

DFSORT OUTFIL: Reformatting DFSORT OUTFIL: Splitting

Advertisements


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=(..)

Name Description
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: -

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 ********************************

Job:

000100 //Jobcard 
000400 //*                                                                     
000500 //**********************************************************************
000600 //*                                                                     
001100 //STEP01   EXEC PGM=SORT                                  
001300 //SORTIN   DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR      
001800 //OUTPUT1  DD DSN=MTHUSER.SORT.OUTPT01,              
001810 //             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,       
001820 //             DISP=(NEW,CATLG,DELETE)                    
001900 //OUTPUT2  DD DSN=MTHUSER.SORT.OUTPT02,              
002000 //             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,       
002100 //             DISP=(NEW,CATLG,DELETE)                    
002200 //OUTPUT3  DD DSN=MTHUSER.SORT.OUTPT03,              
002300 //             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,       
002310 //             DISP=(NEW,CATLG,DELETE)                    
002400 //SYSOUT   DD SYSOUT=*                                    
002410 //SYSIN    DD *                                                         
002411      SORT FIELDS=(1,5,ZD,A)                                             
002420      OUTFIL FNAMES=OUTPUT1,INCLUDE=(30,5,CH,EQ,C'dept1'),               
002421      BUILD=(1,59,X,SEQNUM,1,ZD,START=1,INCR=1)                          
002430                                                                         
002431      OUTFIL FNAMES=OUTPUT2,REPEAT=2,INCLUDE=(30,5,CH,EQ,C'dept2'),      
002432      BUILD=(1,59,X,SEQNUM,2,ZD,START=1,INCR=2)                          
002440                                                                         
002450      OUTFIL FNAMES=OUTPUT3,REPEAT=3,INCLUDE=(30,5,CH,EQ,C'dept3'),      
002460      BUILD=(1,59,X,SEQNUM,3,ZD,START=1,INCR=3)                          
003500 /*                                                                      
****** **************************** Bottom of Data ****************************

Output File: 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 ********************************

File: 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 ********************************

File: 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 Solution:

  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.

DFSORT OUTFIL: Reformatting DFSORT OUTFIL: Splitting

Advertisements