Page 1 of 1

Extract first record from multiple files

PostPosted: Wed Jan 13, 2021 2:14 pm
by Prasanna G
Hi

I have close to 25000+ flat files of different record lengths and record format (FB/VB). My requirement is to create a report with file name and 30 bytes of first record of corresponding file. If the input file is less than 30 bytes, the output record can be written with padded spaces.

Input:
TEST.OTHR.FILE1
TEST.OTHR.FILE2
TEST.OTHR.FILE3
TEST.OTHR.FILE4

Output report to be created in a file with the following as records in it:
TEST.OTHR.FILE1 - UHDR2021002
TEST.OTHR.FILE2 - …………..
TEST.OTHR.FILE3 - HEADER20210102
TEST.OTHR.FILE4 -
 


In the above example, TEST.OTHR.FILE2 has low values in it as the first record. TEST.OTHR.FILE4 is empty.
Is it possible to be done using DFSORT?

Thanks
Prasanna G

Re: Extract first record from multiple files

PostPosted: Wed Jan 13, 2021 5:36 pm
by NicC
With the aid of another program - yes. But, also, that other program could do it all.

Re: Extract first record from multiple files

PostPosted: Wed Jan 13, 2021 7:50 pm
by Prasanna G
Is it not doable using DFSORT?

Re: Extract first record from multiple files

PostPosted: Wed Jan 13, 2021 8:19 pm
by NicC
Yes it is. But would you want to? You would need to run the step for each dataset (not file). Each execution would have a dataset as the SORTIN and its name would be passed via the JPy parameter. Simple enough to read one record, combine that with the JPy data and write out to SORTOUT. Subsequent executions would need a DISP=MOD on SORTOUT. Do that 2,500 times.

Or write a quick Rexx which will read a list of the dataset names and for each it would allocate the dataset, read one record and then create the output record. Do once,

Re: Extract first record from multiple files

PostPosted: Wed Jan 13, 2021 9:16 pm
by sergeyken
Prasanna G wrote:Is it not doable using DFSORT?

It is doable with DFSORT.
But it would be the same as hammering 2500 nails using a screwdriver.

The simplest way should be using REXX, as suggested above.

Re: Extract first record from multiple files

PostPosted: Wed Jan 13, 2021 11:16 pm
by Prasanna G
Hi NicC

I was able to achieve my requirement by writing a simple rexx.

Thanks for you time.