在cobol中读取顺序文件
有没有办法多次读取 cobol 中的连续文件?例如,您到达文件末尾然后从文件开头返回?
Is there any way to read a sequential file in cobol many times? For example you reached the end of the file then go back from the beggining of the file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
关闭文件,重新打开并重新读取。
我很想知道你为什么要这样做?
Close the file, reopen it and re-read.
I'm interested to know why you'd want to do this?
您还可以在循环内读取文件或执行变化。与其他答案一样,请确保每次到达末尾时关闭文件并重新打开它。
You could also read the file inside a loop or perform varying. Like the other answer, make sure you close the file out each time you reach the end and reopen it.
在这种情况下,
DFSORT
的JOINKEYS
有很大帮助。如果您的要求只是使用 file2 中的字符串列表搜索 file1 中的字符串,我强烈不建议您采用这种方法。In that case,
JOINKEYS
ofDFSORT
helps alot. I strongly dont suggest your approach if your requirement is ONLY to search for the string from file1 with the list of strings in file2.另一种方法:使用实用程序(或另一个 COBOL 程序)制作文件 1 的副本。文件 1a 的副本具有相关组织(可能是 VSAM RRDS)。在扫描/匹配程序中,您可以使用 START 语句重新定位到文件 1a 的第一条记录。
同样,您可以创建一个索引顺序文件 1a,其中键只是一个任意升序的数字,恰好与记录号相同。
An alternative: make a copy of file 1 with a utility (or another COBOL program). The copy, file 1a, has ORGANIZATION RELATIVE (a VSAM RRDS, perhaps). In your scanning/matching program, you can reposition to the first record of file 1a with the START statement.
Equivalently, you could make an indexed-sequential file 1a, where the key is just an arbitrary ascending number that happens to be the same as the record number.
打开、处理、关闭、重新打开、重新处理、重新关闭任意次数都是愚蠢的,更不用说最多 1,000 次了。这是非常非常耗时的。
使用 Cobol 程序,您可以将较小的文件存储在表中,并根据较大的文件处理该表,如建议的那样。
但是,您不需要程序。 JOINKEYS 将为您提供解决方案。
你没有钥匙吗?哦,亲爱的,亲爱的。你做一个。您可以为两个文件上的每条记录创建相同的单字节密钥和相同的值。在该键上执行 JOINKEYS。在 JOINKEYS 上指定 SORTED(如果有 DFSORT,则指定 NOSEQCK) 您有一个“笛卡尔”连接。使用 SS(子字符串匹配),可以用于整个记录,也可以用于部分记录。您实际所需的输出尚不清楚,我认为您现在不会想出这个。
使用 DFSORT,您可以一步完成。使用 SyncSort,如果您的版本支持 JNFnCMTL 文件,您可以一步完成此操作。
It would be plain silly to open, process, close, re-open, reprocess, re-close, for any number of times, let alone up to 1,000. It is very, very, time consuming.
With a Cobol program, you store the smaller file in a table and process the table against the larger file, as has been suggested.
However, you don't need a program. JOINKEYS will give you the solution.
You don't have a key? Oh, dear, dear. You make one. You make the same one-byte key, with the same value, for each record on both files. Do the JOINKEYS on that key. Specify SORTED on the JOINKEYS (and NOSEQCK if you have DFSORT) You have a "Cartesian" Join. Use SS (a Sub-String match) which can be for the entire record, or part of the record. Your actual required output is unclear, and I don't suppose you're going to come up with that now.
With DFSORT you can do it in one step. With SyncSort you can do it in one step if your version supports JNFnCMTL files.
这是我的解决方案
File1 has reocrds plus a key
文件2有记录,其中键出现多次
我将文件1详细信息存储到数组中,这意味着您必须知道
我扫描文件2直到文件末尾的数据大小,如果文件2中的键与数组中的键匹配,则进行计算,
示例
将 1 2 3 4 从 File1 存储到数组中,直到 File1 的 EOF
扫描 file2 有 1 1 4 4 2 3
如果 file2 中的 1 与数组中的 1 匹配,则计算
继续这样做,直到到达 File2 的末尾
希望它有帮助
Here is my solution
File1 has reocrds plus a key
File2 has reocrds where key occurs many times
I store file1 details into an array, this mean u must know size of data
I scan file2 until end of file, if key in file2 match key in array then do your computation,
Example
Store 1 2 3 4 in array from File1, until EOF of File1
Scan file2 having 1 1 4 4 2 3
If 1 in file2 match 1 in array then compute
Keep doing until u reach end of File2
Hope it helps