Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Inserting sequence numbers z/OS DFSORT: Getting Started SC23-6880-00 |
||||||||||||||||
Suppose you want to show the total price for all of the books associated
with each course department, but you need the list in its original
course department order rather than sorted by course department.
In order to get the totals, you need to SORT by the department field,
and SUM the price field, using the following statements:
Table 1 shows the result of these statements.
Because you had to SORT in order to SUM (remember that you cannot SUM with COPY), the list is in sorted order by course department instead of the original order of COMP, blank, BUSIN, ENGL, HIST, PSYCH, and BIOL you need. To get back the original order, you can add a sequence number to each record before the records are sorted, and use a second step to sort the records back into their original order by that sequence number. You can remove the sequence numbers at the end of the second step. You can use the previous statements with a slightly modified INREC
statement to add the sequence number for the first step:
The sequence numbers start at 00000001 for the first record and are incremented by 00000001 for each subsequent record. This allows you to sort the summed records back into their original course department order by the sequence number. Table 2 shows the result of this first
step. The output records are stored in a temporary data set.
You can use the following statements for the second step to sort
by the sequence number, display the data in a meaningful way, and
remove the sequence numbers. The input for this second step is the
temporary data set you created in the first step.
The output records from this second step are:
You can use SEQNUM,m,f to create sequence numbers of various lengths in various formats. You can use START=j to start the sequence numbers at j instead of 1. You can use INCR=i to increment each sequence number by i instead of 1. You can use RESTART=(p,m) to start the sequence number at the starting value again each time the value in a particular field changes. Suppose you have the following input records:
If you wanted to sort the records by the State field in positions
1-15 and by the City field in positions 16-30, and add a third field
with a sequence number starting from 1000 and incrementing by 10,
you could use START=1000 and INCR=10 as shown in the following statements:
The output records would look like this:
Note that each record has a different sequence number. If you wanted to start the sequence number over at 1000 again each
time the State changed, you could add RESTART=(1,15) as shown in the
following statements:
The output records would look like this:
Note that the sequence number starts over at 1000 again each time the State changes. If you specify an IFTHEN clause with a sequence number, the sequence
number is only incremented for the subset of records selected by that
IFTHEN clause. For example, if you specified the following statements
for the input records shown previously:
The output records would look like this:
For complete details about creating sequence numbers with INREC, OUTREC and OUTFIL OUTREC, see z/OS DFSORT Application Programming Guide. |
Copyright IBM Corporation 1990, 2014
|