Problem:
Resolution:
However, there are techniques that can help you get around these limits, although they may require running the sort in several steps, and writing simple programs to "pre-process" the input and/or "post-process" the output.
1. Too many SORT fields
a) If you are sorting on character fields, and any of the fields are contiguous, and in the same order as they appear in your SORT statement, simply amalgamate them into a single field for sorting purposes, for example:
Replace SORT FIELDS=(1,10,CH,A,11,10,CH,A,21,10,CH,A, etc., etc.)
With SORT FIELDS=(1,30,CH,A, etc., etc.)
b) If the fields are not contiguous, they can be temporarily amalgamated using the INREC and OUTREC options:
Replace SORT FIELDS=(16,3,A,5,3,A,9,1,A),FORMAT=CH
With SORT FIELDS=(1,7,A),FORMAT=CH
INREC FIELDS=(1:16,3,4:5,3,7:9,1,8:1,20)
OUTREC FIELDS=(1:8,20)
The INREC statement takes the non-contiguous sort fields from their original locations, and places them in a contiguous area beginning at column 1, followed by the whole of the original data record (20 characters), beginning at column 8 in the temporary data record. The SORT statement then sorts the temporary data records on columns 1 to 7, using a single sort field. The OUTREC statement then recreates the original data record from the sorted temporary records.
c) If the sort fields are not character format, you may have to reformat them into character format in order to use one or other of the above techniques, using a simple COBOL program.
2. Too many SUM fields
a) If you are trying to sum numeric fields, and they are in character format, with no sign, you may be able to amalgamate some of them, provided that the sums will not exceed the field width, for example:
Data file: ABA00012003215009
AAA00712010517011
ABA01019008503022
AAA00098021704053
Replace SORT FIELDS=(1,3,A),FORMAT=CH
SUM FIELDS=(4,5,9,6,15,3),FORMAT=ZD
With SORT FIELDS=(1,3,A),FORMAT=CH
SUM FIELDS=(4,14),FORMAT=ZD
In both cases, the resulting sortout file will contain:
AAA00810032221064
ABA01031011718031
b) If the fields are not contiguous, you can use the techniques described in section (1.b) above, to rearrange them into contiguous areas before summation, and then return them to their original positions after sorting. You can also use the INREC statement to effectively lengthen individual fields, if you think that when summed, the fields will overflow the original length, but of course you must be careful when reconstructing the output file to cater for the new length, and/or the possibility that any sums have overflowed the original field lengths.
For example, the following INREC specification increases two of the above fields by two bytes each, by inserting leading zeroes, creating a single 18 byte numeric field:
INREC FIELDS=(1:1,3,4:C'00',6:4,5,11:9,6,17:C'00',19:15,3)
SUM FIELDS=(4,18),FORMAT=ZD
When sorted, the output is now:
AAA000081003222100064
ABA000103101171800031
Note that the maximum number of digits that you can sum as a single field is currently 18.
b) If the above technique will not reduce the number of summed fields below the limit, you may have to perform the sort in two or more steps, and combine the output using a simple Cobol program, for example:
Replace SORT FIELDS=(1,3,A),FORMAT=CH
SUM FIELDS=(4,5,9,6,15,3,25,6),FORMAT=ZD
With #1 SORT FIELDS=(1,3,A),FORMAT=CH
SUM FIELDS=(4,5,9,6),FORMAT=ZD
OUTREC FIELDS=(1:1,14)
#2 SORT FIELDS=(1,3,A),FORMAT=CH
SUM FIELDS=(15,3,25,6),FORMAT=ZD
OUTREC FIELDS=(1:1,3,4:15,16)
#3 Combine the output files from #1 and #2,
The first sort operation sums a subset of fields from the input file, creating "short" records, consisting of the sort fields, and the summed fields. The second sort operation sums a second subset of fields from the original input file, and creates a second set of "short" records, consisting of the same sort fields, and the second set of summed fields.
The third step is performed by a simple Cobol program that reads a record from each of the two sortout files, and creates a single record by concatenating the summed fields from the second file to the sort fields and summed fields from the first file.
#StudioEnterpriseEdition
#netexpress
#Server
#ServerExpress
#COBOL
#EnterpriseServer
#Enterprise