Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Opening file multiple times - better way

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Opening file multiple times - better way
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Wed May 09, 2012 2:12 pm    Post subject: Reply to: Opening file multiple times - better way
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
Reply with quote

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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Wed May 09, 2012 3:46 pm    Post subject: Reply to: Opening file multiple times - better way
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Thu May 10, 2012 2:58 pm    Post subject: Reply to: Opening file multiple times - better way
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
This topic is locked: you cannot edit posts or make replies. Natural ADABAS Opening with CTS enikhilk Mainframe Jobs 0 Wed Nov 30, 2016 5:37 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us