 |
RAMESH KRISHNA REDDY |
|
DFSORT TUTORIAL
from DRONA SERIES
ASSUMPTIONS
Before discussing about SORT,let us assume following things
Input file has following data and structure
INPUT FILE |
MOHANK 23423423434534344 KIRAN
MOHANK 13342345345345345 RAJEEV
ARAMES 34535345325354324 SURESH
SURESH 98347385385933987 PULI
RAMESH 67575789769876785 MADHU
KRISHN 50830948530859340 OIIED
KRISHN 30495849572938495 MADHU
SURESH 98347385385933987 PULI
|
Simple SORT jcl structue is as follows - Sample sort jcl ----
.
.
//STEP10 EXEC PGM=SORT,REGION=1024K,PARM=parameters
//SYSOUT DD SYSOUT=* Output messages from SORT
//SORTIN DD DSN=...,DISP=SHR Input if SORT request
//SORTOUT DD DSN=... Output for SORT request
//SORTOFxx DD DSN=... OUTFILE output data sets
//SORTXSUM DD DSN=... Output eliminated by the SUM stm
//SORTWKnn DD UNIT=SYSDA, Work files if SORT request
//SYSIN DD * Control statement input data set
sort control statements
/*
.
.
FOLLOWING ARE THE SORTCARDS FOR DIFFERENT TYPES OF SORTS
//SYSIN DD *
SORT FIELDS=(1,3,CH,A,9,3,CH,A)
/*
OUTPUT FILE |
ARAMES 34535345325354324 SURESH
KRISHN 30495849572938495 MADHU
KRISHN 50830948530859340 OIIED
MOHANK 13342345345345345 RAJEEV
MOHANK 23423423434534344 KIRAN
RAMESH 67575789769876785 MADHU
SURESH 98347385385933987 PULI
SURESH 98347385385933987 PULI
|
EXPLANATION
Above syntax of SORT sorted the recrods, depends
on keys we have provided
(we have provided two keys in FIELDS parameter)
FIRST KEY
1,3,CH,A - first key started at col 1 , its length is 3
SECOND KEY
9,3,CH,A - second key started at col 9, its length is 3
In the above example,
CH- means character we may use BI for binary
A - Ascending order
TASK 2. ELEMINATE DUPLICATES |
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=NONE
/*
//** copyright www.mainframegurukul.com
OUTFILE |
ARAMES 34535345325354324 SURESH
KRISHN 50830948530859340 OIIED
MOHANK 23423423434534344 KIRAN
RAMESH 67575789769876785 MADHU
SURESH 98347385385933987 PULI
|
EXPLANATION
if we give SUM FIELDS=NONE it will eliminate duplicates
.
.
.
//SORTOF01 DD DSN=dataset1,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(1,4),RLSE),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SORTOF02 DD DSN=dataset2,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(1,4),RLSE),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SORTOF03 DD DSN=dataset3,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(1,4),RLSE),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
.
.
.
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FILES=01,INCLUDE=(1,6,CH,EQ,C'MOHANK')
OUTFIL FILES=02,INCLUDE=(1,6,CH,EQ,C'SURESH')
OUTFIL FILES=03,INCLUDE=(1,6,CH,EQ,C'KRISHN')
/*
SORTOF01 |
MOHANK 23423423434534344 KIRAN
MOHANK 13342345345345345 RAJEEV
|
SORTOF02 |
SURESH 98347385385933987 PULI
SURESH 98347385385933987 PULI
|
SORTOF03 |
KRISHN 50830948530859340 OIIED
KRISHN 30495849572938495 MADHU
|
EXPLANATION
1. SORT FIELDS=COPY - indicate , it for copy of records, not for sort
2. OUTFIL FILES=01,INCLUDE=(1,6,CH,EQ,C'MOHANK')
OUTFIL FILES=02,INCLUDE=(1,6,CH,EQ,C'SURESH')
OUTFIL FILES=03,INCLUDE=(1,6,CH,EQ,C'KRISHN')
- SYNCSORT will take data from 1st positioon to 6th position of input
file and it will compare that data with MOHANK or SURESH or KRISHN
- If data equals to MOHANK then that recorrd will copies to dataset defined
in SORTOF01 step. ( because we defined FILES=01 in second condition )
- If data equals to SURESH then that recorrd will pass to dataset defined
in SORTOF02 step. ( because we defined FILES=02 in second condition )
- If data equals to KRISHN then that recorrd will copied to dataset difned
in SORTOF03 step. ( because we defined FILES=03 in third condition )
.
.
//SORTXSUM DD DSN=datasetname,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(1,4),RLSE),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
.
.
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=NONE,XSUM
/*
//*copyright www.mainframegurukul.com & www.geocitie.comhttp://www.mainframetutorials.com
SORTOUT |
ARAMES 34535345325354324 SURESH
KRISHN 50830948530859340 OIIED
MOHANK 23423423434534344 KIRAN
RAMESH 67575789769876785 MADHU
SURESH 98347385385933987 PULI
|
SORTXSUM |
KRISHN 30495849572938495 MADHU
MOHANK 13342345345345345 RAJEEV
SURESH 98347385385933987 PULI
|
EXPLANATION
1. SORT FIELDS=(1,3,CH,A)
Input file will be sorted depending up on the key specified above
1,3,CH,A - key starting position is 1 and length 3, comparing type
character, sorting is don in ascending order
2. SUM FIELDS=NONE,XSUM
SUM FIELDS=NONE means it will eliminate duplicates
XSUM options will copy all records eliminated in sort
process will copy to another data set defined in
SORTXSUM step
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(1,6,CH,EQ,C'SURESH')
/*
//* copyright www.mainframegurukul.com
OUTPUTFILE |
SURESH 98347385385933987 PULI
SURESH 98347385385933987 PULI
|
EXPLANATION
above card is to copy records from input file which
contains SURESH at 1st position
//SYSIN DD *
SORT FIELDS=COPY
INREC FIELDS=(7:2,5,20:10,3)
/*
//* copyright www.mainframegurukul.com
OUTPUT FILE |
OHANK 342a
OHANK 334
RAMES 453
URESH 834
AMESH 757
RISHN 083
RISHN 049
URESH 834
|
EXPLANATION
1. SORT FIELDS=COPY
It is for copy records to output file
2. INREC FIELDS=(7:2,5,20:10,3) (for formatting)
Here we have two formattings,
1. 7:2,5 - data at 2nd position of input file with length 5
copied to 7th position of output file
2. 20:10,3 - data at 10th position of input file with length 3
copied to 20th position of output file
In above example, we can use OUTREC instread of INREC,
INREC adds, deletes, or reformats fields before the
records are sorted or merged. so that performance will
be improved
OUTREC adds, deletes, or reformats fields after the
records are sorted or merged.
Other parameters we can pass with sort card |
SKIPREC=n
causes sort to skip over 'n' records in the input file before
starting a sorting or copying operation.
STOPAFT=n
causes sort to stop after 'n' records in the input file have
been sorted or copied.
CURRENT DISCUSSIONS IN -- SORT FORUM
www.mainframegurukul.com
In this website you can post questions on sort/icetool.
Those will get answered by experts in this forum.
If any suggestions please send to srcsinc@yahoo.com or click here to send
-- A tutorial from DRONA SERIES
www.mainframetutorials.com
Visit books section in this site for good books