Example 8
INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=11),
%01=(ENDBEFR=C',',FIXLEN=5),
%02=(FIXLEN=6)),
OVERLAY=(31:%00,42:%01,47:%02)
SORT FIELDS=(31,11,CH,A,42,5,UFF,A,47,6,SFF,D)
OUTREC BUILD=(1,30)
This example illustrates how you can sort FB input records with variable position/length fields, such as comma separated values.
Marketing,96218,+27365
Development,3807,+1275
Research,7283,+5001
Development,1700,-5316
Research,978,+13562
Development,3807,-158
Research,7283,+5002
Marketing,52,-8736
Development,5781,+2736
Marketing,52,+1603
Research,16072,-2022
We want to sort the first field as character ascending, the second field as unsigned numeric ascending and the third field as signed numeric descending.
Note that each record has three variable fields in comma separated value format. The fields do not start and end in the same position in every record and do not have the same length in every record. The first and second fields end with a comma and the third field ends with a blank.
In order to sort variable fields like these, we use the PARSE and OVERLAY functions of INREC to create a fixed parsed copy of each variable field. We use %00 to create an 11-byte fixed parsed field into which we extract the value before the first comma. We use %01 to create a 5-byte fixed parsed field into which we extract the value after the first comma and before the second comma. We use %02 to create a 6-byte fixed parsed field into which we extract the value after the second comma. Then we SORT on the fixed parsed fields. Finally, we use OUTREC to remove the fixed parsed fields.
Marketing,96218,+27365 Marketing 96218+27365
Development,3807,+1275 Development3807 +1275
Research,7283,+5001 Research 7283 +5001
Development,1700,-5316 Development1700 -5316
Research,978,+13562 Research 978 +13562
Development,3807,-158 Development3807 -158
Research,7283,+5002 Research 7283 +5002
Marketing,52,-8736 Marketing 52 -8736
Development,5781,+2736 Development5781 +2736
Marketing,52,+1603 Marketing 52 +1603
Research,16072,-2022 Research 16072-2022
Since the second fixed parsed field is unsigned and left-justified, we sort it with the UFF format. Since the third fixed parsed field is signed and left-justified, we sort it with the SFF format.
Development,1700,-5316
Development,3807,+1275
Development,3807,-158
Development,5781,+2736
Marketing,52,+1603
Marketing,52,-8736
Marketing,96218,+27365
Research,978,+13562
Research,7283,+5002
Research,7283,+5001
Research,16072,-2022