z/OS DFSORT: Getting Started
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Updating counts and totals in trailer with OUTFIL

z/OS DFSORT: Getting Started
SC23-6880-00

You can use OUTFIL's IFTRAIL parameter to update count and total values in an existing trailer (last) record to reflect the actual data records in the OUTFIL data set.

Suppose another process deleted 3 records from a data set that originally contained 7 records, but did not update the counts and totals in the trailer record. The modified data set looks like this:
1 SAN JOSE      -1.23     +0.35                 
1 PALO ALTO     +8.34     +1.23                 
1 DALLAS        -0.03     -3.41                 
1 MORGAN HILL  -15.25    +20.21                 
9 COUNT=0007,TOTAL1= -12.32,TOTAL2= +26.15  

The data records are identified by a '1' and the trailer record is identified by a '9'. Note that the count of data records is 7 even though there are now only 4 data records, and the totals are also incorrect.

You can use the following OUTFIL statement to update the trailer record with the correct count and totals:
  OUTFIL IFTRAIL=(TRLID=(1,1,CH,EQ,C'9'),                     
   TRLUPD=(9:COUNT=(EDIT=(TTTT)),                            
     21:TOT=(16,6,SFF,EDIT=(SIIT.TT),SIGNS=(+,-)),           
     36:TOT=(26,6,SFF,EDIT=(SIIT.TT),SIGNS=(+,-))))

IFTRAIL tells DFSORT to update the trailer record.

TRLID=(logexp) identifies the trailer record using the same type of logical expression you can use for INCLUDE. In this case, we identify the trailer record as having a '9' in position 1. The identified trailer record is treated as the last record; it is not treated as a data record.

TRLUPD indicates the fields in the data records to be used to update counts and totals. c:, COUNT=, COUNT+n=, COUNT-n=, TOT= and TOTAL= can be used in TRLUPD in the same way they are used in TRAILER1.

The output data set will contain these data records and a trailer record updated with the correct count and totals:
1 SAN JOSE      -1.23     +0.35                  
1 PALO ALTO     +8.34     +1.23                  
1 DALLAS        -0.03     -3.41                  
1 MORGAN HILL  -15.25    +20.21                  
9 COUNT=0004,TOTAL1=  -8.17,TOTAL2= +18.38       

You can also use IFTRAIL to update counts and totals as you modify a data set, such as when you use two OUTFIL statements to split a data set.

Suppose your input data set has a header, data and trailer records like this:
H 2010/07/06                                 
D key1   0100                                
D key2   0200                                
D key2   0118                                
D key1   0150                                
D key1   0025                                
D key2   1000                                
D key2   0310                                
T X  0007 QR 001903  D52-007-321-7526      

The header record is identified by an 'H', the data records are identified by a 'D' and the trailer record is identified by a 'T'. In the trailer record, positions 6-9 contain a count (0007) of the data records, and positions 14-19 contain a total (001903) for the amount fields in the data records.

You can use the following OUTFIL statements to split the data records by key (key1 and key2) into two output data sets each of which has the header and trailer with accurate count and total for the included data records.
  OUTFIL FNAMES=OUT1,                          
   INCLUDE=(3,4,CH,EQ,C'key1'),                
   IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),     
    TRLUPD=(6:COUNT=(M11,LENGTH=4),            
           14:TOT=(10,4,ZD,TO=ZD,LENGTH=6)))   
  OUTFIL FNAMES=OUT2,                          
   INCLUDE=(3,4,CH,EQ,C'key2'),                
   IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),     
    TRLUPD=(6:COUNT=(M11,LENGTH=4),            
           14:TOT=(10,4,ZD,TO=ZD,LENGTH=6)))   

IFTRAIL tells DFSORT to update the trailer record.

INCLUDE includes the records with key1 (for OUT1) or key2 (for OUT2).

HD=YES indicates the first record is a header record. The header record will be output without change and its fields will not be used for the count or total. If the input data set has a header, you must use HD=YES to avoid treating the header record as a data record.

TRLID=(logexp) identifies the trailer record as having a 'T' in position 1. The identified trailer record is treated as the last record; it is not treated as a data record.

TRLUPD indicates the counts and totals to be updated.

The results produced for OUT1 are:
H 2010/07/06                           
D key1   0100                          
D key1   0150                          
D key1   0025                          
T X  0003 QR 000275  D52-007-321-7526

The trailer record has a count (0003) and total (000275) for the three included data records.

The results produced for OUT2 are:
H 2010/07/06                                     
D key2   0200                                    
D key2   0118                                    
D key2   1000                                    
D key2   0310                                    
T X  0004 QR 001628  D52-007-321-7526   

The trailer record has a count (0004) and total (001628) for the four included data records.

For complete details on using IFTRAIL, see z/OS DFSORT Application Programming Guide.

So far
So far, you have learned how to create multiple identical copies of an input data set; select and sample input records by relative record number for output; include, omit or save selected input records for output; reformat, repeat and split input records for output; create various types of reports and update counts and totals in trailer records. Next, you will learn about converting between fixed and variable records.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014