DFSORT

Pages

Monday, 27 August 2012

Other names that can be
used to invoke SORT are ICEMAN,IERRCO00,IGHRCOOO and SYNCSORT.

Sorting can be done
from ISPF prompt also. For this open the file to be sorted in edit mode.
Then use the command 'SORT 1 22' to sort the file from 1st to 22nd
characters.

DFSORT is invoked using
JCL.

Sample
JCL:

//STEPSORT
EXEC PGM=SORT,PARM=sort-parms

//SORTIN
DD DSN=G1SG00AT.SORTIN1,DISP=SHR Input for sort

//SORTINnn
DD DSN=G1SG00AT.SORTIN2,DISP=SHR Input for merge

//SORTOUT DD
DSN=G1SG00AT.SORTOUT,

//
DISP=(NEW,CATLG,DELETE),

//
UNIT=SYSDA,

//
SPACE=(CYL,(2,2),RLSE),

//
DCB=(LRECL=80,BLKSIZE=0,RECFM=FB,DSORG=PS)

//SORTOFnn
DD DSN=G1SG00AT.SORTOUT, Output data sets

//
DISP=OLD

//SORTXSUM
DD DSN=G1SG00AT.SORTOUT, Records eliminated by SUM

//
DISP=OLD

//SORTWK01
DD SPACE=(CYL,(20,15),RLSE),UNIT=SYSDA

//SORTWK02
DD SPACE=(CYL,(20,15),RLSE),UNIT=SYSDA

//SYSOUT
DD SYSOUT=*

//SYSIN
DD *<control statements>

Following
DDNAMES are required to code a DFSORT job.

//JOBNAME JOB
-->

Signals the initiation of a job. JOB statement contains
all normal parameters as in normal JCL.

//STEPNAME EXEC
-->

Signals the initiation of a step. Tells OS which program
is to be executed. For DFSORT the program to be executed is SORT.

//STEPNAME EXEC PGM=SORT

//SYSOUT DD -->

Defines the output dataset for messages.

//SYSOUT DD SYSOUT=*

//SORTIN -->

Defines the input dataset that needs to be sorted. Input
Could be sequential, extended sequential, PDSE member, PDS member or a
VSAM dataset. Files can be concatenated if the RECFM is the same for all
files. For variable length files the file with largest record length
must be first.

//SORTINxx -->

Used for merge request input files . Up to 100 SORTINnn
DD's may be specified. The 'nn' suffix can be any number in the range 00
thru 99; they may be skipped or used out of order. The files must
already be sorted in the proper sequence for the MERGE.

//SORTWknn -->

From 1 to 100 sort work files can be allocated using the
SORTWKnn DD statement. The 'nn' suffix can be any number in the range 00
thru 99.SORTWKnn DD's are not used for a MERGE or a copy operation, or
if the DYNALLOC parmis used. Each SORTWKnn MUST be on one unit & one
volume.

//SORTOUT -->

Defines the output dataset. It can be sequential,
extended sequential data set ,a PDS member or a PDSE member.

//SORTOFnn -->

Output file for a SORT, MERGE, or copy function. Up to
100 SORTOFnn DD's may be specified. The 'nn' suffix can be any number in
the range 00 through 99. They may be skipped or used out of order. The
FNAMES/FILES parameter on the OUTFILE control statement specifies the DD
names of the output files and the output records that are written to
each SORTOFnn data set.

//SORTXSUM -->

Output file for a SORT or MERGE function. The records
eliminated by SUM processing are written to the SORTXSUM DD.

//SYSIN DD * -->

Defines the sort cards.

Sorting
data:

Sorting means Rearranging data in either ascending or
descending order.

SORT FIELDS=(Starting
position of field, Length of the field, datatype, Ascending or Descending
order)

SORT
FIELDS=(pos1,len1,type1,opt1,pos2,len2,type2,opt2,...)

{,SIZE=n | En}

{,FILSZ=n |
eN}

