Tags

, , , , , , , , , ,

SORT – EDIT FIRST AND LAST RECORD

//STEP01 EXEC PGM=SORT

//SYSOUT DD SYSOUT=*

//SORTIN DD DSN=HLQ1.HLQ2.SORTIN,DISP=SHR

//TEMPIN DD DSN=HLQ1.HLQ2.TEMPIN,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,CATLG)

//SYM DD DSN=HLQ1.HLQ2.SYMNAMES,UNIT=SYSDA, SPACE=(CYL,(5,5)),DISP=(,CATLG)

//SYSIN DD *

OPTION COPY

OUTFIL FNAMES=TEMPIN,OVERLAY=(81:SEQNUM,8,ZD)

OUTFIL FNAMES=SYM,REMOVECC,NODETAIL,

TRAILER1=(‘LASTREC,+’,COUNT=(M11,LENGTH=8),80:X)

/*

//STEP02 EXEC PGM=SORT

//SYSOUT DD SYSOUT=*

//SYMNAMES DD DSN= HLQ1.HLQ2.SYMNAMES,DISP=OLD

//SORTIN DD DSN= HLQ1.HLQ2.TEMPIN,DISP=OLD

//OUT DD DSN= HLQ1.HLQ2.OUTPUT,DISP=SHR

//SYSIN DD *

SORT FIELDS=COPY

INREC IFTHEN=(WHEN=(81,8,ZD,EQ,1),OVERLAY=(1:C’FIRST RECORD ‘)),

IFTHEN=(WHEN=(81,8,ZD,EQ,LASTREC),OVERLAY=(43:C’LAST RECORD’))

OUTFIL FNAMES=OUT,

BUILD=(1,80)

/*

This is done in 2 step process.

  1. In the first step, we create a temporary copy of input file with sequence number appended at the last 8 bytes.

    OUTFIL FNAMES=T1,OVERLAY=(81:SEQNUM,8,ZD)

    Creating a SYMNAMES file with the symbol LASTREC that has the value of count of the records in the input file.

    OUTFIL FNAMES=SYM,REMOVECC,NODETAIL,

    TRAILER1=(‘LASTREC,+’,COUNT=(M11,LENGTH=8),80:X)

    NOTE:

    1. COUNT gets the record count in the input file.
    2. M11 would tell SORT to use leading zeros

    10 – Would be displayed as 00000010 as 8 chars with leading zeroes

    1. REMOVECC parameter is used to remove the ANSI carriage control characters in your output records
    2. NODETAIL tells SORT to process the data records in the usual way, but not to write them to the report data set
    3. TRAILER1 tells SORT to write a report trailer
  1. In the second step, the sequence number appended at the end and the SYMNAMES dataset containing the LASTREC will help us in finding the first and the last record.

    INREC IFTHEN=(WHEN=(81,8,ZD,EQ,1),OVERLAY=(1:C’$$DD01 COPY ‘)),

    IFTHEN=(WHEN=(81,8,ZD,EQ,LASTREC),OVERLAY=(43:C’ ‘))

——————————————————————————————————–

In United States, If you would like to Earn Free Stocks, Credit card Points and Bank account Bonuses, Please visit My Finance Blog

——————————————————————————————————–

You may also like to look at:

Working on Mainframes – Is Change to a different technology necessary
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

 

Advertisement