DFSORT OUTFIL Splitting

DFSORT OUTFIL: Repeating DFSORT OUTFIL: Creating Reports

Advertisements


OUTFIL can be used to split the dataset with a specific number of records.

SPLIT key word used to split the dataset.

If SPLIT is used and there are two OUTFIL datasets, the SORT will distribute first record to OUTFIL dataset1 and second record to OUTFIL dataset2 and third to OUTFIL dataset1 and so on until the end of the records.

If SPLIT=n used and two OUTFIL files, then n records will be distributed from first OUTFIL dataset, the next n records to OUTFIL dataset2, the next n records to OUTFIL file1 and so on until the end of the records.

If the number of files changed, then the process will adjust accordingly.

SPLIT splits the records one ata time among the data sets specified by FNAMES.


Syntax:

OPTION COPY
OUTFIL FNAMES=(DDNAME1, DDNAME2,….,DDNAMEn), SPLIT=n

Name Description
DDNAMEnDDNAME is eight character’s name that representing the actual dataset in JCL.
SPLIT=nSpecifies the number of records that the file needs to split with.

In SPLIT=n, n is optional.

If n is not specified, the file split up can be done record by record.

If n is specified, the file split up can be done n records by n records.


Example: -

Create three output files by splitting 4 records each.


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,OUTPUT2,OUTPUT3),SPLITBY=4                  
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                                 
00002     student2           dept3          510                                 
00003     student3           dept2          520                                 
00004     student4           dept1          540                                 
******************************** Bottom of Data ********************************

File: MTHUSER.SORT.OUTPT02 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00005     student5           dept2          500                                 
00006     student6           dept3          550                                 
00007     student7           dept3          510                                 
00008     student8           dept1          530                                 
******************************** Bottom of Data ********************************

File: MTHUSER.SORT.OUTPT03 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00009     student9           dept2          520                                 
00010     student10          dept2          505                                 
******************************** 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,OUTPUT2,OUTPUT3),SPLITBY=4 - Splits the records by 4. First 4 records to output1 file, next 4 records to Output2 file and next 4 to output3 file.

  3. If any more records than 12, then the above process will occur again and again until it reaches to file end.

DFSORT OUTFIL: Repeating DFSORT OUTFIL: Creating Reports

Advertisements