Sorting with INREC, OUTREC, AND SUM

Document ID : KB000027709
Last Modified Date : 14/02/2018
Show Technical Document Details

Introduction:

CA-SORT also provides a number of other options that can improve the performance of the sort. Among those are the INREC, OUTREC and SUM statements.

 

Instructions:

Use the INREC statement to reduce the size of each record before passing it to the sort phase. If the programs that use the sorted file need only the first 100 bytes of a 1000 byte record next, then include the INREC statement INREC FIELDS=(1,100). Restore the records to their original length if the program that processes the file requires 1000-byte records using the OUTREC statement OUTREC FIELDS=(1,100,900X).

A test using the following sort showed a savings in CPU time and I/O with just 5100 records. The sort using INREC/OUTREC did not need external sort work storage. The sort without INREC/OUTREC required external sort work DASD. It was run in a partition too small to contain all the records. DATASPACE was not used.

 SORT FIELDS=(44,6,CH,A),WORK=1     
 INREC FIELDS=(1,100)               
 OUTREC FIELDS=(1,100,900X)         
 RECORD TYPE=F,LENGTH=1000          
 INPFIL BLKSIZE=1000                
 OUTFIL BLKSIZE=1000                
 
      		DURATION   CPU SECS.  SIO COUNT
 INREC/OUTREC     00.00.01      000.05       1535
 NO INREC/OUTREC  00.00.01      000.07       1781

The SUM statement also improves performance. It reduces the number of output records. If the record contains numeric data in the data fields, they can be totaled prior to passing the output to another program. The application program that follows runs faster, because it processes fewer records.

INREC, OUTREC, and SUM can be used in the same sort. Use the INREC statement to prevent overflow when totaling numeric fields. Insert pad fields in front of numeric fields to contain the overflow digits.

 INREC FIELDS=(1,23,X'F0F0',24,57)      
 SUM FIELDS=(24,10,ZD)                  

Even records that contain edited zoned decimal fields can be totaled with the aid of INREC and OUTREC to remove then reinsert decimal points or other characters.

    SORT FIELDS=(44,6,CH,A),WORK=1                         
    OPTION STORAGE=64K                                     
    INREC FIELDS=(1,31,33,10,44,2,46,35)                   
    SUM FIELDS=(24,10,ZD,34,10,ZD)                         
    OUTREC FIELDS=(1,31,X'4B',32,10,X'4B',42,37)
    RECORD TYPE=F,LENGTH=80                                
    INPFIL SYSIPT                                          
    OUTFIL SYSLST                                          
    END                                                    
 AAAAAA     CCCCCC      00078901.4500009017.12ZBBCCC       
 BBBBBBBBB  DDDDDD      00077777.1300001015.12ZBBCCC       
 YYYY       NNNNN       00007865.2200011897.32GCCEEE       
 KKKKK      MMMMMM      00005865.3100023891.23BCCEEE       
 JJJJJ      EEEEEE      00004865.4800023892.43BCCEEE       
 CCCCCCC    XXXXXXXX    00003865.5300012893.23BCCEEE       
 FFFFFFFF   MMMMMMM     00000005.6000000194.44GHHIII       
 DDDD       AAAAAA      00001865.7300055895.56BCCEEE       
 MMMMM      SSSSSSS     00007265.8300011896.65BCCEEE       
 NNNNNNNN   TTTTTTT     00007365.9300012397.11FGGCCC       
 VVVVVV     KKKKKKK     00007465.0300023498.67FGGCCC