Thursday 20 August 2015

SYNCSORT Utility

JCL SORT or SYNCSORT utility in JCL is used to sort the datasets, merge datasets and copy datasets. Most of the installations change the SYNCSORT utility program name to SORT.

JCL SORT Statement format:

SORT FIELDS=(Starting position, Length, Format, Asc/Des, { Starting position, Length, Format, Asc/Des}{…..})

OR

SORT FIELDS=(Starting position, Length, Asc/Des, { Starting position, Length, Asc/Des}{…..}),{Format}

Starting position indicates the location of the sort key in the record.

Length indicates the length of the sort key.

Format indicates the field type which can have values CH – Character, ZD – 
Zonal Decimal, PD – Packed Decimal and BI – Binary.

Asc/Des indicates order of the sort Ascending / Descending.

Examples:

SORT FIELDS=(1,3,CH,A)
SORT FIELDS=(1,5,CH,D)
SUM FIELDS=NONE -->To eliminate duplicates.
SUM FIELDS=NONE,XSUM

XSUM -> Copies duplicate records into a data set. We will specify this dataset name with DD name SORTXSUM.

Ex: 

SORT FIELDS=(1,5,CH,D)
SUM FIELDS=NONE

SKIPREC and STOPAFT parameters :

SKIPREC = n statement skips n records before copy or sort.

SORT FIELDS=COPY
SKIPREC=1000

The above statement skips first 1000 records and copies remaining records.

STOPAFT=n statement copies or sorts at most n records.

SORT FIELDS=COPY
STOPAFT=1000

The above statement outputs first 1000 records after any processing is done.

MERGE can be used to merge two or more pre sorted datasets. We can merge a maximum of 32 datasets.

MERGE Statement format:

MERGE FIELDS=(Starting position, Length, Format, Asc/Des, { Starting position, Length, Format, Asc/Des}{…..})

OR

MERGE FIELDS=(Starting position, Length, Asc/Des, { Starting position, Length, Asc/Des}{…..}),{Format}

INCLUDE COND:

Include statement can be used to include records based on a specific condition.

INCLUDE COND=(Starting position, Length, condition operator,value)

Example:

SORT FIELDS=COPY
INCLUDE COND=(1,3,CH,EQ,C'JCL')


In the above examples the records which contain ‘JCL’ in the first 3 positions will be copied.

OMIT COND: 

Similarly we can omit the records from the dataset based on a specific condition.

SORT FIELDS=COPY
OMIT COND=(1,3,CH,EQ,C'JCL')

In the above examples the records which contain ‘JCL’ in the first 3 positions will not be copied.

No comments:

Post a Comment