{,DYNALLOC=(OFF) | (d,n){,RETRY=(OFF | (nn,mm)}}

{,SKIPREC=n} --> skip
these many records and then start the sort operation

{,STOPAFT=n} --> Stop
after these records

{,EQUALS |
NOEQUALS}

{,CKPT |
CHKPT}{,CENTWIN={0 | s | f}

EQUALS ¦ NOEQUALS -

Determines whether or not the sort will preserve the
order of records with identical sort fields.

NOEQUALS is the default, and causes equal-keyed records
to bewritten in a random order, not in the order they were encountered.

Used to set up selection criteria for records to be
omitted from the output dataset.

We can omit a record by comparing contents of its fields
to a constant or another field in the record.

Omit Statement cannot appear with INCLUDE on the same
SORT execution.

Format of OMIT:

OMIT COND={({c1,{AND | OR},c2},...){,FORMAT=x} }

{ALL}

{NONE}

Example:

SORT FIELDS=COPY

OMIT COND=(16,15,CH,EQ,31,15,CH)

OMIT COND=((10,3,CH,EQ,C'REV'),AND,(67,2,CH,NE,C'GA')) OR

OMIT
COND=((10,3,EQ,C'REV'),AND,(67,2,NE,C'GA')),FORMAT=CH

Comparison Operators that can be used with INCLUDE and
OMIT are EQ,NE,GT,GE,LE,LT

SUMming
fields:

The SUM control statement deletes records with equal
control fields and optionally summarizes specified numeric fields on those
records. If numeric fields are to be summarized, the data in the summary fields
is added, the sum is placed in one of the records, and the other record is
deleted.

The format of the SUM statement is:

{FIELDS={NONE}
}

SUM {FIELDS=(p1,l1,f1 {,p2,l2,f2) ... ) }

{FIELDS=(p1,l1
{,p2,l2) ... ),FORMAT=f } {,XSUM}

Where XSUM means the dropped records are written in the
dataset specified by SORTXSUM data set.

INCLUDE COND=(31,4,CH,EQ,C'MIKE')

SORT FIELDS=(31,15,,CH,A)

SUM FIELDS=(46,10,BI)

The result will contain a Single row which is top mostrow
of the Sorted fields including the condition mentioned in INCLUDE Statement,
and the Price Fields will contain the Sum of prices of all books whose Author
is MIKE.

Eliminating
duplicates on a field:

SORT FIELDS=COPY

SUM FIELDS=NONE

We could use XSUM if we want to save off the remaining
records.

SUM FIELDS=NONE,XSUM

In this case we must have a additional DD called
SORTXSUM. This is where the discards will go.

Reformatting
output:

We can perform reformatting using INREC,OUTREC and
OUTFIL.

We can use INREC,OUTREC,OUTFIL to

Delete fields

Reorder fields

Insert strings or
blanks

Convert data to hexadecimal representation.

Convert case.

Edit numeric values

Convert numeric values
to another format.

Perform arithmetic
operations.

Insert sequence number.

Change record Length.

INREC: Formatting will be done before sorting ,
merging or copying of the records is done. Hence we will refer the original
file layout when using INREC. In short operation will be performed on the input
file.

Use of INREC improves the sort performance by reducing
the number of bytes that must be processed.

The format of the INREC statement is INREC FIELDS=(...).

The FIELDS parameter simply identifies the fields that
should be processed.

A sample INREC statement is as follows:

INREC FIELDS=(1:1,20,21:40,15,ZD,PD,29:60,5)

In this statement, 3 data fields are specified as
follows:

The first field begins
in byte 1 of the input record and is 20 bytes long.

It will be in position 1 of the output record.

The second field begins
in byte 40 of the input record and is a 15-byte ZD field.

The field will be converted to PD. It will be in position
21 of the output record.

The third field begins
in byte 60 of the input record and is 5 bytes long.

It will be in position 29 of the output record.

IN the above example we used absolute positioning using
":". We can also just specify the position in input file and it will
create fields back to back.

OUTREC: Formatting will be done after sorting
or merging is done. In short Operation will be performed on the output file.

Delete or repeat
segments of the input records.

Insert character
strings between data fields.

Insert binary zeros.

Create a sequence
number field.

Convert numeric data to
printable format or to another numeric data format.