Reformatting Records With FINDREP

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Reformatting records with FINDREP

z/OS DFSORT: Getting Started


SC23-6880-00

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.

Suppose you had input records that looked like this:


*"Goodbye John"*"Goodbye William"*"Goodbye Goodboy"*
"Goodbye Mike""Good Dog""Goodbye Goodbye"
You could use the following statements to replace all instances of 'Goodbye' anywhere in the input records with
'Bye'.
OPTION COPY
OUTREC FINDREP=(IN=C'Goodbye',OUT=C'Bye')

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 output records produced by this OUTREC statement are:


*"Bye John"*"Bye William"*"Bye Goodboy"*
"Bye Mike""Good Dog""Bye Bye"
You can use OUT=C'' (null constant) to remove identified constants. For example, you could use the following
statements to remove 'bye' anywhere in the input records:
OPTION COPY
OUTREC FINDREP=(IN=C'bye',OUT=C'')
The results produced for this OUTREC statement using the input records shown previously are:
*"Good John"*"Good William"*"Good Goodboy"*
"Good Mike""Good Dog""Good Good"
You could use the following statements to change 'William' to 'Bill', 'Mike' to 'Michael', 'Dog' to 'Beagle' and '*'
to '#' anywhere in the input records:
OPTION COPY
OUTREC FINDREP=(INOUT=(C'William',C'Bill',
C'Mike',C'Michael',C'Dog',C'Beagle',C'*',C'#'))

INOUT identifies pairs of find and replace constants.

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.

Suppose you have your input file as below:

RAJESH TML

RAMS TML

SUNIL TML

SURESH TML

And you want your output file in this format

RAJESH TPT

RAMS TPT

SUNIL TPT

SURESH TPT

Your SORT card would look like below:

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

IN Tells the field that needs to be found

OUT Tells the field that needs to be replaced with

INOUT Specifies both find and replace strings in order

1. IFTHEN

You can use five types of IFTHEN clauses as follows:

WHEN=INIT: Use one or more WHEN=INIT clauses to apply BUILD, FINDREP or


OVERLAY items to all of your input records.

WHEN=GROUP: Use one or more WHEN=GROUP clauses to propagate fields,


identifiers and sequence numbers within groups of records.

WHEN=(logexp): Use one or more WHEN=(logexp) clauses to apply BUILD,


FINDREP or OVERLAY items to the subset of your records that satisfy a specified
logical expression.

WHEN=ANY: Use a WHEN=ANY clause after multiple WHEN=(logexp) clauses to


apply additional BUILD, FINDREP or OVERLAY items to your records if they satisfied
the criteria for any of the preceding WHEN=(logexp) clauses.

WHEN=NONE: Use one or more WHEN=NONE clauses to apply BUILD, FINDREP or


OVERLAY items to your records that did not meet the criteria for any of the
WHEN=(logexp) clauses.

Sample JCL:

Input File

RAJESH

RAMS

SURI
SUNIL

And you want your output file in this format

RAJESH FRIEND BTECH

RAMS FRIEND MCA

SURI FRIEND MSC

SUNIL FRIEND BE

Your SORT card would look like below:

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’)))

Example to use WHEN=GROUP

Suppose you want to write only the records between HDR and TRL into the
output file.

Your input file looks like below

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))

OUTFIL INCLUDE=(21,1,CH,NE,C’ ‘),BUILD=(1,20)

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

OUTFIL INCLUDE=(21,1,CH,NE,C’ ‘),BUILD=(1,20)

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)

You might also like