Example 16
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.
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'.
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.
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