IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Opening file multiple times - better way


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Wed May 09, 2012 1:58 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed May 09, 2012 2:12 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed May 09, 2012 2:15 pm
Reply with quote

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
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Wed May 09, 2012 2:41 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed May 09, 2012 2:50 pm
Reply with quote

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
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Wed May 09, 2012 3:03 pm
Reply with quote

Ok thanks Dick. I will follow this approach.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed May 09, 2012 3:46 pm
Reply with quote

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
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Thu May 10, 2012 2:27 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu May 10, 2012 2:58 pm
Reply with quote

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
View user's profile Send private message
CJT

New User


Joined: 02 Aug 2007
Posts: 83
Location: Here

PostPosted: Thu May 10, 2012 3:36 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top