OUTFIL Saving discards
OUTFIL Saving discards
We can use the OUTFIL statement to save discarded records—that are discarded by the group of OUTFIL statements. The SAVE parameter selects the records for its OUTFIL file that are not chosen for any OUTFIL.
Syntax -
//SYSIN DD *
SORT FILEDS=...
OUTFIL FNAMES=DDname-1,INCLUDE/OMIT COND=(….)
OUTFIL FNAMES=DDname-2,INCLUDE/OMIT COND=(….)
…
OUTFIL FNAMES=DDname-n,SAVE
/*
INCLUDE or OMIT | Specifies the INCLUDE or OMIT condition for specific OUTFIL |
SAVE | This option saves all records that were not included in any previous OUTFIL datasets (i.e., the discarded records). |
Examples -
Scenario1 - Saving Discards with a Condition.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=OUTPUT,INCLUDE=(1,3,CH,EQ,C'ABC')
OUTFIL FNAMES=DISCARDS,SAVE
/*
Only records where the first 3 characters are equal to 'ABC' are written to the OUTPUT file. All records not matching the INCLUDE condition are saved to the DISCARDS file.
Scenario2 - Multiple Outputs with Saving Discards.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=OUTPUT1,INCLUDE=(1,3,CH,EQ,C'ABC')
OUTFIL FNAMES=OUTPUT2,INCLUDE=(4,3,CH,EQ,C'XYZ')
OUTFIL FNAMES=DISCARDS,SAVE
/*
Records where the first 3 characters equal 'ABC' are written to OUTPUT1. Records where characters 4 to 6 equal 'XYZ' are written to OUTPUT2. All records that do not meet either condition are saved to DISCARS.