DFSORT OUTFIL Saving discards

DFSORT OUTFIL: Including, omitting Records DFSORT OUTFIL: Reformatting

Advertisements


OUTFIL used to save the discards by using SAVE parameter.

The discards are the records which are discarded by the group of OUTFIL statements.

The SAVE parameter selects the records for its OUTFIL dataset that not selected for any OUTFIL.


Syntax:

SORT FILEDS=(Starting position, length, data-format, A/D)
OUTFIL FNAMES=DDNAME1, INCLUDE/OMIT COND=(….)
OUTFIL FNAMES=DDNAME2, INCLUDE/OMIT COND=(….)
…..
OUTFIL FNAMES=DDNAMEn, SAVE

Name Description
DDNAMEnDDNAME is eight character’s name that representing the actual dataset in JCL.
INCLUDE/OMITSpecifies the INCLUDE/OMIT condition for specific OUTFIL
SAVESpecifies the records not selected for any OUTFIL will be saved to DDNAMEn

Example: -

Create three output files with dept1 records to file1 and records which are not belongs to dept3 to file2 and the remaining records which are not satisfied above two conditions 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                                 
******************************** 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')                
002430      OUTFIL FNAMES=OUTPUT2,OMIT=(30,5,CH,EQ,C'dept3')                   
002440      OUTFIL FNAMES=OUTPUT3,SAVE                                         
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                                 
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 **********************************
00001     student1           dept1          560                                 
00003     student3           dept2          520                                 
00004     student4           dept1          540                                 
00005     student5           dept2          500                                 
******************************** 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                                 
******************************** 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=OUTPUT2,OMIT=(30,5,CH,EQ,C'dept3') ) - All the records marching with “dept3” from the 30th position of length 5 will be ignored and remaining all records will be copied to output2 file.

  4. OUTFIL FNAMES=OUTPUT3,SAVE - All the records which are ignored from the above two filters will be copied to output3 file. i.e. All dept3 records will be copied to output3 file.

DFSORT OUTFIL: Including, omitting Records DFSORT OUTFIL: Reformatting

Advertisements