OUTFIL Repeating Records
The OUTFIL statement can use the REPEAT option to repeat specified fields or constant values in the output records. It is used to repeat the records for specific times.
If the BUILD, OUTREC, OVERLAY, or IFTHEN parameters are coded with sequence numbers, those are incremented for each repeated record. If no BUILD, OUTREC, OVERLAY, or IFTHEN parameters are coded with sequence numbers, the repeated records are identical as coded.
Syntax -
//SYSIN DD *
OPTION COPY
INCLUDE|OMIT COND=(……)
OUTFIL FNAMES=DDname-n,REPEAT=n,BUILD=(..)|OUTREC=(..)
/*
'|" represents OR.
REPEAT=n | Specifies how many times the output records should be repeated. |
OUTREC | Similar to BUILD, used to reformat the output records by selecting and arranging specific fields. |
Examples -
Scenario1 - Repeating a Constant Value.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=SORTOUT,REPEAT=5,BUILD=(C'HELLO')
/*
Creates 5 identical records in the output and wach repeated record contains the constant 'HELLO'.
Scenario2 - Repeating a Field from the Input Dataset.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=SORTOUT,REPEAT=3,BUILD=(1,10)
/*
Each input record is repeated 3 times in the output and each repeated record includes the first 10 bytes from the input record.
Scenario3 - Repeating a Field with a Constant.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=SORTOUT,REPEAT=4,BUILD=(C'CONSTANT',X'40',C'REPEAT')
/*
Creates 4 identical records in the output and each repeated record includes the text 'CONSTANT', followed by a space (X'40'), and the text 'REPEAT'.