Is there a way to insert a Header record with count of total number of records in a file preferably with a single sort step.
For example i have a flat file (PS) which is FB 80 bytes and has around 50 records. File does not have header. Is it possible to run this file through a sort step sum the total number of records and write whole file back out but now with a additional Header record with total record count.
To insert the count in a header record takes two passes. Since the header record is the first record, we don't know the count when we read/write it. You could insert a trailer record with the count in one pass, but not a header record.
I could show you how to do what you want in two passes, but first I need you to show me an example of your input records and what you expect for output. What should the header record look like? Should the count include the header record, or just the data records? Is there a trailer record - if so, should it be included in the count?
The first step uses TRAILER1 to create a DFSORT symbol for the input record count as:
The second step uses HEADER1 with MYCT to create the header.
REMOVECC suppresses the ANSI carriage control character.
NODETAIL suppresses the data records.
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from: