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


Reformatting records after sorting with BUILD or FIELDS

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

In the last chapter, you used the SUM statement to sum the price of the books in stock and the books sold for each publisher. Now, using the FIELDS or BUILD parameter of the OUTREC statement, you can delete all the fields that are not needed for the application; in other words, fields whose contents are not meaningful in a summation record. Only the publisher, number-in-stock, and number-sold fields are written, reducing the output record length to 12 bytes.

The OUTREC statement looks like this:

The OUTREC statement

Here are the steps for writing this OUTREC statement:

Table 1. Steps to Create the OUTREC Statement for Reformatting Records
Step Action
1 Leave at least one blank, and type OUTREC
2 Leave at least one blank, and type FIELDS= (or BUILD=)
3 Type, in parentheses, and separated by commas:
  1. The location and length of the publisher field
  2. The location and length of the number in stock field
  3. The location and length of the number sold field.
The SORT, SUM and OUTREC statements are as follows:
  SORT FIELDS=(106,4,CH,A)
  SUM FIELDS=(162,4,BI,166,4,BI)
  OUTREC FIELDS=(106,4,162,4,166,4)

Table 2 shows the output.

Table 2. Writing Only Publisher, Number In Stock, and Number Sold Fields

 
Publisher

Number
In Stock

Number
Sold

1  4

5  8

9  12

COR
FERN
VALD
WETH

 103
  19
  42
  62

  161
   87
   97
   79

The number in stock and number sold fields are binary values which would actually be unreadable if you printed or displayed the output records shown in Table 2. Later in this chapter, you'll learn how binary and other unreadable numeric values can be converted to various readable forms.

Suppose you use this SORTOUT DD statement for your output data set:
//SORTOUT DD DSN=MY.OUTPUT,DISP=(NEW,CATLG,DELETE),
//  UNIT=SYSDA,SPACE=(CYL,(5,5))

DFSORT automatically sets the LRECL of your new output data set (MY.OUTPUT) to the reformatted output record length, so LRECL=12 would be set in this case. You do not need to specify the LRECL on your SORTOUT DD statement, because DFSORT will set it appropriately for you.

If your SORTOUT data set already has an LRECL value (OLD data set), or you choose to specify an LRECL value on the SORTOUT DD statement, that value overrides the value DFSORT would set for the LRECL. This can result, intentionally or unintentionally, in padding or truncating your output records if the calculated length of the reformatted record does not match your specified LRECL.

In general, it is best to let DFSORT set the RECFM, LRECL and BLKSIZE for your NEW SORTOUT data sets, unless you have a particular reason to override these values. For OLD SORTOUT data sets, ensure that the existing RECFM, LRECL and BLKSIZE values are appropriate for the control statements you use.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014