Example 12
INREC IFTHEN=(WHEN=GROUP,BEGIN=(2,4,CH,EQ,C'RPT.'),
PUSH=(31:6,8))
OPTION EQUALS
SORT FIELDS=(31,8,CH,A)
OUTFIL INCLUDE=(31,8,CH,EQ,C'FRANK',OR,
31,8,CH,EQ,C'SRIHARI'),BUILD=(1,30)
This example illustrates how you can SORT and INCLUDE groups of FB records depending on a value in the first record of each group. We propagate the value in the first record of the group to every record of the group, SORT and INCLUDE on the value, and then remove it.
The 30-byte FBA input records might look like this:
1RPT.SRIHARI
LINE 1 FOR REPORT 1
LINE 2 FOR REPORT 1
...
1RPT.VICKY
LINE 1 FOR REPORT 2
LINE 2 FOR REPORT 2
...
1RPT.FRANK
LINE 1 FOR REPORT 3
LINE 2 FOR REPORT 3
...
1RPT.DAVID
LINE 1 FOR REPORT 4
LINE 2 FOR REPORT 4
...
Each report starts with 'RPT.reptname' in positions 2-13. In the output data set we only want to include records for reports with specific reptname values, and the reptname values we want can change from run to run. We also want to sort by the reptname values in ascending order. For this example, let's say we just want the SRIHARI and FRANK reports.
We use an IFTHEN WHEN=GROUP clause to propagate the reptname value to each record of the group. BEGIN indicates a group starts with 'RPT.' in positions 2-5. PUSH overlays the reptname value from the first record of the group (the 'RPT.reptname' record) at positions 31-38 (after the end of the record) in each record of the group including the first. After the IFTHEN GROUP clause is executed, the intermediate records look like this:
1RPT.SRIHARI SRIHARI
LINE 1 FOR REPORT 1 SRIHARI
LINE 2 FOR REPORT 1 SRIHARI
... SRIHARI
1RPT.VICKY VICKY
LINE 1 FOR REPORT 2 VICKY
LINE 2 FOR REPORT 2 VICKY
... VICKY
1RPT.FRANK FRANK
LINE 1 FOR REPORT 3 FRANK
LINE 2 FOR REPORT 3 FRANK
... FRANK
1RPT.DAVID DAVID
LINE 1 FOR REPORT 4 DAVID
LINE 2 FOR REPORT 4 DAVID
... DAVID
Note that the records of each group have the reptname value from the first record of that group in positions 31-38.
We use a SORT statement to sort ascending on the reptname in positions 31-38. We use the EQUALS option to ensure that records in the same group (that is, with the same reptname value) are kept in their original order. After the SORT statement is executed, the intermediate records look like this:
1RPT.DAVID DAVID
LINE 1 FOR REPORT 4 DAVID
LINE 2 FOR REPORT 4 DAVID
... DAVID
1RPT.FRANK FRANK
LINE 1 FOR REPORT 3 FRANK
LINE 2 FOR REPORT 3 FRANK
... FRANK
1RPT.SRIHARI SRIHARI
LINE 1 FOR REPORT 1 SRIHARI
LINE 2 FOR REPORT 1 SRIHARI
... SRIHARI
1RPT.VICKY VICKY
LINE 1 FOR REPORT 2 VICKY
LINE 2 FOR REPORT 2 VICKY
... VICKY
We use an OUTFIL statement to only INCLUDE the records with a a reptname of FRANK or SRIHARI in positions 31-38, and to remove the reptname from positions 31-38 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:
1RPT.FRANK
LINE 1 FOR REPORT 3
LINE 2 FOR REPORT 3
...
1RPT.SRIHARI
LINE 1 FOR REPORT 1
LINE 2 FOR REPORT 1
...