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