Sunday, 28 July 2013

JCL SORT | JCL SORT CARDS | JCL SORT COND

JCL Sort.
JCL Sort.

Sequential files are still commonly used in mainframe shops to store transaction records. Then, before the records in these files can be processed, they often need to be sorted or merged into an appropriate sequence. For instance, sales transactions may need to be sorted into salesperson, customer, or item number sequence before they can be used to prepare reports or update master files. 

To do this sorting or merging, you use the sort/merge utility that comes with OS/390. As you will see, you normally use JCL to run this utility as a standalone program. However, you can also use this utility to do an internal sort or internal merge within an application program. 

The JCL requirements for sorting


Sort the records in a file, the sort/merge utility (or program) reads the records from one or more input files, sorts them based on the data in one or more control fields (or sort keys), and writes the sorted records to an output file. 

If you want to sort two or more files at the same time, you can concatenate them like this: 

//SORTIN DD DSNAME=RC01.INVOICE.TRANS.APRIL,DISP=SHR 
//       DD DSNAME=RC01.INVOICE.TRANS.MAY,DISP=SHR
//       DD DSNAME=RC01.INVOICE.TRANS.JUNE,DISP=SHR

This assumes of course that the control field is in the same location in all of the files.

Although the JCL for this job step provides for only one work file, you can provide for more than one. Either way, the space allocation for the work files should be about twice the combined sizes of the input files. That extra space lets the sort/merge program work more efficiently while it does the sorting.


JCL Sort Utility
JCL Sort.

The DD statements required by a sort
ddname
Use
SORTLIB
A partitioned data set that contains the modules required by the sort/merge utility. Normally, SYS1.SORTLIB.
SYSOUT
The messages produced by the sort/merge utility. Normally, a SYSOUT data set.
SORTIN
The input file or files to be sorted. If more than one file is to be sorted, you can concatenate them.
SORTOUT
The sorted output file. It can be a new non-VSAM file with DISP=(NEW,KEEP) or DISP=(NEW,CATLG); an extension of an existing non-VSAM file with DISP=MOD; or an existing VSAM file.
SORTWKnn
The work files that are required by the sort, where nn is a consecutive number starting with 01. One or two files are usually adequate, and the total DASD space allocated to the work files should be about twice the input file size. You can specify up to 255 work files.
SYSIN
The sort control statements. Normally, an instream data set.

Example: Sample SORT JCL.


//RCORT01 JOB  (...JOB CARD..) 
//SORT    EXEC PGM=SORT
//SORTLIB DD DSNAME=SYS1.SORTLIB,DISP=SHR
//SYSOUT  DD SYSOUT=*
//SORTIN  DD DSNAME=RCKT10.INVOICE.TRANS,DISP=SHR
//SORTOUT DD DSNAME=RCKT10.INVOICE.TRANS.SORTED,DISP=(NEW,CATLG),
//                  UNIT=SYSDA,VOL=SER=MPS8BV,
//                  SPACE=(CYL,(10,5))
//SORTWK01 DD UNIT=SYSDA,SPACE=(CYL,(20,5))
//SYSIN    DD * 

  SORT FIELDS=(9,5,CH,A)
/*



No comments:

Post a Comment

New In-feed ads