Reformatting Records With FINDREP
Reformatting Records With FINDREP
Reformatting Records With FINDREP
With the BUILD, FIELDS or OVERLAY parameter of the OUTREC statement, you reformat output records by
specifying items that start at a specific position. But if you want to replace or remove data anywhere in your
records, you would use the FINDREP parameter of the OUTREC statement instead.
FINDREP indicates that you want to do a find and replace operation. IN identifies the constant you are looking
for (the "find" constant) and OUT identifies the constant you want instead (the "replace" constant).
The results produced for this OUTREC statement using the input records shown previously are:
#"Goodbye John"#"Goodbye Bill"#"Goodbye Goodboy"#
"Goodbye Michael""Good Beagle""Goodbye Goodbye"
For complete details on find and replace, see z/OS DFSORT Application Programming Guide.
So far
Now you know how to use the FINDREP parameter of the OUTREC statement to replace or remove data
anywhere in your records. Keep in mind that you can use all of these reformatting features with the FINDREP
parameter of the INREC statement and OUTFIL statement, as well as with the OUTREC statement. Next, you
will learn how to use IFTHEN clauses with the OUTREC statement to reformat different records in different
ways.
Parent topic: Reformatting records with fixed fields
1. FzxxxxxxsINDREP
Using SORT, you can FIND a value and REPLACE it with another value.
RAJESH TML
RAMS TML
SUNIL TML
SURESH TML
RAJESH TPT
RAMS TPT
SUNIL TPT
SURESH TPT
OPTION COPY
OUTREC FINDREP=(IN=C’TML’,OUT=C’TPT’)
Or
OPTION COPY
OUTREC FINDREP=(INOUT=(C’TML’,C’TPT’)
FINDREP is used to find and replace the input record
1. IFTHEN
Sample JCL:
Input File
RAJESH
RAMS
SURI
SUNIL
SUNIL FRIEND BE
OPTION COPY
OUTREC IFTHEN=(WHEN=INIT,BUILD=(1,7,C’FRIEND’,20X),
IFTHEN=(WHEN=(1,7,CH,EQ,C’RAJESH’,OVERLAY=(15:C’BTECH’)),
IFTHEN=(WHEN=(1,7,CH,EQ,C’RAMS’,OVERLAY=(15:C’MCA’)),
IFTHEN=(WHEN=(1,7,CH,EQ,C’SURI’,OVERLAY=(15:C’MSC’)),
IFTHEN=(WHEN=NONE,OVERLAY=(15:C’BE’)))
Suppose you want to write only the records between HDR and TRL into the
output file.
HDR VARUN
001 SRI
002 RAJESH
TRL RAMS
TMP SURI
HDR SUNIL
001 CHIRU
TRL PAVAN
TP1 PRAVEEN
OPTION COPY
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C’HDR’),
END=(1,3,CH,EQ,C’TRL’),PUSH=(21:ID=1))
PUSH overlays a 1-byte ID character at position 21 in each record of a group (after the
end of the record).
After the IFTHEN GROUP clause is executed, the intermediate records look like this
HDR VARUN 1
001 SRI 1
002 RAJESH 1
TRL RAMS 1
TMP SURI
HDR SUNIL 2
001 CHIRU 2
TRL PAVAN 2
TP1 PRAVEEN
Your output file will be like below due to the OUTFIL statement
HDR VARUN
001 SRI
002 RAJESH
TRL RAMS
HDR SUNIL
001 CHIRU
TRL PAVAN
1. INREC
INREC reformats the records before they are sorted, so the SORT and SUM
statements must refer to the reformatted records as they will appear in the output
data set.
If you want to sort your input file based on bytes 11-15 and write only the bytes 11-
20 into the output file.
INREC FIELDS=(11,10)
SORT FIELDS=(1,5,CH,A)
OUTREC FIELDS=(1,10)
Instead of
SORT FIELDS=(11,5,CH,A)
OUTREC FIELDS=(11,10)