z/OS DFSORT Application Programming Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Example 17

z/OS DFSORT Application Programming Guide
SC23-6878-00

  OPTION COPY
  OUTREC IFTHEN=(WHEN=INIT,BUILD=(1,4,6:5)),
    IFTHEN=(WHEN=GROUP,BEGIN=(6,3,CH,EQ,C'HDR'),
      END=(6,3,CH,EQ,C'TRL'),PUSH=(5:ID=1))
  OUTFIL INCLUDE=(5,1,CH,NE,C' '),BUILD=(1,4,5:6)

This example illustrates how you can INCLUDE groups of VB records between a header and a trailer. It's similar to Example 16, but here the records are variable-length. For the FB records, we could add the ID after the end of each record and then remove it without changing the records. But we can't add the ID at the end of each VB record because that would pad all of the records to a fixed length. So, instead we insert the ID between the RDW and the first data byte of each record, and later remove it.

The VB input records might look like this:
Len|Data
 23|C33  Not in a group
 23|HDR   Start Group 1
 25|A01    Group 1 record
 25|B02    Group 1 record
 25|C03    Group 1 record
 21|TRL   End Group 1
 23|R24  Not in a group
 23|T02  Not in a group
 23|HDR   Start Group 2
 25|D04    Group 2 record
 25|E05    Group 2 record
 21|TRL   End Group 2
 25|F97  Not in a group

In the output data set we only want to include groups of records that start with 'HDR' and end with 'TRL'.

We use an IFTHEN WHEN=INIT clause to reformat each record so it has room for the ID byte between the RDW and the first data byte. After the WHEN=INIT clause is executed, the intermediate records look like this:
Len|Data
 24| C33  Not in a group
 24| HDR   Start Group 1
 26| A01    Group 1 record
 26| B02    Group 1 record
 26| C03    Group 1 record
 22| TRL   End Group 1
 24| R24  Not in a group
 24| T02  Not in a group
 24| HDR   Start Group 2
 26| D04    Group 2 record
 26| E05    Group 2 record
 22| TRL   End Group 2
 26| F97  Not in a group

Note that position 5 is blank and the 'HDR' and 'TRL' characters have been shifted over to positions 6-8.

We use an IFTHEN WHEN=GROUP clause to put a non-blank character in each record that is part of a group. BEGIN indicates a group starts with a record that has 'HDR' in positions 6-8. END indicates a group ends with a record that has 'TRL' in positions 6-8. PUSH overlays a 1-byte ID character at position 5 in each record of a group. After the IFTHEN GROUP clause is executed, the intermediate records look like this:
Len|Data
 24| C33  Not in a group
 24|1HDR   Start Group 1
 26|1A01    Group 1 record
 26|1B02    Group 1 record
 26|1C03    Group 1 record
 22|1TRL   End Group 1
 24| R24  Not in a group
 24| T02  Not in a group
 24|2HDR   Start Group 2
 26|2D04    Group 2 record
 26|2E05    Group 2 record
 22|2TRL   End Group 2
 26| F97  Not in a group

Note that the records within a group have a non-blank character in position 5 whereas the records outside groups have a blank character in position 5. The ID starts at 1 for the first group and is incremented by 1 for each subsequent group. Since we are only allowing one character for the ID, when the ID counter gets to 10, a '0' will appear in position 5. That's fine since we are just looking for a non-blank to indicate a record within a group, or a blank to indicate a record outside of a group.

We use an OUTFIL statement to only INCLUDE records with a non-blank in position 5, and to remove the ID character so the included output records will be identical to the input records. After the OUTFIL statement is executed, the final output records look like this:
Len|Data
 23|HDR   Start Group 1
 25|A01    Group 1 record
 25|B02    Group 1 record
 25|C03    Group 1 record
 21|TRL   End Group 1
 23|HDR   Start Group 2
 25|D04    Group 2 record
 25|E05    Group 2 record
 21|TRL   End Group 2

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014