Code Comments
Programming Forum and web based access to our favorite programming groups.Is there any difference between opening as OUTPUT an indexed file with ACCESS MODE RANDOM and ACCESS MODE DYNAMIC? I know the difference when opening for INPUT or I-O, but I can't think of how one of the above would be preferred over the other. What brings this fairly silly question up is that I have a sorted input file that I read in, extract some data from, and write the "modified" version of some of the records to an indexed output file. I had been opening the output file as SEQUENTIAL, and this worked fine. That is, until I needed to add a "header" record. I can't actually create the header record until I've read all of the other records, so I put my logic to create the header after I finished processing the input file. This, of course, caused a write error with status '21' (sequence error). I'm not really looking for a solution, because I already have two: 1) Add a trailer record instead of a header record. or 2) Define output file as ACCESS RANDOM instead of SEQUENTIAL. But it made me wonder what difference it might make using ACCESS DYNAMIC instead of RANDOM. I tried both ways and DYNAMIC *seems* to run faster, but I don't know if that's just because of CPU utilization issues or if it actually makes sense that DYNAMIC would be faster because it would do SEQUENTIAL for 99% of the records. Frank --- Frank Swarbrick Senior Developer/Analyst - Mainframe Applications FirstBank Data Corporation - Lakewood, CO USA
Post Follow-up to this messagehi! the best way is: open output the indexed file write sequentially all the file close open i-o set the key and write the label record close doing so, the computer write all the index really in order and it's very fast. and all the next read access will fly. you can do it only if you declare the file for dynamic. bye! gz "HeyBub" <heybubNOSPAM@gmail.com> wrote in message news:119vfscobpe0cbf@news.supernews.com... > Frank Swarbrick wrote: > > Well, you actually CAN write the header record first. Write a dummy > record - with the low key - then, when finished update it with record > counts or whatever. > > > > If you can't really tell the difference in your timing tests, then it > probably doesn't make any difference. >
Post Follow-up to this message> the computer write all the index really in order and it's very > fast. and all the next read access will fly. > you can do it only if you declare the file for dynamic. Writing an indexed file in ascending key order is not necessarily the best mechanism to get an efficient index. Many b-tree indexes need to be rotated to keep the tree balanced and an all ascending key will mean that there will be the most number of rotations required. I have seen some systems (eg early RM Cobol) where the index was never rotated and loading a file in ascending key sequence resulted in the worst possible index that was basically a single linked list. In these cases it was necessary to sort the records to a random sequence in order that the index resulted in a reasonable balance.
Post Follow-up to this messageThis is a good reason for referring to the language reference manual and programmers guide for the particular version of COBOL in use for their recommendations.
Post Follow-up to this messageHi Frank, In an IBM Mainframe environment the following applies. I assume it's the same for others. With RANDOM only random access of recs is allowed; with SEQUENTIAL only seq access of recs is allowed. With DYNAMIC both modes of access is allowed. Use READ NEXT when doing a seq read; use READ when doing a random read. Just make sure the key field in the FD contains the value you need.
Post Follow-up to this message> Use READ NEXT when doing a seq read; use READ when doing a random read. The question was about OPEN OUTPUT, so the difference in the READ statement does not apply.
Post Follow-up to this message"Robert Jones" <rjones0@hotmail.com> wrote in message news:1117878926.227936.129310@z14g2000cwz.googlegroups.com... > This is a good reason for referring to the language reference manual > and programmers guide for the particular version of COBOL in use for > their recommendations. > I agree. in my experience (ufas file system on bull ) loading sequentially an indexed file was the best mode to obtain a very fast access file. but surely different implementation of cobol and file system can achieve different results. regards!
Post Follow-up to this messageMy indexed file system is IBM VSAM/VSE, so I would guess (or hope!) that if I declare the access as being sequential it would handle this in the most efficient manner possible. Now if I declared it as RANDOM or DYNAMIC I'm not so sure, though DYNAMIC did appear to run faster than RANDOM. In any case, I'm going to depend on the file system to work efficiently until such time as I determine that it's not. Thanks for the info, in any case. Frank > the computer write all the index really in order and it's very > fast. and all the next read access will fly. > you can do it only if you declare the file for dynamic. Writing an indexed file in ascending key order is not necessarily the best mechanism to get an efficient index. Many b-tree indexes need to be rotated to keep the tree balanced and an all ascending key will mean that there will be the most number of rotations required. I have seen some systems (eg early RM Cobol) where the index was never rotated and loading a file in ascending key sequence resulted in the worst possible index that was basically a single linked list. In these cases it was necessary to sort the records to a random sequence in order that the index resulted in a reasonable balance.
Post Follow-up to this messageHi "Slade", This makes sense when you're talking about reads, but when you're talking about writes where mode is DYNAMIC what is the difference between a "random" write and a "sequential" write. I don't see anything that documents something similar to "READ NEXT", such as "WRITE NEXT". I'm in an IBM mainframe environment also (VSE/ESA). Thanks, Frank Hi Frank, In an IBM Mainframe environment the following applies. I assume it's the same for others. With RANDOM only random access of recs is allowed; with SEQUENTIAL only seq access of recs is allowed. With DYNAMIC both modes of access is allowed. Use READ NEXT when doing a seq read; use READ when doing a random read. Just make sure the key field in the FD contains the value you need.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.