My apologies for this redundant done-to-death query, on what is turning out be 'dumb guy's day- Wednesday'.
Sample data (I've repeated the records below, in actual scenario they can be same/different between each 'XXXX' and '999' group; all records are of fixed length) -
SORTIN:
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
ABCDEFGDSLFHSO LFHAODSDFKG
ABAFKSAPDJFLOS JEFAJHSDFKG
ASFJSFGDSLFHSO LFHAODSDFKG
ABCDSFALJHSDSO LFHAODSDFKG
999EEEEEEEEEFFFFFFFFFFFFFFF
I need to generate a consolidated file for which output has below:
1. The first record in the output file should be as below; the only difference here being - the 'N' and 'M' in this record have to be a sum of all the 'N', 'M' that have appeared against the 'XXXX' or the header records:
XXXXDD/MM/YYYYNNNNNNNNNMMMMMMMMMMMMMMM
2. The second record onwards, are the detail records; which is a mere SORT COPY of the records other than 'XXXX' and '999'
3. The last record in the file will be '999' record; here again, 'E' and 'F' that appear, have to be sum of all 'E' and 'F' that have appeared against the '999' or tail records.
999EEEEEEEEEFFFFFFFFFFFFFFF
I was able to complete this in two passes; by seperating the 'X' and '9' records in a different file and then merging them with the original data; I am trying to do the same in one go itself.
One way was to build all records in INREC processing, and then subsequently write them to output.
But the point where I am stuck is, how do I build the consolidated header record (I've been trying to GROUP the data, but am totally off the rail on building header).
My apologies for this simple query, but I'm somehow/somewhere missing the FINE PRINT. Any pointers will be really helpful.
Thank you.