Join Files on Country Code and Summarize

Input File 1 - Customers.txt
US Smith    100
UK Jones     50
GR Alexander  1
GR Alexander  3
US Smith     39
UK Hill       1
ES James    890
Input File 2 - CountryCodes.txt
ES Spain
UK United Kingdom
US United States
GR Greece
Sort Control Cards - JoinAndSumByCountry.txt
 JOINKEYS FILE=F1,FIELDS=(1,2,A) * Customers
 JOINKEYS FILE=F2,FIELDS=(1,2,A) * Country Code file
 REFORMAT FIELDS=(F2:1,20,F1:4)  * Copy Country Info to Customers
 SORT FIELDS=(1,2,CH,A)          * After joining, sort by country code
 SUM FIELDS=(30,3,ZD)            * Sum the amount
 OUTREC FIELDS=(1,20,30,3)       * Include Country and Total
Command Line
> ahlsort JoinAndSumByCountry.txt "Customers.txt,dcb=(RECFM=T,LRECL=15),CountryCodes.txt,dcb=(RECFM=T,LRECL=17)" JoinedAndSummed.txt
Output File - JoinedAndSummed.txt
ES Spain            890
GR Greece           004
UK United Kingdom   051
US United States    139
Back to Examples