SORT
The SORT program is used to sort data into a certain sequence or to merge from 2 to 100 previously sorted input data sets into 1 output data set.
//STEP10 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=<<>>
//SORTOUT DD DISP=(MOD,CATLG,DELETE),SPACE=(CYL,(5,5),RLSE),
// UNIT=SYSDA,DCB=*.SORTIN,
// DSN=<<>>
//SYSIN DD *
//************** INCLUDE SORT STEPS HERE
<!--[if !supportLists]-->1) <!--[endif]-->TO SORT ON POSITIONS say for eg. 1 to 7
SORT FIELDS=(1,7,CH,A)
Where
Sort fields = (position ,length ,format ,sequence) or
Sort fields = (position ,length , sequence..),format = CH/BI/PD/ZD.d
PD=packed Decimal(COMP-3), ZD=zone decimal.
NOTE :-
Instead of using JCL to perform SORT operation , there's one simple alternative,
For eg:- Open a Flat file in edit mode. On the command line type (say) SORT 1,7 and press ENTER, the file will be sorted on positions 1 to 7 bytes.
2) TO COPY ALL THE RECORDS FROM INPUT FILE TO OUTPUT FILE
SORT FIELDS=COPY
3) TO COPY THOSE RECORDS WHICH SATISFY A PARTICULAR CONDITION.
INCLUDE COND=(38,10,CH,EQ,C'57071509',OR,36,10,CH,EQ,C' 57105779')
4) TO OMIT THOSE RECORDS WHICH SATISFY A PARTICULAR CONDITION.
OMIT COND=(19,1,CH,EQ,C'S',OR,19,1,CH,EQ,C'S')
5) TO SKIP CERTAIN NO OF RECORDS
SORT FIELDS=COPY,SKIPREC=1000
6) TO STOP AFTER COPYING CERTAIN NO OF RECORDS
SORT FIELDS=COPY,STOPAFT=5000
7) SKIPREC AND STOPREC CAN BE USED IN COMBINATION
SORT FIELDS=COPY,SKIPREC=1000,STOPAFT=5000
<!--[if !supportLists]-->
<!--[endif]-->TO REMOVE DUPLICATES FROM THE FILE USING SORT
SORT FIELDS=(1,7,A),FORMAT=CH
SUM FIELDS=NONE
MERGE
The MERGE control statement defines the application as a MERGE application.
MERGE FIELDS=...
{,FILES=n}
{,EQUALS | NOEQUALS}
{,CKPT | CHKPT}
{,CENTWIN={0 | s | f}}
where
FIELDS=(pos1,len1,opt1,pos2,len2,opt2,...),FORMAT= type
Keyword explanations:
The FIELDS= keyword is used to identify the fields to use as merge keys. Each field is described using 4 values:
'pos', its position in the record, relative to 1;
'len', the field's length;
'type', the type of data stored in the field; and
'opt', the sort order for the field which can be
A for ascending, D for descending, or
E as modified by an E61 exit.
Up to 128 fields can be sorted or merged using one
MERGE control statement.