ALTSEQ in SYNCSORT/DFSORT
//**************************************************
//STEP02 EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=TEST.SORT.INPUT,DISP=SHR
//SORTOUT DD DSN=TEST.SORT.OUTPUT,
// DISP=(NEW,CATLG,DELETE),UNIT=DISK,
//
DCB=(RECFM=FB,LRECL=400,BLKSIZE=8800),
// SPACE=(TRK,(350,200),RLSE)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
ALTSEQ CODE=(E340,C940,4D40,5D40)
OUTREC FIELDS=(1,80,TRAN=ALTSEQ)
/*
EXPLANATION:
ALTSEQ
will replace the character in the INPUT File with that specified.Here in ALTSEQ code we are specifying
ALTSEQ CODE=(E340,C940,F540,5D40).
'E3' is the hexadecimal value for alphabet 'I'.
'40' is the hex equivalent for SPACE.
So ALTSEQ CODE=E340 will replace 'I' with 'SPACE'.
Like wise we can do for any characters provided we know the HEX equivalent of that character.
Similarly '4D40' will replace '5' with 'SPACE'. So in OUTPUT we will see 'I' and '5' getting replaced by SPACE.
INPUT:
**************
INDIA MIKA
INDIA 1500
SWEDEN
2500
SPAIN 1096
TURKEY 2000
BRAZIL
6700
HOLLAND 3456
NEPAL 1209
OUTPUT:
SYNCSORT TO GET COUNT OF RECORDS
//STEP02 EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=TEST.SORT.INPUT,DISP=SHR
//SORTOUT DD DSN=TEST.SORT.OUTPUNT,
// DISP=(NEW,CATLG,DELETE),UNIT=DISK,
// SPACE=(TRK,(350,200),RLSE)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
OUTFIL REMOVECC,NODETAIL,
TRAILER1=('NO OF RECORDS:',COUNT=(M11,LENGTH=8))
/*
REMOVECC omits the ANSI carriage control character from all of the report records.
NODETAIL generates a report with no data records.
SYNCSORT TO PRINT A LINE AFTER EVERY RECORDS
SYNCSORT TO PRINT A LINE AFTER EVERY RECORDS
//STEP02 EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=TEST.SORT.INPUT2,DISP=SHR
//SORTOUT DD DSN=TEST.SORT.OUTPUNT,
//SORTOUT DD DSN=TEST.SORT.OUTPUNT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(TRK,(350,200),RLSE)
//*ORTOF02 DD DUMMY
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL BUILD=(1,80,/,80C'-')
OUTFIL BUILD=(1,80,/,80C'-')
/*
SYNCSORT TO EXTRACT A RECORD USING SUB STRING CONDITION.
//STEP02 EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=TEST.SORT.INPUT2,DISP=SHR
//SORTOUT DD DSN=TEST.SORT.OUTPUNT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(TRK,(350,200),RLSE)
//*ORTOF02 DD DUMMY
//SYSOUT DD SYSOUT=*
//SYSIN DD *
INCLUDE COND=(1,20,SS,EQ,C'IS')
SORT FIELDS=COPY
/*
SS looks for the sub string 'IS' in the position 1 to 20 in the input file and puts that reocrd in the output.
JOINKEYS for SYNCSORT
SYNCSORT TO CONVERT PACKED DECIMAL TO ZONNED DECIMAL
//STEP02 EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=TEST.SORT.INPUT2,DISP=SHR
//SORTOUT DD DSN=TEST.SORT.OUTPUNT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(TRK,(350,200),RLSE)
//*ORTOF02 DD DUMMY
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,5,PD,ZD)
/*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,5,PD,ZD)
/*
input:
----+
*****
1223A
23434
*****
Output:
----+----1
**********
.1.2.2.3.
.2.3.4.3
**********
.1.2.2.3.
.2.3.4.3
**********
Use sort to filter out matched and unmatched record
//SYSOUT DD SYSOUT=*
//SYSPRINT DD
SYSOUT=*
//SORTJNF1 DD
DSN=TEST.SORT.INPUT2,DISP=SHR
//SORTJNF2 DD
DSN=TEST.SORT.INPUT3,DISP=SHR
//SORTOF01 DD
DSN=TEST.SORT.OUTPUNT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// DCB=(*.SORTJNF1),
// SPACE=(TRK,(350,200),RLSE)
// SPACE=(TRK,(350,200),RLSE)
//SORTOUT DD DUMMY
//SYSOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(1,5,A)
JOINKEYS FILES=F2,FIELDS=(1,5,A)
JOIN UNPAIRED,F1,ONLY
REFORMAT FIELDS=(F1:1,5)
SORT FIELDS=COPY
OUTFIL FILES=01,BUILD=(1,5)
/
EXPLANATION:The above JCL will filter out the unmatched record from INPUT2 by comparing with INPUT3. /
To find out the matching record we need to use.
//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(1,5,A)
JOINKEYS FILES=F2,FIELDS=(1,5,A)
REFORMAT FIELDS=(F1:1,5)
SORT FIELDS=COPY
OUTFIL FILES=01,BUILD=(1,5)
/*
DFSORT TO WRITE HEADER ,TRAILER RECORDS
SYSIN DD*
OPTIONS COPY
OUTFIL REMOVECC,
TRAILER1=('TOTAL:',TOT=(10,6,ZD))
Adding the length and mask sub parameter:
SORT FIELDS=COPY
OUTFIL REMOVECC,NODETAIL,
TRAILER1=('TOTAL:',TOT=(10,6,ZD,M1,LENGTH=9))
To Write more than one Trailer we need to use the keywords "Trailer1,Trailer2,Trailer3."
we will see how to write trailer for count of records and total of records.
OPTION COPY
OUTFIL REMOVECC, TRAILER1=('TOTAL:',TOT=(10,6,ZD,LENGTH=10,EDIT=(TTTTTTTTTT))),
TRAILER2=('COUNT:',COUNT=(LENGTH=10))
Explanation of the keywords used: TRAILER1,TRAILER2,TRAILER3,COUNT,TOT are the keywords for SORT cards.OUTFIL is used to print the reports.REMOVECC in sort is used to remove the Cariage control inserted by DFSORT in first position.
The value of '1' in the first position of a record tells the printer to start a new page.To remove these carriage control, we need to use REMOVECC in OUTFIL statement.
TOT=(10,6,ZD) will make the total on 6 digits starting in 10th column.
If we use NODETAIL,then we would see only the trailer and header records.Other records would not be shown in output.
Omitting NODETAIL in OUTFIL would ensure we see all records along with trailer and header.
Output:
----+----1----+----2----+----3--
********************************
HARLEY 123456MEXICO
DAVID 658999CANADA
COUNT: 2
TOTAL:0000782455
********************************
To Add Header in SORT using HEADER1 parameter :
OPTION COPY
OUTFIL REMOVECC,
HEADER1=('REPORT GENERTED AS ON:',&DATE,//,22C'-'),
TRAILER1=('TOTAL:',TOT=(10,6,ZD,LENGTH=10,EDIT=(TTTTTTTTTT))),
TRAILER2=('COUNT:',COUNT=(LENGTH=10))
Output:
*********************************
REPORT GENERTED AS ON:03/02/13
---------------------
HARLEY 123456MEXICO
DAVID 658999CANADA
COUNT: 2
TOTAL:0000782455
********************************
DFSORT TO COMPARE THE HEXCODE/ASCII OF CHARACTER ALPHABETS.
DFSORT TO WRITE HEADER ,TRAILER RECORDS
SYSIN DD*
OPTIONS COPY
OUTFIL REMOVECC,
TRAILER1=('TOTAL:',TOT=(10,6,ZD))
Adding the length and mask sub parameter:
SORT FIELDS=COPY
OUTFIL REMOVECC,NODETAIL,
TRAILER1=('TOTAL:',TOT=(10,6,ZD,M1,LENGTH=9))
To Write more than one Trailer we need to use the keywords "Trailer1,Trailer2,Trailer3."
we will see how to write trailer for count of records and total of records.
OPTION COPY
OUTFIL REMOVECC, TRAILER1=('TOTAL:',TOT=(10,6,ZD,LENGTH=10,EDIT=(TTTTTTTTTT))),
TRAILER2=('COUNT:',COUNT=(LENGTH=10))
Explanation of the keywords used: TRAILER1,TRAILER2,TRAILER3,COUNT,TOT are the keywords for SORT cards.OUTFIL is used to print the reports.REMOVECC in sort is used to remove the Cariage control inserted by DFSORT in first position.
The value of '1' in the first position of a record tells the printer to start a new page.To remove these carriage control, we need to use REMOVECC in OUTFIL statement.
TOT=(10,6,ZD) will make the total on 6 digits starting in 10th column.
If we use NODETAIL,then we would see only the trailer and header records.Other records would not be shown in output.
Omitting NODETAIL in OUTFIL would ensure we see all records along with trailer and header.
Output:
----+----1----+----2----+----3--
********************************
HARLEY 123456MEXICO
DAVID 658999CANADA
COUNT: 2
TOTAL:0000782455
********************************
To Add Header in SORT using HEADER1 parameter :
OPTION COPY
OUTFIL REMOVECC,
HEADER1=('REPORT GENERTED AS ON:',&DATE,//,22C'-'),
TRAILER1=('TOTAL:',TOT=(10,6,ZD,LENGTH=10,EDIT=(TTTTTTTTTT))),
TRAILER2=('COUNT:',COUNT=(LENGTH=10))
Output:
*********************************
REPORT GENERTED AS ON:03/02/13
---------------------
HARLEY 123456MEXICO
DAVID 658999CANADA
COUNT: 2
TOTAL:0000782455
********************************
DFSORT TO COMPARE THE HEXCODE/ASCII OF CHARACTER ALPHABETS.
//STEP02 EXEC PGM=SORT
//SORTIN DD DSN=TEST.SORTINC,DISP=SHR
//SORTOUT DD DSN=TEST.SORT.OUT1,
// DISP=(NEW,CATLG,DELETE),UNIT=(SYSDA,59),
// DCB=*.SORTIN,
// SPACE=(TRK,(50,100),RLSE)
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(3,1,AC,GE,X'41',AND,3,1,AC,LE,X'4F')
Input:
00B0000
00A1462
00C1850
00D2108
00E2109
00FM006
00ZM007
00ZM008
00YM023
00CM050
Output:
00B0000
00A1462
00C1850
00D2108
00E2109
00FM006
00CM050
Explanation: The above sort card checks for the characters from A to O. All other characters will be eliminated. '41' hex of 'A' and '4F' is hex of 'O' in ASCII.
DFSORT TO INSERT/ADD DELIMITER/CHARACTERS AFTER EVERY RECORD.
//SYSIN DD *
SORT FIELDS=COPY
INREC BUILD=(1,60,SQZ=(SHIFT=LEFT,MID=C'~'))
Explanation:MID=C'`' tells DFSORT to insert the character between the fields.
SORT TO REMOVE SPACES BETWEEN CHARACTERS
SQZ operator in DFSORT/SYNCSORT can be used to remove spaces between characters.
Input:Q WE R T Y
Expected Output: QWERTY
We can use SQZ operator to remove the spaces and format the field.
OPTION COPY
OUTREC FIELDS=(1,40,SQZ=(SHIFT=LEFT))
Explanation: We are squeezing out the blanks and shifting the characters to the left for all the data in thje positions 1 to 40.
//SORTIN DD DSN=TEST.SORTINC,DISP=SHR
//SORTOUT DD DSN=TEST.SORT.OUT1,
// DISP=(NEW,CATLG,DELETE),UNIT=(SYSDA,59),
// DCB=*.SORTIN,
// SPACE=(TRK,(50,100),RLSE)
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(3,1,AC,GE,X'41',AND,3,1,AC,LE,X'4F')
Input:
00B0000
00A1462
00C1850
00D2108
00E2109
00FM006
00ZM007
00ZM008
00YM023
00CM050
Output:
00B0000
00A1462
00C1850
00D2108
00E2109
00FM006
00CM050
Explanation: The above sort card checks for the characters from A to O. All other characters will be eliminated. '41' hex of 'A' and '4F' is hex of 'O' in ASCII.
DFSORT TO INSERT/ADD DELIMITER/CHARACTERS AFTER EVERY RECORD.
//SYSIN DD *
SORT FIELDS=COPY
INREC BUILD=(1,60,SQZ=(SHIFT=LEFT,MID=C'~'))
Explanation:MID=C'`' tells DFSORT to insert the character between the fields.
SORT TO REMOVE SPACES BETWEEN CHARACTERS
SQZ operator in DFSORT/SYNCSORT can be used to remove spaces between characters.
Input:Q WE R T Y
Expected Output: QWERTY
We can use SQZ operator to remove the spaces and format the field.
OPTION COPY
OUTREC FIELDS=(1,40,SQZ=(SHIFT=LEFT))
Explanation: We are squeezing out the blanks and shifting the characters to the left for all the data in thje positions 1 to 40.
Thanks for the information.
ReplyDeleteYou can also refer http://clearmainframeinterview.blogspot.com/
for more information on SORT
i need help to do total of s9(16)v99
ReplyDeleteExcellent blog ... these examples are REALLY helpful
ReplyDelete