Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Sort Final

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

SORT Utilities

SORT Definition & Different Utilities:

What is SORT?
Rearranging records to produce a specific sequence.

Different Utilities
SORT
SYNCSORT
DFSORT
ICETOOL
ICEMAN

Confidential ©2009 Syntel, Inc.


Basic functions:

 Sort has three basic functions:

• Sorting - Rearranging data set records to produce a


specific sequence.
• Merging - Combining up to 100 pre-sequenced data sets
into one data set which has the same sequence.
• Copying – Reproducing a data set without going through
the sorting process.

Confidential ©2009 Syntel, Inc.


Types of SORT:

 Different types of SORT:


Internal Sort
External Sort

• 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

Confidential ©2009 Syntel, Inc.


Types of SORT:

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:

Confidential ©2009 Syntel, Inc.


Syntax of External Sort:

//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=*

Confidential ©2009 Syntel, Inc.


Basic Commands in SORT:

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

Sort card to sort the records based on the key fields


Syntax:
SORT FIELDS = (STARTPOS, LENGTH, TYPE, ASC/DESC)

TYPE: CH (Character), BI(Binary), ZD (Zoned Decimal), PD(Packed


Decimal)

Confidential ©2009 Syntel, Inc.


Basic Commands in SORT:

Sort card to select the records meeting the criteria.


Syntax: INCLUDE COND =
(STARTPOS,LENGTH,TYPE,RO,VALUE)
RO->Relation Operator EQ,NE,LT,GT,LE,GE

Example:
INCLUDE COND = (4,6,CH,EQ,C’BANGLR’)

This will select all the records having the values BANGLR in
the column 4-9.

Confidential ©2009 Syntel, Inc.


Basic Commands in SORT:

Sort filed to reject the records meeting the criteria.


Syntax: OMIT COND = (STARTPOS,LENGTH,TYPE,RO,VALUE)
Example:
OMIT COND = (4,6,CH,EQ,C’BANGLR’)
This will reject the records having the values BANGLR in the
column 4-9.

Sort filed to remove duplicates


Syntax:
SORT FILEDS = (1,5,CH,A), EQUALS
SUM FILEDS= NONE

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.

Confidential ©2009 Syntel, Inc.


Basic Commands in SORT:

Example:
SORT FIELDS = (1,10,CH,A) : This will sort the
records with the columns 1-10 in ascending
order.

10

Confidential ©2009 Syntel, Inc.


Basic Commands in SORT:

Sum fields can also be used as below syntax so as to


remove all the duplicates to another file, XSUM is reserved
word.

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

Confidential ©2009 Syntel, Inc.


Basic Commands in SORT:

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:

OUTFIL FILES=1 INCLUDE=(1,6,CH,EQ,C’MUMBAI’)


OUTFIL FILES=2 INCLUDE=(1,6,CH,EQ,C’TRICHY’)
Code output files as SORTOF1 and SORTOF2.

12

Confidential ©2009 Syntel, Inc.


Special Commands in SORT:

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

Confidential ©2009 Syntel, Inc.


Special Commands in SORT:

Join fields from two files on a key:


The following ICETOOL SPLICE job to do it. This is used to
reformat the fields of the IN1 and IN2 files so you can join them
with the SPLICE operator.

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

Confidential ©2009 Syntel, Inc.


Special Commands in SORT:

SPLITBY using ICEMAN:


To split the records evenly among the output data sets if you don't
need the records in
each output data set to be contiguous. It is similar to SPLIT, except
that it writes n records to each output data set
in rotation.

Syntax:
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLITBY=3
/*

15

Confidential ©2009 Syntel, Inc.


Special Commands in SORT:

Split using ICEMAN:


SPLIT is the easiest way to split an input data set into multiple
output data sets if you don't need the records in
each output data set to be contiguous. SPLIT can be used to split
the records as evenly as possible among the
output data sets. SPLIT writes one record to each output data set
in rotation

Syntax:
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLIT
/*

16

Confidential ©2009 Syntel, Inc.


Special Commands in SORT:

SPLIT1R using ICEMAN:


SPLIT1R=n can be used to split an input data set into multiple
output data sets each of which will have contiguous
records. SPLIT1R=n writes n records to each output data set, and
writes any extra records to the last output data
set.

Syntax:
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTFIL FNAMES=(OUT1,OUT2,OUT3),SPLIT1R=3
/*

17

Confidential ©2009 Syntel, Inc.

You might also like