by BillyBoyo » Tue Mar 22, 2011 3:07 am
Assuming the best of answers to all Robert's questions, you have a straigtforward problem.
if data, store in middle part of output record, read next
if header, store in first part of output record, read next
if trailer, store in last part of output record, write output record, read next
Sort of. I'd add some "flags" to check that you always get the data in correct sequence (always header, one data, trailer).
If you have "header-expected", "data-expected" and "trailer-expected" and set them appropriately, and test that when you have each record type it is the one expected. Then you'll know your input file is OK.
When you get end of file, make sure that there is no unused data lying in the output record (ie, header-expected).
You can initialise the output record (set to space, low values, high values, whatever) either when you get a header, or after you have written the output record (when processing the trailer).
As has been suggested, and if Robert's questions have the best answers, you might be able to do this with a SORT (they are remarkable things these days). Ask in the appropriate forum for the SORT that your site has. Note, you will not be sorting the file, just using the SORT package for a bit of data manipulation.