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

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.