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


Example 16

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

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

This example illustrates how you can INCLUDE groups of FB records between a header and a trailer. We add an ID after the end of each record to indicate whether it's part of a group or not, INCLUDE on the ID, and then remove it.

The 30-byte FB input records might look like this:
C33  Not in a group
HDR   Start Group 1
A01    Group 1 record
B02    Group 1 record
C03    Group 1 record
TRL   End Group 1
R24  Not in a group
T02  Not in a group
HDR   Start Group 2
D04    Group 2 record
E05    Group 2 record
TRL   End Group 2
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=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 1-3. END indicates a group ends with a record that has 'TRL' in positions 1-3. PUSH overlays a 1-byte ID character at position 31 in each record of a group (after the end of the record). After the IFTHEN GROUP clause is executed, the intermediate records look like this:
C33  Not in a group
HDR   Start Group 1           1
A01    Group 1 record         1
B02    Group 1 record         1
C03    Group 1 record         1
TRL   End Group 1             1
R24  Not in a group
T02  Not in a group
HDR   Start Group 2           2
D04    Group 2 record         2
E05    Group 2 record         2
TRL   End Group 2             2
F97  Not in a group

Note that the records within a group have a non-blank character in position 31 whereas the records outside groups have a blank character in position 31. 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 31. 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 31, 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:
HDR   Start Group 1
A01    Group 1 record
B02    Group 1 record
C03    Group 1 record
TRL   End Group 1
HDR   Start Group 2
D04    Group 2 record
E05    Group 2 record
TRL   End Group 2

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014