Home » SORT » SORT – FINDREP, IFTHEN and INREC

SORT – FINDREP, IFTHEN and INREC

SORT – FINDREP, IFTHEN and INREC

  1. FINDREP

    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 to look at:

     

    SORT – CONVERT PD to ZD and BI to ZD
    SORT – EDIT FIRST AND LAST RECORD
    SORT – EDIT MASK PATTERNS
    SORT – EDIT NUMERIC FIELDS (I,T,S)
    SORT – FINDREP, IFTHEN and INREC
    SORT – How to use VB dataset (VLSHRT)
    SORT – INCLUDE and OMIT
    SORT – INREC, INCLUDE and OMIT
    SORT – JUSTIFY, SQUEEZE and OVERLAY
    SORT – LOOKUP AND CHANGE
    SORT – OUTPUT DATASET DCB (LRECL,RECFM,BLKSIZE)
    SORT – OUTREC – INSERT ZEROES, BLANKS, STRINGS
    SORT – OUTREC – TRAN
    SORT – PARSE – REFORMAT VARIABLE FIELDS
    SORT – Process Order of CONTROL Statements
    SORT – REMOVE DUPLICATES AND WRITE THEM TO XSUM
    SORT – SET RETURN CODE ‘04’ IF OUTPUT FILE IS EMPTY
    SORT – SKIPREC and STOPAFT
    SORT – SUM FIELDS
    SORT – TO REPLACE A CHAR WITH ANOTHER CHAR - ALTSEQ
    SORT – INREC
    SORT – SYMBOLS
    SORT JOB – SIMPLE COPY
    SORT JOIN – TO JOIN TWO FILES BASED ON A KEY
    SORT JOIN – UNPAIRED RECORDS INDICATOR


About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s