View previous topic :: View next topic
|
Author |
Message |
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
HI I have the following file format - the file contains one header record and several detail records.
Header record - Name - Total record count
Detail record - several details
Example of a header record - HDRXXX500
Example of a detail record - DTL1YYY
Now, i need to read the file completely and make sure the number of detail records is the same as the total record count mentioned in the header. If there is a mismatch i should not process the detail records. If there is a match then the detail records need to be processed.
So, say i have 499 detail records and 500 is the record count on the header. Since both mismatched, i cannot process the detail records.
If the count was 500 just like the header count then i could take each record and process it. However the problem is i have already reached the bottom of the file counting the number of detail records. if the count is matching with the header count i need to go back to the beginning of the file and process each detail record.
Opening a file multiple times is poor logic. can someone suggest a better way? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
In the Header, have all the "identification information" you need for the data, data/business date, logical file name, that sort of thing.
In the trailer, have the counts/hash totals. As soon as you find that your data is corrupt, you let someone know via your site's preferred method.
How is the "count of records in the header" maintained elsewhere? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Batches should always be proofed before processing.
so, preprocess with sort do validate the count.
you can use option copy (thus no sorting)
you do not need an output, only a return code.
sort can read the file much faster than an application program.
remove validation logic from your program. |
|
Back to top |
|
|
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
HI Bill and Dick, thanks for your responses.
We dont have trailer records Bill - the client gave the total record count in the header.
Dick, i think your idea about doing a preprocess with Sort would be good.
So for that i will need to use Count function and write the count of records into a file and then use this file in the program to check if it matches with the header count. Did you have something better than this? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
yeah, use the count, compare against the header, RC>0 if no match.
rc=0 run your program.
rc>0 do something else, like follow-up/create invalid header count process..... |
|
Back to top |
|
|
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
Ok thanks Dick. I will follow this approach. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
There are examples in the DFSORT forum here, also look at the Smart Tricks DFSORT book.
I know you don't have trailers, I'm saying you should... :-)
You missed the other question, which was how is the count on the header maintained elsewhere? |
|
Back to top |
|
|
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
HI Bill,
the count on the header is send from the client side. we do a match with the number of records sent in the file and if it is mismatching we inform the client.
The other question i have is.. i am trying to do this with IDCAMS... is this possible?
Since i am not very familiar with the sort.
Thanks
CJ |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Get familiar with the Sort. Have a look at some examples, hit the manual. If you get stuck, post a question in the appropriate place for your Sort product, DFSORT for DFSORT (ICE messages) else JCL. |
|
Back to top |
|
|
CJT
New User
Joined: 02 Aug 2007 Posts: 83 Location: Here
|
|
|
|
Ok, I went through some examples here. I came up with this solution - for the benefit of others - if needed.
Code: |
SORT FIELDS=copy
OUTFIL FILES=1,INCLUDE=ALL
OUTFIL FILES=2,NODETAIL,REMOVECC,
TRAILER1=(1:COUNT=(ZD,LENGTH=8))
|
This above sort copies input records into one file and then copies the count into another file. |
|
Back to top |
|
|
|