Splitting an input file into multiple output files based on record data

This example shows how to split an input file into one or more output files based on the contents of each input record.

Example

Split the input file into multiple output files based on the packed value in bytes 1-4. If the value is greater than 100, put the record in DD OV100; if it is less than 10, put the record in LT10; and if the value is in the middle, put the record in MIDDLE. If the value in bytes 1-4 is not packed, put the record into DD ERROR.
Note: In the REXX and FASTREXX solutions, there is potential for an error to occur. File Manager does not open any of the secondary output DDs for output until there is a WRITE command to that DD executed.

For example, suppose there is never a WRITE to the file ERROR and that ERROR is allocated NEW in the DD card, with BLKSIZE=0 for DFSMS to determine. After DSC executes with the control cards shown below, ERROR will not have been opened, so the BLKSIZE will not have been set acceptably by DFSMS and so it will still be zero. All attempts to read ERROR will generate errors. Therefore, before running this utility you should create empty secondary output data sets. You can use File Manager Data Set Generate (DSG) with NLRECS=0.

This discussion only applies to secondary (WRITE) output data sets. File Manager always opens the primary DSC output data set.

FASTREXX:
$$FILEM DSG OUTPUT=ERROR,NLRECS=0
$$FILEM DSG OUTPUT=OV100,NLRECS=0
$$FILEM DSG OUTPUT=LT10,NLRECS=0
$$FILEM DSG OUTPUT=MIDDLE,NLRECS=0
$$FILEM DSC PROC=*
 If \ FLD_TYPE(1,4,"P") Then WRITE( ERROR )
 Else If FLD(1,4,"P") > 100 Then WRITE( OV100 )
 Else If FLD(1,4,"P") < 10 Then WRITE( LT10 )
 Else WRITE( MIDDLE )
 RETURN DROP

REXX:

(Same as FASTREXX)