Vous êtes sur la page 1sur 3

External Sort

Example 1

(1) // EXEC PGM=IERRCO00,PARM='CORE=98000'


(2) //SYSOUT DD SYSOUT=*
(3) //SORTWK01 DD UNIT=DISK,SPACE=(CYL,(1,1))
(4) //SORTWK02 DD UNIT=DISK,SPACE=(CYL,(1,1))
(5) //SORTWK03 DD UNIT=DISK,SPACE=(CYL,(1,1))
(6) //SORTWK04 DD UNIT=DISK,SPACE=(CYL,(1,1))
(7) //SORTWK05 DD UNIT=DISK,SPACE=(CYL,(1,1))
(8) //SORTWK06 DD UNIT=DISK,SPACE=(CYL,(1,1))
(9) //SORTIN DD DSN=NAME.OFFILE.TOBE.SORTED,DISP=SHR
(10) //SORTOUT DD DSN=NAME.OF.SORTED.FILE,DISP=(NEW,CATLG),UNIT=DISK,
(11) // SPACE=(TRK,(1,1)),DCB=(*.SORTIN),VOL=SER=ACD001
(12) //SYSIN DD *
(13) SORT FIELDS=(2,4,CH,A)

Comments:

1. The // are ALWAYS in columns 1 and 2. The numbers to the left of


the // are used for reference purposes.
2. The PGM name on line one: the character after the C is the letter O
The last two digits are the number 00
3. On line one: 98000 is a number
4. Lines 3 through 8: The last two digits of SORTWK01 are numbers
5. Line 11: SPACE must begin between columns 4 through 16
6. Line 13: Describes the columns to be sorted:
a. 2,4 ==> start in column 2 and sort for four columns
sort columns 2 - 5
b. CH ==> these columns contain character (including unpacked
numeric) data
PD ==> packed decimal COMP-3
BI ==> binary COMP
c. A ==> ascending sequence (D ==> Descending)
d. notice: start fields start in column 2
7. Can have multiple keys: SORT FIELDS=(5,3,CH,D,9,3,CH,A)
a. Sort on columns 5 - 7 in Descending Sequence
b. In case of duplicate values in columns 5-6, sort on columns
9-11 in Ascending Sequence
External Sort (2)

(1) // EXEC PGM=IERRCO00,PARM='CORE=98000'


(2) //SYSOUT DD SYSOUT=*
(3) //SORTWK01 DD UNIT=DISK,SPACE=(CYL,(1,1))
(4) //SORTWK02 DD UNIT=DISK,SPACE=(CYL,(1,1))
(5) //SORTWK03 DD UNIT=DISK,SPACE=(CYL,(1,1))
(6) //SORTWK04 DD UNIT=DISK,SPACE=(CYL,(1,1))
(7) //SORTWK05 DD UNIT=DISK,SPACE=(CYL,(1,1))
(8) //SORTWK06 DD UNIT=DISK,SPACE=(CYL,(1,1))
(9) //SORTIN DD DSN=NAME.OFFILE.TOBE.SORTED,DISP=SHR
(10) //SORTOUT DD DSN=NAME.OF.SORTED.FILE,DISP=(NEW,CATLG),UNIT=DISK,
(11) // SPACE=(TRK,(1,1)),DCB=(*.SORTIN),VOL=SER=ACD001
(12) //SYSIN DD *
(13) SORT FIELDS=(1,4,CH,A)
(14) INCLUDE COND=(30,9,CH,EQ,C'123456789')

The INCLUDE statement will only sort the records with '123456789' in
columns 30 - 38.
a. Compare column 30 for nine columns with the characters (C)
'123456789' for equality (EQ)
b. Other relational operators include:
NE (not equal)
GT (greater than)
GE (greater than or equal to)
LT (less than)
LE (less than or equal to)

You can change INCLUDE to OMIT


a. Omit will sort all records except the ones that meet the
condition in the OMIT statement
b. The OMIT condition format is the same as the INCLUDE condition

You can also compound conditions with the & for AND and | for OR

OMIT COND=(30,1,EQ,C'1',&,32,1,EQ,C'2')
References:

1. Brown, G. D. (1999) Advanced COBOL for Structured and Object-


Oriented Programming, Third Edition. Wiley. pp. 473-475.
Problems p480-81 #5, 6

2. add my question about binary search to using/giving hw

2. Lowe, D. (1994) MVS JCL, Second Edition, Murach. pp. 458-467.


#1 page 474

Vous aimerez peut-être aussi