Sort Final
Sort Final
Sort Final
What is SORT?
Rearranging records to produce a specific sequence.
Different Utilities
SORT
SYNCSORT
DFSORT
ICETOOL
ICEMAN
• Internal Sort:
It is used in COBOL application program
If you want to manipulate the data before feeding to sort, prefer
internal sort.
Syntax:
SORT SORTFILE ON ASCENDING /DESCENDING KEY sd-key-1 sd-
key2
USING file1 file2
GIVING file3
END-SORT
4
External Sort:
• External sort is used in JCL.
• If there is no manipulate of the data before feeding to sort
then we can use external sort.
Syntax:
//Job card
//STEP1 EXEC PGM=SORT
//SORTIN DD DSN=X.Y.Z,DISP=SHR, (Input file for sort)
//SORTOUT DD DSN=A.B.C,DISP=SHR, (Output file for sort)
//SORTWRK01 DD DSN=&&temp1,UNIT=SYSDA,
// SORTWRK02 DD DSN=&&temp2,UNIT=SYSDA,
// SORTWRK03 DD DSN=&&temp3,UNIT=SYSDA,
(SORT WORK FILES FOR SORT)
//SYSIN DD *
CONTROL CARD (Sort commands are written here)
/*
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
The Sort card used to copy all the records from SORTIN to
SORTOUT.
Syntax:
SORT FIELDS=COPY
Sort to skip first 100 records and then copy next 20 records.
Syntax:
SORT FIELDS=COPY SKIPREC=100 STOPAFT=20
Example:
INCLUDE COND = (4,6,CH,EQ,C’BANGLR’)
This will select all the records having the values BANGLR in
the column 4-9.
SORTIN records are sorted on the key 1-5 and if more than one record
is found to have same key, then only one record will be written to
SORTOUT. If EQUALS is coded , then the record to be written is the
first record else it can be anything.
Example:
SORT FIELDS = (1,10,CH,A) : This will sort the
records with the columns 1-10 in ascending
order.
10
Syntax:
//JOB CARD
//STEP EXEC PGM=SORT
//SORTIN DD DSN=X.Y.Z,DISP=SHR,
//SORTOUT DD DSN=A.B.C,DISP=SHR,
//SYSIN DD *
SORT FILEDS = (1,5,CH,A), EQUALS
SUM FILEDS= NONE,XSUM
/*
//SORTXSUM DD DSN=OUTPUT.DUP.FILE,DISP=SHR,
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
11
Inrec SORT card to restructure the input file before feeding to sort
Outrec can also be used for reconstruction of the sorted file but
before writing to file
Syntax:
OUTREC = (1:1,20 first 20 char from input file
21:C’BANGL’ Followed by string ‘BANGL’
36:21,10) 21 st to 10 CHAR from input file.
SORT card to create multiple files from single input file (Maximum 32 files)
Syntax:
12
Outrec Fields with Build Option: This Control card can be used
when we have to create a output file by checking the input fields
and replace particular filed with specific character
SORT FIELDS=COPY
OUTREC IFTHEN=(WHEN=(5,14,CH,EQ,C'10080100002195'),
BUILD=(1:1,4,5:C'10073100002195',19:19,132)),
IFTHEN=(WHEN=(5,14,CH,EQ,C'10080100002196'),
BUILD=(1:1,4,5:C'10073100002196',19:19,132))
13
Syntax:
//TOOLIN DD *
COPY FROM(IN1) TO(TMP1) USING(CPY1)
COPY FROM(IN2) TO(TMP1) USING(CPY2)
SPLICE FROM(TMP1) TO(OUT) ON(1,3,CH) WITH(11,5)
/*
//CPY1CNTL DD *
OUTREC BUILD=(1:1,3,5:5,5,11:5X)
/*
//CPY2CNTL DD *
OUTREC BUILD=(1:1,3,11:5,5)
/*
14
Syntax:
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLITBY=3
/*
15
Syntax:
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLIT
/*
16
Syntax:
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLIT1R=3
/*
17