collate
In this example, you need to process a flat file that contains information for Stores and Sales. All of the Stores information is listed first in the file, in no particular order, and all of the Sales information follows the Stores information, in no particular order. You need to sort the information and associate the Sales information to the appropriate Store information. The Stores and Sales records contain a common field: Stor_id.
Syntax
Use this syntax:
collate (MASTERGROUPNAME[iteration], MASTERFIELDNAME ordering,
MASTERFIELDNAME ordering, …, DETAILGROUPNAME[iteration], DETAILFIELDNAME,
DETAILFIELDNAME, …, RESULTGROUPNAME))
Example
An example of this function follows:
collate($POHeader, #PONumber, $PODetail, #POHeaderNumber, $PODetailResult);
Map Layout
The input side of the map contains two repeating groups that are children to the input level: Stores_Group and Sales_Group. The Stores_Group group contains a single occurring record for the Stores records in the input file, and the Sales_Group group contains a single occurring record for the Sales records in the input file.
The Stores_Group is the Master group and the Sales_Group is the Detail Group when you write the Collate extended rule. Since the Stores_Group is the master group, the result group must be contained within this group.
Therefore, the Stores_Group structure contains the single occurring record for the Stores records in the input file and a repeating Result_Group. The Result_Group contains a temporary Sales record that is an exact copy of the Sales_Record in the Sales_Group.
Collate Input On-End Extended Rule
To sort and collate the data, place the following rule on the Input On-End Extended Rules:
SORT($Stores_Group,#Stores_Stor_ID ASC);
SORT($Sales_Group,#Sales_Stor_ID ASC);
COLLATE ($Stores_Group, #Stores_Stor_ID ASC,$Sales_Group,
#Sales_Stor_ID,$ Result_Group);
Sample Input File
The following is the sample input file:
STORES8042 Bookbeat 679 Carson St. Portland OR 890762
STORES7066 Barnum's 567 Pasadena Ave. Tustin CA 927892
STORES7896 Fricative Bookshop 89 Madison St. Fremont CA 900192
SALES7896QQ2299 1993-10-28 00:00:00 15 Net 60 BU78322
SALES8042423LL922 1994-09-14 00:00:00 15 ON invoice MC30212
SALES8042P723 1993-03-11 00:00:00 25 Net 30 BU11112
SALES7066QA7442.3 1994-09-13 00:00:00 75 ON invoice PS20912
SALES7896TQ456 1993-12-12 00:00:00 10 Net 60 MC22222
SALES7896X999 1993-02-21 00:00:00 35 ON invoice BU20752
SALES8042423LL930 1994-09-14 00:00:00 10 ON invoice BU10322
SALES8042QA879.1 1993-05-22 00:00:00 30 Net 30 PC10352
SALES7066A2976 1993-05-24 00:00:00 50 Net 30 PC88882
Output File
The following is an example of the output file after translation:
STORES7066 Barnum's 567 Pasadena Ave. Tustin CA 927892
SALES7066QA7442.3 1994-09-13 00:00:00 75 ON invoice PS20912
SALES7066A2976 1993-05-24 00:00:00 50 Net 30 PC88882
STORES7896 Fricative Bookshop 89 Madison St. Fremont CA 900192
SALES7896QQ2299 1993-10-28 00:00:00 15 Net 60 BU78322
SALES7896TQ456 1993-12-12 00:00:00 10 Net 60 MC22222
SALES7896X999 1993-02-21 00:00:00 35 ON invoice BU20752
STORES8042 Bookbeat 679 Carson St. Portland OR 890762
SALES8042423LL922 1994-09-14 00:00:00 15 ON invoice MC30212
SALES8042P723 1993-03-11 00:00:00 25 Net 30 BU11112
SALES8042423LL930 1994-09-14 00:00:00 10 ON invoice BU10322
SALES8042QA879.1 1993-05-22 00:00:00 30 Net 30 PC10352