Sorting the output of the HD Reorganization Unload utility

The method for sorting the output of the HD Reorganization Unload utility differs depending on whether you are using /SX fields to create unique keys in your secondary index.

Sorting output when you are not using a /SX field for uniqueness

If you are not using /SX fields, sort the secondary index output data sets by using the sort control statements that are generated by the HD Reorganization Unload utility in the data sets that are defined by the DFSSRTnn DD statement.

You must sort each secondary index output file. The following example shows sample JCL for the sorting of the STUNUM secondary index. The SORTIN DD specifies the DFSWRK01 output from the HD Reorganization Unload utility. The SYSIN DD specifies the DFSSRT01 output from the HD Reorganization Unload utility. The output of this sort is input to the HD Reorganization Reload utility (DFSURGL0) for the STUNUM secondary index.

//******************************************************************* 
//*   SORT THE STUNUM SEC. INDEX RECORDS FROM MIGRATX=YES             
//******************************************************************* 
//*                                                                   
//SORT01   EXEC PGM=SORT,REGION=2048K,PARM='CORE=MAX'                 
//SORTLIB  DD DSN=SYS1.SORTLIB,DISP=SHR                               
//SYSOUT   DD SYSOUT=*                                                
//SORTWK01 DD UNIT=SYSDA,SPACE=(CYL,(50,5),,CONTIG)                  
//SORTWK02 DD UNIT=SYSDA,SPACE=(CYL,(50,5),,CONTIG)                  
//SORTWK03 DD UNIT=SYSDA,SPACE=(CYL,(50,5),,CONTIG)                  
//SYSIN    DD DSN=JOUKO3.STUDENT.MIGR.SRT01,DISP=OLD                  
//SORTIN   DD DSN=JOUKO3.STUDENT.MIGR.WRK01,DISP=OLD                  
//SORTOUT  DD DSN=JOUKO3.STUDENT.MIGR.WRK01.SORTED,DISP=(NEW,CATLG),  
//         UNIT=3390,VOL=SER=TOTIMN,                                  
//         SPACE=(CYL,(50,10),RLSE) 

Sorting output when you are using a /SX field for uniqueness

If you are using /SX fields for uniqueness, perform the following steps to place the secondary index unload records in the correct subsequence order:

  1. Split the file into three separate files that contain the header record, the unload records, and the trailer record. The following example shows sort JCL and control statements for this step.
    Note: The following example is used when MIGRATX=YES is specified. When MIGRATE=YES is specified, the OUTFIL INCLUDE statement for the trailer record includes X'0090' instead of X'0290'.
    //SORTIN     DD  DSN=UNLOAD.OUTPUT,DISP=SHR
    //HEADER     DD  DSN=HEADER.FILE,DISP=(NEW,PASS)
    //TRAILER    DD  DSN=TRAILER.FILE,DISP=(NEW,PASS)
    //ULCOPY     DD  DSN=UNLOAD.COPY,DISP=(NEW,PASS)
    //SYSIN      DD   *
    OPTION     COPY
    OUTFIL INCLUDE=(5,2,CH,EQ,X'0080'),FNAMES=HEADER
    OUTFIL INCLUDE=(5,2,CH,EQ,X'0290'),FNAMES=TRAILER
    OUTFIL SAVE,FNAMES=ULCOPY
    RECORD TYPE=V
  2. Sort the file that contains the unload records in the /SX subsequence order. You must calculate the offset and the size of the sort field. The offset is 63 bytes plus the size of the root key of the indexed database. The sort field size is the size of the secondary index search field plus 8 bytes. The following example shows sort JCL and control statements for this step. In this example, the offset is 73 bytes and the sort field size is 18 bytes.
    //SORTIN   DD DSN=UNLOAD.COPY,DISP=SHR
    //SORTOUT  DD DSN=UNLOAD.SORTED1,DISP=(,CATLG),
    //            UNIT=SYSDA,VOL=SER=000000,SPACE=(CYL,(1,5))
    //SYSIN    DD  *
    SORT FIELDS=(73,18,CH,A),FILSZ=E1000
    RECORD TYPE=V
    END
  3. Merge the records into one file. The following example shows sort JCL and control statements for this step.
    //SORTIN DD DSN=UNLOAD.HEADER,DISP=(OLD,DELETE),
    //          UNIT=SYSDA,VOL=SER=000000,SPACE=(CYL,(1,5))
    //       DD DSN=UNLOAD.SORTED1,DISP=(OLD,DELETE),
    //          UNIT=SYSDA,VOL=SER=000000,SPACE=(CYL,(1,5))
    //       DD DSN=UNLOAD.TRAILER,DISP=(OLD,DELETE),
    //          UNIT=SYSDA,VOL=SER=000000,SPACE=(CYL,(1,5))
    //SORTOUT DD DSN=UNLOAD.SORTED2,DISP=(NEW,KEEP),
    //          UNIT=SYSDA,VOL=SER=000000,SPACE=(CYL,(1,5))
    //SYSOUT   DD  SYSOUT=A
    //SYSIN    DD  *
    OPTION    COPY
    END